using variables for paths in project file
-
Hi all -
I have a project that relies heavily on a third-party IDF. I have many entries in my .pro file pointing to subdirectories of this IDF, like so:
INCLUDEPATH += \ "C:\esp-idf-release-v3.2\components\bt\include" \ "C:\esp-idf-release-v3.2\components\bt\bluedroid\api\include\api" \ "C:\esp-idf-release-v3.2\components\coap\port\include" \ "C:\esp-idf-release-v3.2\components\console" \ "C:\esp-idf-release-v3.2\components\driver\include" \ "C:\esp-idf-release-v3.2\components\esp_adc_cal\include" \ "C:\esp-idf-release-v3.2\components\esp32\include" \ "C:\esp-idf-release-v3.2\components\esp_https_ota\include" \ ...
The root directory of this IDF changes, and I'd like to use a variable (Qt or Windows) to hold it, so my .pro file would look something like:
INCLUDEPATH += \ $IDF_PATH"\components\bt\include" \ ...
But I don't know the correct syntax. Couldn't find it on the QMake variables page. Can someone show me the light?
Thanks...
-
Hi,
Is
IDF_PATH
an environment variable ? -
To get the content of a variable you should use:
$$VARIABLE_NAME
and it's an environment variable use$${ENV_VAR_NAME}
. -
INCLUDEPATH += $$IDFPATH/components/bt/include
You can (and should) use forward slash also on Windows. qmake will do the necessary conversions for you.
-
INCLUDEPATH += $$IDFPATH/components/bt/include
You can (and should) use forward slash also on Windows. qmake will do the necessary conversions for you.
I'd say you must ;)
And a hint to @mzimmers: never end a line with a backslash or a slash - this will lead to problems sooner or later. I have had big problems already when doing something like:
INCLUDEPATH += $$IDFPATH/components/bt/include/
as the last slash was converted to backslash and there to problems begun... -
Yeah, I was just being lazy...I'd grabbed those paths from somewhere else and just plugged them in verbatim. Now corrected.
So, aha - if I can't end a line with a backslash, when I want to use one as a concatenator, should I move it to the start of the next line?
Thanks, guys.
-
Yeah, I was just being lazy...I'd grabbed those paths from somewhere else and just plugged them in verbatim. Now corrected.
So, aha - if I can't end a line with a backslash, when I want to use one as a concatenator, should I move it to the start of the next line?
Thanks, guys.
@mzimmers said in using variables for paths in project file:
when I want to use one as a concatenator,
You don't want to.
A backslash at the end-of-line in a
.pro
file is always line-continuation. But forward slashes may be translated in the generated Makefile and that's where the fun begins... -
MYPATH = /usr/include MYOTHERPATH = $$MYPATH/mylib
If you need backslashes then you have to double them as you would in a classic C string. However, you really should use forward slashes.
-
@mzimmers said in using variables for paths in project file:
when I want to use one as a concatenator,
You don't want to.
A backslash at the end-of-line in a
.pro
file is always line-continuation. But forward slashes may be translated in the generated Makefile and that's where the fun begins... -
@aha_1980 I misspoke - I didn't mean concatenator; I meant line continuator. I interpreted your earlier statement as saying a backslash shouldn't end a line, but I guess you meant when used as part of a Windows-style path?
Hi @mzimmers,
you're right, the backslash is the line continuator for qmake.
but I guess you meant when used as part of a Windows-style path?
Also correct.
But what could be unexpected, is if you end a Unix-style path with '/', this will be converted to a backslash in the Makefile an can lead to fun there also.