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.7k 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 1 Oct 2018, 19:47 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 1 Oct 2018, 19:49 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
      • M Offline
        M Offline
        mzimmers
        wrote on 1 Oct 2018, 19:50 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 1 Oct 2018, 19:59 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
          • M Offline
            M Offline
            mzimmers
            wrote on 1 Oct 2018, 20:20 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 1 Oct 2018, 20:23 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

              A 1 Reply Last reply 1 Oct 2018, 20:26
              1
              • S SGaist
                1 Oct 2018, 20:23

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

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

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 1 Oct 2018, 20:26 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
                • M Offline
                  M Offline
                  mzimmers
                  wrote on 1 Oct 2018, 20:39 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.

                  A 1 Reply Last reply 1 Oct 2018, 20:51
                  0
                  • M mzimmers
                    1 Oct 2018, 20:39

                    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.

                    A Offline
                    A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on 1 Oct 2018, 20:51 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.

                    M 1 Reply Last reply 1 Oct 2018, 20:56
                    1
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 1 Oct 2018, 20:51 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
                      • A aha_1980
                        1 Oct 2018, 20:51

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

                        M Offline
                        M Offline
                        mzimmers
                        wrote on 1 Oct 2018, 20:56 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?

                        A 1 Reply Last reply 2 Oct 2018, 06:15
                        0
                        • M mzimmers
                          1 Oct 2018, 20:56

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

                          A Offline
                          A Offline
                          aha_1980
                          Lifetime Qt Champion
                          wrote on 2 Oct 2018, 06:15 last edited by aha_1980 10 Feb 2018, 06:16
                          #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

                          1/12

                          1 Oct 2018, 19:47

                          • Login

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