Modifying the qmake file to create multiple targets for use with the #IFDEF macro.

I want to modify the qmake file of the Qt project so that it creates two versions of my program: one where SOME_FLAG defined, and the other where it is missing. My code will behave differently depending on the result of #ifdef SOME_FLAG .

Is it possible?

+4
source share
2 answers

As far as I know, qmake allows only one TARGET, with one exception. Thus, if you want to create a debug version and a release version, you can build both with the same project file. Thus, you can also specify DEFINITIONS for each assembly separately. Keep in mind that you can use the strip command to remove debugging after the fact, and it may be useful for your circumstances. Qt4 HTML documents (see if they are installed on your system) describe the debug_and_release mode in qmake-common-projects.html.

Now that it’s said, you are allowed several project files. Create one project for each executable file, with the desired OPERATIONS for each project. Use the qmake -o flag to release separate Makefiles for each target and one Makefile to link them. I can not help you with QtCreator, because I do not use it, but it works on the command line. A sample Makefile that illustrates this diagram will look something like this:

 all: Makefile_A Makefile_B $(MAKE) -f Makefile_A $(MAKE) -f Makefile_B Makefile_A: withSomeFlag.pro qmake -o $@ $< Makefile_B: withoutSomeFlag.pro qmake -o $@ $< 

It's just a quick file that does the job, and someone better at Makefiles can make it more general. NOTE. Indenting Makefiles are single TAB characters, not 8 spaces.

Also note that the default executable name matches the base name of the project file. Hope this makes you go to some extent.

+1
source

You can add

 DEFINES += "SOME_FLAG" 

in your .pro file, presumably in a conditional expression.

+1
source

Source: https://habr.com/ru/post/1388153/


All Articles