qMake: How exactly does qmake interpret the "CONFIG(debug, debug|release)" syntax
Solution 1:
In the article you linked to, it's said in the very beginning that the project file is processed three times. This should answer your first question; since it's processed three times, your message() is executed three times too. Why is it processed multiple times? Because qmake does not build your project! It only generates build instructions which are then used to actually build the project. In order to generate build instructions for all possible configurations, it needs to process the project file multiple times, one time for each configuration.
For your second question: your project is built only in debug mode if that's what you selected, but build instructions are created for release mode too, as already mentioned above. When using "make" with mingw for example (rather than Visual Studio), you get two Makefiles: Makefile.Release
and Makefile.Debug
. When it generates the release makefile, that's when "release mode" is printed.
Finally, CONFIG(debug, debug|release)
evaluates to true if CONFIG contains "debug" but not "release", or if it contains both "debug" and "release" but "release" doesn't appear after the last occurrence of "debug". For example you might have this:
CONFIG += release debug release debug release debug
Since the last "debug" comes after the last "release", CONFIG(debug, debug|release)
is true.
The first argument of CONFIG() ("debug" in this case) is the value that has to appear last. The second argument ("debug|release") is the set of values that the first argument is checked against.
Translating that to English would give something like this: evaluate to true if "debug" appears at least once and, in case "release" appears too, the last appearance of "debug" comes after the last appearance of "release".