Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use environment variable in a Qt qmake file (Windows)?

I have setted an environment variable like this:

XXX_ENV H:\xxx

I can see

H:\xxx

when I run command

echo %XXX_ENV%

in cmd. Then I have a Qt .pro file like this:

> INCLUDEPATH += ($$(XXX_ENV))/include

but unfortunately the INCLUDEPATH don't work, I can't use those .h file in H:\xxx\include

How can I use the environment varibale in qmake file ?

---------------------update---------------------------------

May be my description is not detaild enough.

This is the case. I have introduced a third party component into my project. The relevant files are in H:\XXX and i can use head files in H:\XXX\include. So my qmake can be writed like this:

INCLUDEPATH += H:/XXX/include

Then I can use head file "aaa.h" which is under directory H:\XXX\include just like this:

#include <aaa.h>

But I don't want to write the absolute path in the qmake file. So I seted a Windows environment variable(not qmake file's variable) XXX_ENV and it's value is "H:\XXX"(or "H:/XXX").

I just want to know can I write INCLUDEPATH += $${XXX_ENV}/include instead of INCLUDEPATH += H:/XXX/include

I tried it but it didn't work.

like image 912
Lion Young Avatar asked Oct 29 '14 02:10

Lion Young


1 Answers

See the documentation for details:

Variables can be used to store the contents of environment variables. These can be evaluated at the time that qmake is run, or included in the generated Makefile for evaluation when the project is built.

To obtain the contents of an environment value when qmake is run, use the $$(...) operator:

 DESTDIR = $$(PWD)
 message(The project will be installed in $$DESTDIR)

Your question seems to be imprecise as to what exactly "does not work" means, but you ought to use the quote function should you have spaces in the path, etc.

quote(string)

Converts a whole string into a single entity and returns the result. This is just a fancy way of enclosing the string into double quotes.

like image 57
lpapp Avatar answered Nov 15 '22 07:11

lpapp