Qmake processes my pro file three times instead of one

This is the full pro file:

 message("This message should appeare only once!!!") CONFIG += qt SOURCES += src/main.cpp 

I call qmake as follows:

 set QMAKESPEC=win32-msvc2008 set QTDIR=c:\Qt\4.8.4_vs2008\ call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 call "%QTDIR%\bin\qmake.exe" -tp vc Server.pro 

And I get the following output:

Setting up the environment for using Microsoft Visual Studio 2008 x86 tools.

MESSAGE ON THE PROJECT: This message should appear only once !!!

MESSAGE ON THE PROJECT: This message should appear only once !!!

MESSAGE MESSAGES: This message should appear only once !!!

Why did the message print three times?

+7
source share
4 answers

In fact, the condition "build_pass" is always true, except for the first time qmake parses your .pro file, so the following works:

 !build_pass:message("This message should appear only once") 

I made a helper function that works fine in my project:

 defineTest(print) { !build_pass:message($$1) } print("This message should appear only once") 
+11
source

Because by default qmake will create 3 makefiles: Makefile , Makefile.debug and Makefile.release . This is due to the fact that the default configuration of the project is in debug and release modes. If you add CONFIG -= debug_and_release to your .pro file, you should see the message only once. You can find more information here and here .

+9
source

Add this line to your .pro file

 CONFIG -= debug_and_release debug_and_release_target 

qmake will only generate one Makefile with it, and the .pro file will be evaluated only once.

0
source

You can do it like this:

 Release:message("This message should appeare only once!!!") 

it will run once if you are in reverse mode to change debugging to Debug:...

0
source

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


All Articles