Add definition to qmake with value?

How to add a definition using qmake With value:

For example, this does not work (as I expected) in my .pro file:

DEFINES += WINVER 0x0500 

neither

 DEFINES += "WINVER 0x0500" 

How to define WINVER as 0x0500 before something starts compiling so that its definition does not affect compilation or inclusion of order in any way?

+41
qt qmake
Jul 27 '10 at 23:09
source share
4 answers

DEFINES += "WINVER=0x0500" works for me.

Thus, -DWINVER=0x0500 added to the compiler command line, which is the GCC / mingw syntax awaiting the definition of a command line preprocessor (see here for details).

+54
Jul 28 '10 at 5:33
source share
 DEFINES += MY_DEF=\\\"String\\\" 

This format should be used when it is assumed that the macro has been replaced by a string element.

+35
Aug 20 '13 at 19:27
source share

In addition, if you want to execute shell code instead of setting a constant (for example, to get the version number or date):

Use $$system() . This is executed when qmake is executed:

 DEFINES += GIT_VERSION=$$system(git describe --always) 

Or use $() if the code needs to be run for each assembly (i.e. when the makefile is executed). For DEFINES you need to avoid the command if it contains spaces, otherwise qmake inserts the unwanted -D 's:

 DEFINES += GIT_VERSION='$(shell git describe --always)' 

This will be literally copied to the makefile.

If the command output contains spaces, you need another level of descent (this time for make):

 DEFINES += BUILD_DATE='"$(shell date)"' 

If you need a quote around your value to get a string, it gets a little ugly:

 DEFINES += BUILD_DATE='"\\\"$(shell date)\\\""' 

I would recommend using preprocessors in this case:

 #define _STR(x) #x #define STR(X) _STR(x) printf("this was built on " STR(BUILD_DATE) "\n"); 
+19
Jun 03 '14 at 8:25
source share

Greg's answer works fine in a .pro file. However, when qmake was called from the command line, I had to leave spaces, i.e. Use sth. as shown below to complete the task:

 qmake DEFINES+="WINVER 0x0500" 
+4
Jan 23 '15 at 8:38
source share



All Articles