Solved Creator / qmake: Set environment needed to evaluate project tree
-
I'm trying to integrate existing auto-generated project import files, which require a specific environment variable to point to a specific path, like so:
SOURCES += \ $$(MLS_DIR)/frei/mlscodepage.cpp
I do not really want to set such environment variables globally. I would prefer a way that allows me to set these variables within Creator, however, I have not found a way to do so:
- My .pro file is not a good choice, because other people use it, and they may need different path
- I tried setting the MLS_DIR in the project setting's system environment section, but to no good result: It seems that qmake evaluates the project structure before these additions to the environment are made: When I output the environment variable through message, I get two passes: One where the variable is set correctly, one where it's empty. And the corresponding source files do not become part of the project tree.
Any ideas how to solve this?
-
Hi @Asperamanca,
It seems that qmake evaluates the project structure before these additions to the environment are made
This is correct when you use the
$$(...)
syntax. In your case, you want to use$(...)
instead.From qmake Lamguage - Variable Expansion:
To obtain the contents of an environment value when qmake is run, use the $$(...) operator:
...
To obtain the contents of an environment value at the time when the generated Makefile is processed, use the $(...) operator:Cheers.
-
I don't control these files, I have to live with what I get...
They are currently used in a batch-style make process, where a script sets all the correct variables up front. However, I would like to set up my project within creator so I can actually work with it.EDIT: Wait: According to the description you quoted, $$(...) would be the correct use, because Creator would not use the generated makefiles to build the source tree...?
-
The following seems to work fine...
I added the following to a sample .pro file:
message(A: $$(MLS_DIR)) message(B: $(MLS_DIR))
As expected, Qt Creator reloaded the project, with output:
Project MESSAGE: A: Project MESSAGE: B:
Then, in Qt Creator:
- clicked Projects
- selected the project under Active Project
- selected the Build item under Build & Run
- clicked the Details link to expand the Build Environment
- added a new
MLS_DIR
variable, setting it tomy-new-value
- clicked Edit (to go back the code editor view)
- right-clicked the project's top-level entry in the Projects tree
- clicked "Run qmake"
Qt Creator then ran qmake, and with the output:
Project MESSAGE: A: my-new-value Project MESSAGE: B: my-new-value
So it seems either will work, as long as you tell Qt Creator to re-run qmake after you've added the new environment variable to the build configuration? Give that a go (if you have't already).
$$(...) would be the correct use, because Creator would not use the generated makefiles to build the source tree...?
Qt Creator will use generated Makefiles (for qmake based projects), they're usually just in a folder where you don't notice them. For example, my Qt Creator is currently generating it under
/home/paul/tmp/build/<project-name>-Desktop_Qt_5_10_0_GCC_64bit-Debug/
.Cheers.
-
@Paul-Colby
Thanks for the elaborate answer. I think I'll set the environment variables on system level for now, and find a better solution together with the people who generate these files.