I'm writing a build script for a Qt application. The script first calls qmake
on the .pro file and then runs make CXXFLAGS=-DSWVERSION=xxxx
.
The problem with this is that it overwrites the CXXFLAGS already defined in the Makefile. Currently, the only method I know to solve this problem is to edit the Makefile and change this:
CXXFLAGS = <flags>
To this:
CXXFLAGS = <flags>
I was hoping there would be a simpler solution. Is there any way I can simply append to CXXFLAGS from the command line WITHOUT rewriting the Makefile?
Alternatively, my real problem is defining SWVERSION
at build-time (because it is dependent on the build timestamp). Do you know of a better way to define this at runtime instead of passing it to CXXFLAGS?
CodePudding user response:
The change you suggest won't work anyway: a value set on the command line completely overrides the value set in the makefile, even if the value is appended to with =
. You could do this and it would work:
override CXXFLAGS = <flags>
However, the way it's normally done is that the makefile provides variables which are reserved specifically for users to override on the command line. For example in automake-generated makefiles, the common variables like CXXFLAGS
, CFLAGS
, etc. are reserved for users to set via the command line or environment, and the internal makefile flags are put into a different variable, like AM_CFLAGS
. Then the recipes to compile objects uses both variable, like $(CC) $(AM_CFLAGS) $(CFLAGS) ...
I don't know anything about qt so I can't say whether they have a similar set of reserved makefile variables but you might check the qt docs, or your generated makefile recipes, to see.
CodePudding user response:
For anyone reading this in the future, the solution I found was to call qmake <project file> DEFINES ="SWVERSION=xxxx"
. Hope someone finds this helpful.