Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Having custom variables in Makefile
QtWS25 Last Chance

[SOLVED] Having custom variables in Makefile

Scheduled Pinned Locked Moved General and Desktop
qmakemakemakefile
16 Posts 3 Posters 7.3k Views
  • 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.
  • K Offline
    K Offline
    kumararajas
    wrote on last edited by kumararajas
    #4

    Hi,

    Later to a quick search and experiments, I have got what I have wanted but partially.

    Here are the details:

    My Makefile looks like this:

    export BOOST_LIBS_PATH=/path/to/boost
    
    all:
            qmake -o Makefilegen testqmake.pro
    

    As it says, it exports a path, and creates Makefilegen using testqmake.pro.

    testqmake.pro looks like this:

    TEMPLATE = app
    TARGET = myapp
    DEPENDPATH += .
    INCLUDEPATH += .
    
    # Input
    SOURCES += main.cpp
    
    DEFINES += "MYPATH=\"$(BOOST_LIBS_PATH)\""
    
    message("Master pro file path : ["$(BOOST_LIBS_PATH)"]")
    
    MYTESTPATH = $(BOOST_LIBS_PATH)/er/er/er/e
    
    message("My path : ["$${MYTESTPATH}"]")
    

    And in the console

    Project MESSAGE: Master pro file path : [/path/to/boost]
    Project MESSAGE: My path : [/path/to/boost/er/er/er/e]
    Project MESSAGE: My path : [/lib/aaa/bbb]
    

    But, I want to take this to my source code. But it doesn't work

    DEFINES += "MYPATH=\"$(BOOST_LIBS_PATH)\""
    

    In the generated Makefile

    DEFINES       = -DQT_WEBKIT -DMYPATH=$(BOOST_LIBS_PATH) -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
    

    I wish to get as

    DEFINES       = -DQT_WEBKIT -DMYPATH="/path/to/boost" -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
    

    How do I pass a variable to defines?

    --Kumar

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

      You'll have to escape your string more than that:

      TESTSTR = '\"$$(TEST)\"'
      DEFINES += TEST=\"$${TESTSTR}\"

      SOURCES += main.cpp

      [edit: fixed code sample SGaist]

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

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        You'll have to escape your string more than that:

        TESTSTR = '\"$$(TEST)\"'
        DEFINES += TEST=\"$${TESTSTR}\"

        SOURCES += main.cpp

        [edit: fixed code sample SGaist]

        K Offline
        K Offline
        kumararajas
        wrote on last edited by kumararajas
        #6

        @SGaist Thanks Sam.

        With your thoughts,

        WAT+="\"/lib/aaa/bbb"\"
        DEFINES += WAT=$${WAT}
        
        GCPU_PATH=$(BOOST_LIBS_PATH)
        DEFINES+=GCPU_PATH=$${GCPU_PATH}
        

        And this is how the generated Makefile looks like:

        DEFINES       = -DQT_WEBKIT -DWAT="/lib/aaa/bbb" -DGCPU_PATH=$(BOOST_LIBS_PATH) -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
        

        What I see here is, with the local variables, it looks to be working.

        but the environment variable, I am not able to acheive.
        -DGCPU_PATH=$(BOOST_LIBS_PATH) I expect this to be -DGCPU_PATH="/path/to/boost"

        Any more thoughts?

        Thank you,
        Kumara

        --Kumar

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

          Sorry, it seems that the code highlighter is not working exactly the same when you are editing the answer and once it's re-loaded.

          I've fixed it. Please take a look again, it's already working for environment variables.

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

          K 1 Reply Last reply
          0
          • SGaistS SGaist

            Sorry, it seems that the code highlighter is not working exactly the same when you are editing the answer and once it's re-loaded.

            I've fixed it. Please take a look again, it's already working for environment variables.

            K Offline
            K Offline
            kumararajas
            wrote on last edited by kumararajas
            #8

            Sam, I am bit confused.

            If I understand correctly,

            Having your code,

            TESTSTR = '\\"$\\"'
            DEFINES += TEST=\"$\"
            

            Should I need to add my environment variable here?
            Example:

            TSTR = '\\"$(BOOST_PATH)\\"'
            DEFINES += TEST=$${TSTR}
            

            Makefile looks like this:

            -DTEST=\"$(BOOST_PATH)\"
            

            Or I understood wrongly?

            Please clarify. Thank you very much for your kind help..

            --Kumara

            --Kumar

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

              Sorry again about the code formatting…

              Trying again here:

              TESTSTR = '\\"$$(TEST)\\"'
              DEFINES += TEST=\"\$\$\{TESTSTR\}\"

              On that last line remove the backslashes before the dollar signs and curly braces...

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

              K 1 Reply Last reply
              0
              • SGaistS SGaist

                Sorry again about the code formatting…

                Trying again here:

                TESTSTR = '\\"$$(TEST)\\"'
                DEFINES += TEST=\"\$\$\{TESTSTR\}\"

                On that last line remove the backslashes before the dollar signs and curly braces...

                K Offline
                K Offline
                kumararajas
                wrote on last edited by kumararajas
                #10

                I did try the exact as you said..
                STRT = '\\"$(BOOST_PATH)\\"'
                DEFINES += BOOST_PATH=\"\$\$\{STRT\}\"
                And the output is,
                -DBOOST_PATH="$${STRT}"

                And I tried removing the back slashes on dollar sign and curly braces
                STRT = '\\"$(BOOST_PATH)\\"'
                DEFINES += BOOST_PATH=\"$${STRT}\"
                And the output is
                -DBOOST_PATH="\"$(BOOST_PATH)\""

                Still no success..

                --Kumara

                --Kumar

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

                  What do you get for the various variable if you show a message with their content:

                  e.g.

                  message($$(BOOST_PATH))
                  message(\$\$\{STRT\})
                  ?

                  Again, remove the backslashes in the second line...

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

                  K 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    What do you get for the various variable if you show a message with their content:

                    e.g.

                    message($$(BOOST_PATH))
                    message(\$\$\{STRT\})
                    ?

                    Again, remove the backslashes in the second line...

                    K Offline
                    K Offline
                    kumararajas
                    wrote on last edited by kumararajas
                    #12

                    While printing a message, it looks good.

                    message($(BOOST_PATH))

                    Project MESSAGE: /path/to/boost
                    

                    message($${STRT})

                    Project MESSAGE: \"/path/to/boost\"
                    

                    But why this has not been taken to Makefile? Mysteries..

                    --Kumar

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

                      Then you are likely just missing some escaping for the last call...

                      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
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        Finally found a way to write it:

                        BOOST = $ $ ( BOOST_PATH )
                        BOOST_STR = ' \ \ " $ $ { BOOST } \ \ " '
                        DEFINES += BOOST_PATH= \ " $ $ { BOOST_STR } \ "
                        

                        Extra spaces to be removed for the sample code

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

                        K 1 Reply Last reply
                        1
                        • SGaistS SGaist

                          Finally found a way to write it:

                          BOOST = $ $ ( BOOST_PATH )
                          BOOST_STR = ' \ \ " $ $ { BOOST } \ \ " '
                          DEFINES += BOOST_PATH= \ " $ $ { BOOST_STR } \ "
                          

                          Extra spaces to be removed for the sample code

                          K Offline
                          K Offline
                          kumararajas
                          wrote on last edited by
                          #15

                          Thanks Sam, for helping me to fix the problem.

                          I do confirm that, it works.

                          (I do not want copy the instruction again here, which contains more spaces :P)

                          With the above code, I can see this in my Makefile

                          -DBOO_PATH="/path/to/boost"
                          

                          It has been a great help! Thanks a lot.

                          --Kumara

                          --Kumar

                          K 1 Reply Last reply
                          0
                          • K kumararajas

                            Thanks Sam, for helping me to fix the problem.

                            I do confirm that, it works.

                            (I do not want copy the instruction again here, which contains more spaces :P)

                            With the above code, I can see this in my Makefile

                            -DBOO_PATH="/path/to/boost"
                            

                            It has been a great help! Thanks a lot.

                            --Kumara

                            K Offline
                            K Offline
                            kumararajas
                            wrote on last edited by kumararajas
                            #16

                            Later to that,

                            I have figured out a problem in having:

                            We need to have \" in the argument:
                            -DBOO_PATH="/path/to/boost"
                            Problem is that, the macro turned out to be
                            #define BOO_PATH /path/to/boost
                            which is actually useless. We need to have double quotes to cover them up.

                            BOOST =  $ $ ( BOOST_PATH )
                            BOOST_STR = ' \ \ " $ $ { BOOST } \ \ " '
                            DEFINES += BOOST_PATH=\ " $ $ { BOOST_STR } \"
                            

                            Again, eliminate the spaces :)

                            --Kumar

                            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