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. Qmake: check for environment variables

Qmake: check for environment variables

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 33.9k 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.
  • Z Offline
    Z Offline
    Zingam
    wrote on last edited by
    #1

    Hi,

    Is it possible to check in a .pro file if environment variables are defined?

    How could I do this in qmake:

    @ifdef AMDAPPSDKROOT
    INC_DIRS = "$(AMDAPPSDKROOT)include"
    endif

    ifdev NVSDKCOMPUTE_ROOT
    INC_DIRS = "$(NVSDKCOMPUTE_ROOT)\OpenCL\common\inc"
    endif@

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca.cossaro
      wrote on last edited by
      #2

      @contains(DEFINES, something) {

      do something

      } else {

      do something else

      }@

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zingam
        wrote on last edited by
        #3

        I am sorry but I cannot understand how can I use that. According to the docs that function does something different:

        bq. Succeeds if the variable variablename contains the value value; otherwise fails. You can check the return value of this function using a scope.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          luca.cossaro
          wrote on last edited by
          #4

          to use contains you have to define the variable when you run qmake.

          i.e:

          @qmake DEFINES+=MY_DEFINE@

          the if you can check in the .pro file:

          @
          contains(DEFINES, MY_DEFINE) {

          ...

          } else {

          ...

          }
          @

          obviously if the variable is defined in a source file (.h, .cpp, etc...) you can't get it from the .pro file. In this case I suggest to use a CONFIG to tell qmake what to do.

          i.e.

          if in your code is defined the variable DEF1 you can pass to qmake

          @qmake CONFIG+=DEF1_OK@

          and check in the .pro file:

          @
          contains(CONFIG, DEF1_OK) {

          ...

          } else {

          ...

          }
          @

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zingam
            wrote on last edited by
            #5

            Thank you. Your explanation is useful and clears a few things up but unfortunately I still cannot figure out the answer to my question. Probably I am not asking it properly.

            What I am trying to do is to check if a system variable is defined.
            For example AMDAPPSDKROOT and NVSDKCOMPUTE_ROOT should be defined as variables within the host operating system.
            I want to check if AMDAPPSDKROOT exists, which should be defined if the AMD SDK was installed. The second check is if the NVIDIA SDK was installed. If none of them are installed/no variables were defined/exported, no compilation should occur.

            In Qt Creator I can check that these variables were defined in Projects->Build Environment->Details. I can use these variables but I cannot figure out how to check if they are defined before I use them.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luca.cossaro
              wrote on last edited by
              #6

              ok, now I've got it.

              you can use the

              @$$system()@

              command to ask to SO if a variable is set

              i.e. (in linux)

              @
              message("Java root path: $$system(env | grep JAVA_ROOT)")

              will produce:

              Project MESSAGE: Java root path: JAVA_ROOT=/usr/lib/jvm/jre
              @

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zingam
                wrote on last edited by
                #7

                What I finally did is this. I have tested it only for NVIDIA's SDK for now. I guess it could be improved a little bit yet:

                @# Check for AMD APP SDK
                _AMDAPPSDK = $$(AMDAPPSDKROOT)
                isEmpty(_AMDAPPSDK) {
                message("AMD APP SDK" not detected...)
                }
                else {
                message("AMD APP SDK" detected in AMDAPPSDKROOT = "$$_AMDAPPSDK")
                DEFINES += _AMDAPPSDK
                }

                win32:contains(DEFINES , _AMDAPPSDK) {
                INCLUDEPATH += $$quote($$_AMDAPPSDKinclude)
                LIBS += -L$$quote($$_AMDAPPSDKlib/x86) -lOpenCL

                message(INCLUDEPATH = \"$$INCLUDEPATH\")
                message(LIBS = \"$$LIBS\")
                

                }

                Check for NVIDIA Compute SDK

                _NVIDIACOMPUTESDK = $$(NVSDKCOMPUTE_ROOT)
                isEmpty(_NVIDIACOMPUTESDK) {
                message("NVIDIA Compute SDK" not detected...)
                }
                else {
                message("NVIDIA Compute SDK" detected in NVSDKCOMPUTE_ROOT = "$$_NVIDIACOMPUTESDK")
                DEFINES += _NVIDIACOMPUTESDK
                }

                win32:contains( DEFINES , _NVIDIACOMPUTESDK ) {
                INCLUDEPATH += $$quote($$_NVIDIACOMPUTESDK/OpenCL/common/inc)
                LIBS += -L$$quote($$_NVIDIACOMPUTESDK/OpenCL/common/lib/Win32) -lOpenCL

                message(INCLUDEPATH = \"$$INCLUDEPATH\")
                message(LIBS = \"$$LIBS\")
                

                }
                @

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  AlterX
                  wrote on last edited by
                  #8

                  [quote author="luca.cossaro" date="1342597232"]@contains(DEFINES, something) {

                  do something

                  } else {

                  do something else

                  }@[/quote]

                  That's very interesting!

                  Qt Ambassador
                  Real-time cooperative teams: http://www.softairrealfight.net
                  Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                  https://codereview.qt-project.org/...

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    abhijeetmhatre
                    wrote on last edited by
                    #9

                    I think this is what you need.

                    DEFINES += FOO
                    contains(DEFINES,FOO){

                    }

                    !contains(DEFINES,FOO){

                    }

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      AlterX
                      wrote on last edited by
                      #10

                      Yes it is!

                      Qt Ambassador
                      Real-time cooperative teams: http://www.softairrealfight.net
                      Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                      https://codereview.qt-project.org/...

                      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