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] qmake - possible to add header files based on a define?

[solved] qmake - possible to add header files based on a define?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.7k 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.
  • rootshellR Offline
    rootshellR Offline
    rootshell
    wrote on last edited by
    #1

    Currently I am working on a app that will need specific headers for specific linux distros, am curious to know how (if possible) to add headers and source based on the distro.

    In my pro file i am checking a environment variable to see if it is Ubuntu with Unity

    @linux{
    CURRENT_DESKTOP = $$(XDG_CURRENT_DESKTOP)
    equals($${CURRENT_DESKTOP}, "Unity")
    {
    DEFINES += "IS_UNITY=YES"
    }
    }@

    How do i add files based on the define?
    I tried:

    @contains(DEFINES, IS_UNITY)
    {
    headers += unity.h
    } else {
    headers += notunity.h
    }@

    But when the pro file is evaluated, both files are added, or i get "expected else"
    Thoughts?

    Certifications: CISSP, MCITP, MCSE, MCSA, BA, AA, AG, CST, CNST, Linux+, Security+, Server+, Network+, A+, iNet+

    Languages: C++, C#, VB, Python, Java

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

      Hi,

      IIRC

      @
      contains(DEFINES, IS_UNITY) { <- bracket position
      headers += unity.h
      } else {
      headers += notunity.h
      }@

      But are you sure you want to use two separate headers for that ? You could #ifdef the code

      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
      • rootshellR Offline
        rootshellR Offline
        rootshell
        wrote on last edited by
        #3

        Hmmm good point....

        perhaps i should re-think my plan :)

        Certifications: CISSP, MCITP, MCSE, MCSA, BA, AA, AG, CST, CNST, Linux+, Security+, Server+, Network+, A+, iNet+

        Languages: C++, C#, VB, Python, Java

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

          What is generally done is a common header file and if needed (as in: there is a lot of code), separate the implementation is several files e.g.

          myclass.h
          myclass.cpp
          myclass_win.cpp
          myclass_unix.cpp
          etc.

          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
          • rootshellR Offline
            rootshellR Offline
            rootshell
            wrote on last edited by
            #5

            SGalst -

            How do you go about loading the different source file...I mean for win vs Linux it is easy, but to get it on environment variable:

            @

            contains(DEFINES, IS_UNITY) {
            SOURCE += ubuntu.cpp
            } else {
            SOUECE += linux.cpp
            }

            @

            When i do the above it always adds both files, I fear I am doing it wrong :)

            Certifications: CISSP, MCITP, MCSE, MCSA, BA, AA, AG, CST, CNST, Linux+, Security+, Server+, Network+, A+, iNet+

            Languages: C++, C#, VB, Python, Java

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

              @
              DEFINES += IS_UNITY <- this is enough
              contains(DEFINES, IS_UNITY) {
              SOURCES += ubuntu.cpp
              } else {
              SOURCES += linux.cpp
              }@

              works for me. Well I replaced SOURCES with message for the test

              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
              • rootshellR Offline
                rootshellR Offline
                rootshell
                wrote on last edited by
                #7

                [quote author="SGaist" date="1396552163"]@
                DEFINES += IS_UNITY <- this is enough
                contains(DEFINES, IS_UNITY) {
                SOURCES += ubuntu.cpp
                } else {
                SOURCES += linux.cpp
                }@

                works for me. Well I replaced SOURCES with message for the test[/quote]

                Hmmm odd.....I get both the files no matter what, i switched it to message and got both messages as well. (Ubuntu 13.10 32 bit with Qt.5.2)

                @
                DEFINES += IS_UNITY
                contains(DEFINES, IS_UNITY) {
                message("Is unity")
                } else {
                message("Is not unity")
                }
                @

                Prints out:

                message: Is unity
                message Is not unity

                I did end up just putting #ifdef at the start of the code file and it worked that way but adding it in the pro file fires off both true and false.

                Certifications: CISSP, MCITP, MCSE, MCSA, BA, AA, AG, CST, CNST, Linux+, Security+, Server+, Network+, A+, iNet+

                Languages: C++, C#, VB, Python, Java

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

                  You seem to have qmake running twice. Can you print what XDG_CURRENT_DESKTOP contains ?

                  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

                  • Login

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