Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. using variables for paths in project file
Forum Updated to NodeBB v4.3 + New Features

using variables for paths in project file

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
12 Posts 3 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    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...

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Is IDF_PATH an environment variable ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        It certainly could be, or I could create it within Qt. Either way is fine with me.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          To get the content of a variable you should use: $$VARIABLE_NAME and it's an environment variable use $${ENV_VAR_NAME}.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            That much I understand. Now, how do I fit that prefix to the rest of the path? Meaning, something like this (but this doesn't work):

            $$IDFPATH + "\components\bt\include"
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              INCLUDEPATH += $$IDFPATH/components/bt/include

              You can (and should) use forward slash also on Windows. qmake will do the necessary conversions for you.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              aha_1980A 1 Reply Last reply
              1
              • SGaistS SGaist

                INCLUDEPATH += $$IDFPATH/components/bt/include

                You can (and should) use forward slash also on Windows. qmake will do the necessary conversions for you.

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @SGaist

                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...

                Qt has to stay free or it will die.

                1 Reply Last reply
                1
                • mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by
                  #8

                  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.

                  aha_1980A 1 Reply Last reply
                  0
                  • mzimmersM mzimmers

                    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.

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @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...

                    Qt has to stay free or it will die.

                    mzimmersM 1 Reply Last reply
                    1
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10
                      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.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2
                      • aha_1980A aha_1980

                        @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...

                        mzimmersM Offline
                        mzimmersM Offline
                        mzimmers
                        wrote on last edited by
                        #11

                        @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?

                        aha_1980A 1 Reply Last reply
                        0
                        • mzimmersM mzimmers

                          @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?

                          aha_1980A Offline
                          aha_1980A Offline
                          aha_1980
                          Lifetime Qt Champion
                          wrote on last edited by aha_1980
                          #12

                          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.

                          Qt has to stay free or it will die.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved