qmake called from QtCreator: packagesExist and system always succeed
-
Within a qmake file I try to make some configuration dependent on the existence of a package or the result of a command. But whatever I try: they always succeed, no matter what the result of the operation is. To reproduce, I just created the minimal pure C application and added these statements as follows:
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += \ main.c system(false):message("Message1") packagesExist(doesnotexist):message("Message2")
Both messages are printed, even if they should not. My platform:
- openSUSE Leap 15.3
- QMake version 3.1
- running from QtCreator
A similar problem was probably reported years ago, but without a solution: https://forum.qt.io/topic/62452/how-to-use-qmakes-packagesexists-function. What am I missing? What am I doing wrong? Or is anything wrong with my platform?
Edit: I just found out that when I run qmake manually from the command line then it seems to work! So what might be wrong with my QtCreator setup?
-
Hi and welcome to devnet,
Which version of Qt are you using ?
-
@letsfindaway said in qmake: packagesExist and system always succeed:
Both messages are printed
I just found out that when I run qmake manually from the command line then it seems to work!
Please be aware that Qt Creator does two different passes when reading .pro files: one "exact" pass, and one "inclusive" pass.
The "exact" pass is used for the code model, and evaluates conditions.
The "inclusive" pass is for the project tree, and basically ignores conditions. That is done so that if you e.g. have "win32:SOURCES+=foo_win.cpp" the file "foo_win.cpp" still appears in the project tree even if you are on Linux/macOS.So, the "reference" for if it works in qmake or not is the compile output when you compile your project.
-
@SGaist Same behavior for the Qt 5.12 still used as standard on Leap 15.3 and Qt 6.2. Here the output of querying the version:
> qmake-qt5 --version QMake version 3.1 Using Qt version 5.12.7 in /usr/lib64 > qmake6 --version QMake version 3.1 Using Qt version 6.2.4 in /usr/lib64 > qtcreator -version Qt Creator 4.12.0 based on Qt 5.12.7
-
@letsfindaway said in qmake: packagesExist and system always succeed:
Both messages are printed
I just found out that when I run qmake manually from the command line then it seems to work!
Please be aware that Qt Creator does two different passes when reading .pro files: one "exact" pass, and one "inclusive" pass.
The "exact" pass is used for the code model, and evaluates conditions.
The "inclusive" pass is for the project tree, and basically ignores conditions. That is done so that if you e.g. have "win32:SOURCES+=foo_win.cpp" the file "foo_win.cpp" still appears in the project tree even if you are on Linux/macOS.So, the "reference" for if it works in qmake or not is the compile output when you compile your project.
@ziller said in qmake: packagesExist and system always succeed:
Please be aware that Qt Creator does two different passes when reading .pro files: one "exact" pass, and one "inclusive" pass.
The "exact" pass is used for the code model, and evaluates conditions.
The "inclusive" pass is for the project tree, and basically ignores conditions. That is done so that if you e.g. have "win32:SOURCES+=foo_win.cpp" the file "foo_win.cpp" still appears in the project tree even if you are on Linux/macOS.So, the "reference" for if it works in qmake or not is the compile output when you compile your project.
I'm trying to use
packagesExist
for selecting a package and an optional other package. And always the first check succeeds, even if that package does not exist. The build fails if it is not the first checked package.The project file shown above is the minimal example to demonstrate the problem. Note that calling the
$$system()
function works, just the test functionssystem()
andpackagesExist()
are returning the wrong (always good) result. The command given to thesystem()
test function is never executed. -
I just found this comment to a quite old bug report from 2014 which might be related: https://bugreports.qt.io/browse/QTCREATORBUG-11510?focusedCommentId=233279&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-233279
Since we don't want to run arbitrary processes while parsing the project, the evaluator simply assumes that the process could be run successfully and thus packageExists returns true.
However I do not understand that, and also don't know how to resolve the issue.