How to analyze a KIT environment variable
-
Hi,
I want to use one QT application with two different KITs. One is for Linux (Ubuntu 18.04) and the other is for an embedded System (ARM).
Therefore I have to switch the include paths in the .pro file.
I set an environment variable in every KIT called TARGET. How can I create a if condition inside the .pro file? Or is there a possibility to use it like the standard defines unix, macx?Thanks
-
The contains function should do the job.
Although more standard approach is to modify the behaviour of
qmake
usingCONFIG
instead.contains(YOUR_ENV_VAR, "someValue") { message("The variable contains some value") }
Remember to change your env. var name from
TARGET
to something other - TARGET is already a keyword inqmake
. -
Hi sierdzio,
thanks for the fast reply but it doesn't work for me. I changed the Variable to TESTVAR=EMBEDDED and add the following line to .pro file:contains(TESTVAR,EMBEDDED) {
INCLUDEDIR += ...
}I also tried contains($TESTVAR,EMBEDDED) and contains(TESTVAR,"EMBEDDED") and contains($TESTVAR,"EMBEDDED") but nothing works.
Where is my mistake?
-
Perhaps this will:
LOCAL_VAR=$$(YOUR_ENV_VAR) contains(LOCAL_VAR, "EMBEDDED") { INCLUDEDIR += ... }
-
Ah that was my mistake. I have to set a local variable to use the contains command.
Okay that's the way I can use the environment variable inside the .pro file. How can I access the environment variable inside a .cpp file? With a #if directive? -
That's it.
Thanks a lot -
@hskoglund said in How to analyze a KIT environment variable:
Hi, in a .cpp file you can use getenv(), like this:
QString target = getenv("TARGET");
Or qEnvironmentVariable which returns a QString.