PDA

View Full Version : Passing global defines to moc



NTwoO
30th March 2007, 09:21
Hi all. We are building an embedded application. On the target a QT application runs. There is however also other processes running that are written in C. We have customer specific requirements that we differentiate via defines. To avoid editing the defines in each subsection, I have environment variables that I set. According to these environment variables, the code is built.

If the defines are added to QMAKE_CXX_RELEASE, then they are automatically added to the CFLAGS in the generated Makefile. This is then handled at compiletime and all is fine.

Unfortunately the moc compiler only looks at $(DEFINES) and at $(INCLUDE). How can I add my list (-DBLA -DBLAH) to the DEFINES without prepending another -D? Alternatively, how can I pass the defines directly to the moc compiler?

wysota
30th March 2007, 11:51
Maybe move the defines from QMAKE_CXX_RELEASE to the proper place?
For example create a separate variable that will hold all these defines and tell QMake to add the contents of this variable to DEFINES.

NTwoO
30th March 2007, 12:21
I would love to do that, but that would mean one of the following:
1: use a scripting language to edit my .pro file before compilation.
2: pass empty/ undefined variables to DEFINES (that provides problems with redefined variables, but that can be solved with undefine)
3: get some information from you how I should get the DEFINES to pack out my list literally without prepending a -D :)
Hope you can help.

wysota
30th March 2007, 13:04
1: use a scripting language to edit my .pro file before compilation.
What for?

2: pass empty/ undefined variables to DEFINES (that provides problems with redefined variables, but that can be solved with undefine)
Again, why?


3: get some information from you how I should get the DEFINES to pack out my list literally without prepending a -D :)

You would have to explain exactly what you want, because from my point of view the thing I think you want is easy to do and from your point of view it sounds complicated, so we might be speaking about completely different two things :)

Could you please explain what effect you want to achieve? Then we can talk about solutions...

NTwoO
30th March 2007, 13:48
Let the code do the talking...



PRO_VER=1
UI_COMPILE_DEFINES="set"
CRIPTLIB="n"
QVFB="n"
LOCALE="US"

export UI_COMPILE_DEFINES
export CRIPTLIB
export QVFB
export LOCALE
export PRO_VER



this is sourced to set the environment variables.

next up, I have makefile in my project to preprocess some steps. This consequently calls Makefile, the file generated by qmake. This is to automate my versioning and environment variables.



ifneq ($(UI_COMPILE_DEFINES),set)
all:
@echo "*** The User interface environment variables aren't correctly set ***"; \
echo " try sourcing UIDEFS.sh"
exit 1
boot: all
else #ifneq ($(UI_COMPILE....
ifeq ($(PRO_VER),1)
UIFCFLAGS += -DPRO_VER1
endif
ifeq ($(PRO_VER),2)
UIFCFLAGS += -DPRO_VER2
endif
ifeq ($(PRO_VER),3)
UIFCFLAGS += -DPRO_VER3
endif
ifeq ($(ALPR),y)
UIFCFLAGS += -DALPR
endif
ifeq ($(QVFB),y)
UIFCFLAGS += -DQVFB
endif
ifeq ($(LOCALE),US)
UIFCFLAGS += -DVER_US
endif
ifeq ($(LOCALE),UK)
UIFCFLAGS += -DVER_UK
endif
ifeq ($(LOCALE),NL)
UIFCFLAGS += -DVER_NL
endif
ifeq ($(LOCALE),BE)
UIFCFLAGS += -DVER_BE
endif
ifeq ($(DRAFTLABLE),y)
UIFCFLAGS += -DDODRAFT
endif
export UIFCFLAGS
all: version
make -f Makefile $@
install: first
#rm ./install/usr/bin/*
make -f Makefile $@
clean:
make -f Makefile $@
distclean:
make -f Makefile $@

first: all
boot: all
version:
ifeq ($(PRO_VER),1)
make -e -C VersionPRO1
endif
ifeq ($(PRO_VER),2)
make -e -C VersionPRO2
endif
ifeq ($(PRO_VER),3)
make -e -C VersionPRO3
endif

endif
~
~
"makefile" [converted] 67L, 1181C 61,2-9 All


The exported UIFCFLAGS should then be added to the $DEFINES in the generated Makefile.

I tried to add them by using DEFINES += $(UIFCFLAGS), but this only generates the the following in the generated Makefile.


DEFINES = -D$(UIFCFLAGS)

which does not work.

Adding them to the QMAKE_CFLAGS means the moc misses them.

wysota
30th March 2007, 14:10
The way I see it you'd have to regenerate the Makefile, for example like this:

qmake UICFLAGS=....
make -f Makefile

and in the project file add:

DEFINES += $UICFLAGS

Of course get rid of the -D prefix when filling the UIFCFLAGS variable.

An alternative way is to alter the way moc works:

new_moc.output = moc_${QMAKE_FILE_BASE}.cpp
new_moc.commands = moc ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} ${QMAKE_CXX_RELEASE}
new_moc.depends = g++ -E -M ${QMAKE_FILE_NAME} | sed "s,^.*: ,,"
new_moc.input = HEADERS
QMAKE_EXTRA_UNIX_COMPILERS += new_moc

NTwoO
2nd April 2007, 12:23
The way I see it you'd have to regenerate the Makefile, for example like this:

qmake UICFLAGS=....
make -f Makefile


I'll check out what the options are when passing the variables to qmake.



and in the project file add:

DEFINES += $UICFLAGS

Of course get rid of the -D prefix when filling the UIFCFLAGS variable.

Shabby of me to write the project example with a -D :o

The problem is if my $UIFCFLAGS is set to "-DPRO_VER1 -DQVFB -DVER_US"
and added to the defines using
DEFINES += $(UIFCFLAGS)
it is expanded to "-D-DPRO_VER1 -DQVFB -DVER_US"
if however it is defined as "PRO_VER1 QVFB VER_US"
it is expanded to
"-DPRO_VER1 QVFB VER_US"



An alternative way is to alter the way moc works:

new_moc.output = moc_${QMAKE_FILE_BASE}.cpp
new_moc.commands = moc ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} ${QMAKE_CXX_RELEASE}
new_moc.depends = g++ -E -M ${QMAKE_FILE_NAME} | sed "s,^.*: ,,"
new_moc.input = HEADERS
QMAKE_EXTRA_UNIX_COMPILERS += new_moc
This might just be the option I would end with. I'll check this out. Hopefully I can get this running:w