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. Check if environment variable set
Forum Updated to NodeBB v4.3 + New Features

Check if environment variable set

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.2k Views 1 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.
  • A Offline
    A Offline
    altendky
    wrote on 25 Oct 2013, 19:26 last edited by
    #1

    (using Qt SDK 4.8.5 under Windows 7 x64)

    In my .PRO, if the environment variable BUILD_NUMBER is set I want to:

    @
    DEFINES += "BUILD_NUMBER=$(BUILD_NUMBER)"
    @

    otherwise just do nothing... but I can't figure out how to do this cleanly. This does not work.

    @
    BUILD_NUMBER = $(BUILD_NUMBER)
    !isEmpty(BUILD_NUMBER) {
    DEFINES += "BUILD_NUMBER=$(BUILD_NUMBER)"
    }
    @

    It seems that BUILD_NUMBER is always not empty even when I print it using message (as below) and it is empty (no space between > and <).

    @
    message(>$$BUILD_NUMBER<)
    @

    My first working solution is (ugly, but also what's below):

    @
    win* {
    CHECK_BUILD_NUMBER_COMMAND = IF DEFINED BUILD_NUMBER (exit /b 0) ELSE (exit /b 1)
    }
    unix {
    CHECK_BUILD_NUMBER_COMMAND = if [ -n "$BUILD_NUMBER" ]; then exit 0; else exit 1; fi
    }
    system($$CHECK_BUILD_NUMBER_COMMAND):BUILD_NUMBER = $(BUILD_NUMBER)

    !isEmpty(BUILD_NUMBER) {
    DEFINES += "BUILD_NUMBER=$$BUILD_NUMBER"
    }
    @

    Thanks for any pointers.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 26 Oct 2013, 08:17 last edited by
      #2

      See "this":http://qt-project.org/forums/viewthread/12578.

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        altendky
        wrote on 28 Oct 2013, 12:58 last edited by
        #3

        Thanks for the response but I don't understand how that relates. My kludgy fix involves quoting and shell calls but the problem seems to be that isEmpty() doesn't work correctly (unrelated to quoting and shell calls).

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 28 Oct 2013, 13:09 last edited by
          #4

          Oh, that thing.
          @
          isEmpty($${BUILD_NUMBER}) {
          DEFINES += "BUILD_NUMBER=$${BUILD_NUMBER}"
          }
          @

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            altendky
            wrote on 28 Oct 2013, 20:20 last edited by
            #5

            Nope... apparently I wasn't curious enough at the beginning. This works:

            @
            BUILD_NUMBER = $$(BUILD_NUMBER)
            !isEmpty(BUILD_NUMBER) {
            DEFINES += "BUILD_NUMBER=$$BUILD_NUMBER"
            }
            @

            Note the double-$ on the first line as opposed to the single-$ in my first attempt. For the record, the double-$ gets the value when QMake runs but the single-$ gets the value when make runs the generated Makefiles. So, a bit convoluted and not exactly directly debuggable, but it seems that's it.

            http://qt-project.org/doc/qt-4.8/qmake-advanced-usage.html#variables

            Thanks again for the effort.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 29 Oct 2013, 07:04 last edited by
              #6

              OK, thanks in return for posting the result :)

              QMake is indeed a bit unfriendly when doing anything more advanced. It will probably be replaced by another system in some future release (a very distant kind of future ;) ).

              (Z(:^

              1 Reply Last reply
              0

              4/6

              28 Oct 2013, 13:09

              • Login

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