Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qmake: check for environment variables

    General and Desktop
    4
    10
    32113
    Loading More Posts
    • 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
      Zingam last edited by

      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 Reply Quote 0
      • L
        luca.cossaro last edited by

        @contains(DEFINES, something) {

        do something

        } else {

        do something else

        }@

        1 Reply Last reply Reply Quote 0
        • Z
          Zingam last edited by

          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 Reply Quote 0
          • L
            luca.cossaro last edited by

            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 Reply Quote 0
            • Z
              Zingam last edited by

              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 Reply Quote 0
              • L
                luca.cossaro last edited by

                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 Reply Quote 0
                • Z
                  Zingam last edited by

                  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 Reply Quote 0
                  • A
                    AlterX last edited by

                    [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 Reply Quote 0
                    • A
                      abhijeetmhatre last edited by

                      I think this is what you need.

                      DEFINES += FOO
                      contains(DEFINES,FOO){

                      }

                      !contains(DEFINES,FOO){

                      }

                      1 Reply Last reply Reply Quote 0
                      • A
                        AlterX last edited by

                        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 Reply Quote 0
                        • First post
                          Last post