qmake processes my pro-file three times instead of one

混江龙づ霸主 提交于 2019-12-10 13:05:51

问题


This is entire pro file:

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

I invoke qmake in the following way:

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 following output:

Setting environment for using Microsoft Visual Studio 2008 x86 tools.

Project MESSAGE: This message should be appeared only once!!!

Project MESSAGE: This message should be appeared only once!!!

Project MESSAGE: This message should be appeared only once!!!

Why did the message print THREE times?


回答1:


Actually, the condition "build_pass" is always true except 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, which works fine in my project:

defineTest(print) {
  !build_pass:message($$1)
}

print("This message should appear only once")



回答2:


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




回答3:


Add this line to your .pro file

CONFIG -= debug_and_release debug_and_release_target 

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




回答4:


you can do it like this :

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

it will run once if you are in relase mode, for debug change to Debug:...



来源:https://stackoverflow.com/questions/17360553/qmake-processes-my-pro-file-three-times-instead-of-one

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!