Qmake "contains" test function weird behaviour
-
When I use the qmake "contains" test function and I have SOURCES += ... and HEADERS += ... in the scope of the function, the sources and header files get included into the project independently if the "contains" function is true or not. This is how I am using the contains function:
@
contains(MODULES, PLOT){
message( "Add module: plot" )
SOURCES += libraries/plot.cpp
HEADERS += libraries/plot.h
}
@if MODULES is empty or does not contain "PLOT" it won't print the message but it will still include the sources and headers. These will even show in Qt Creator on the projects tree. I would expect this NOT to happen. Anything that I may missing here? Any other way I could selectively include files with a variable?
The "contains" test function is described here: http://doc.qt.io/qt-5/qmake-test-function-reference.html
-
I use "contains" but always with a colon, though I am not sure whether this is the problem here:
@ contains(MODULES, PLOT): {
message( "Add module: plot" )
SOURCES += libraries/plot.cpp
HEADERS += libraries/plot.h
}
@ -
Hi and welcome to devnet,
Are you sure you are not adding these files somewhere else in your pro file ?
Your code works fine
-
So, it seems like Qt Creator in Windows will show all the files even if it won't use them to compile. On the other hand Qt Creator on the Mac will hide them (this is what I would expect).
The other interesting "bug" is that when I add an "include" inside an "include" it will show a folder on the Project browser at the root level. It would be more convenient to show it in subfolders inside the first include.
Example
myproject.pro
MODULES += DONTLOADLIB3DS
include( thirdparty/thirdparty.pri )thirdparty.pri
contains(MODULES, LIB3DS){
message( "Add thirdparty module: LIB3DS" )
# >> Qt Creator should not list these files because the MODULES variable is not set to LIB3DS
include( thirdparty/lib3ds.pri )
}Is this an expected behavior or a bug in Qt Creator?