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. How to detect GCC version in qmake (variable for .pro file)?
Forum Updated to NodeBB v4.3 + New Features

How to detect GCC version in qmake (variable for .pro file)?

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 4.1k Views 2 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.
  • M mrjj
    5 Jul 2020, 16:22

    @Robert-Hairgrove
    Yeah the SO post is very old so i also wonderd if Qmake had something for it by now but
    didnt find any.

    R Offline
    R Offline
    Robert Hairgrove
    wrote on 5 Jul 2020, 16:41 last edited by
    #5

    @mrjj Thank you ... I was starting to feel a little incompetent, thinking that there must be a very trivial answer to this which I could not see! :) Obviously, it seems still not such a trivial thing, especially if one has multiple compiler versions installed -- it is possible to configure a project with different kits, so calling system() and querying GCC will only return what g++ --version would also return.

    The solution suggested by Eric Lemanissier seems to be the best for that situation, AFAICT (3rd from the bottom in that thread).

    M R 2 Replies Last reply 5 Jul 2020, 16:46
    0
    • R Robert Hairgrove
      5 Jul 2020, 16:41

      @mrjj Thank you ... I was starting to feel a little incompetent, thinking that there must be a very trivial answer to this which I could not see! :) Obviously, it seems still not such a trivial thing, especially if one has multiple compiler versions installed -- it is possible to configure a project with different kits, so calling system() and querying GCC will only return what g++ --version would also return.

      The solution suggested by Eric Lemanissier seems to be the best for that situation, AFAICT (3rd from the bottom in that thread).

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 5 Jul 2020, 16:46 last edited by
      #6

      @Robert-Hairgrove
      Hi
      Well, I kinda gave up after not even the secret of qmake seems to have anything for it :)
      https://wiki.qt.io/Undocumented_QMake
      and also felt like you that i must overlook it or something.

      Yes, i also noticed his way which also seems very elegant/compact.
      I didn't try it but please report back if it just works.

      1 Reply Last reply
      0
      • R Robert Hairgrove
        5 Jul 2020, 16:41

        @mrjj Thank you ... I was starting to feel a little incompetent, thinking that there must be a very trivial answer to this which I could not see! :) Obviously, it seems still not such a trivial thing, especially if one has multiple compiler versions installed -- it is possible to configure a project with different kits, so calling system() and querying GCC will only return what g++ --version would also return.

        The solution suggested by Eric Lemanissier seems to be the best for that situation, AFAICT (3rd from the bottom in that thread).

        R Offline
        R Offline
        Robert Hairgrove
        wrote on 6 Jul 2020, 08:43 last edited by
        #7

        @Robert-Hairgrove This works now:

        gcc {
            COMPILER_VERSION = $$system($$QMAKE_CXX " -dumpversion")
            COMPILER_MAJOR_VERSION = $$str_member($$COMPILER_VERSION)
            greaterThan(COMPILER_MAJOR_VERSION, 7): QMAKE_CXXFLAGS += -Wno-deprecated-copy
        }
        

        Marking as solved.

        K 1 Reply Last reply 6 Jul 2020, 11:21
        2
        • R Robert Hairgrove
          6 Jul 2020, 08:43

          @Robert-Hairgrove This works now:

          gcc {
              COMPILER_VERSION = $$system($$QMAKE_CXX " -dumpversion")
              COMPILER_MAJOR_VERSION = $$str_member($$COMPILER_VERSION)
              greaterThan(COMPILER_MAJOR_VERSION, 7): QMAKE_CXXFLAGS += -Wno-deprecated-copy
          }
          

          Marking as solved.

          K Offline
          K Offline
          KroMignon
          wrote on 6 Jul 2020, 11:21 last edited by
          #8

          @Robert-Hairgrove said in How to detect GCC version in qmake (variable for .pro file)?:

          This works now:

          Just for my understanding, what's wrong with QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION, QMAKE_CXX.QMAKE_GCC_MINOR_VERSION and QMAKE_CXX.QMAKE_GCC_PATCH_VERSION?

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          M 1 Reply Last reply 6 Jul 2020, 11:34
          5
          • K KroMignon
            6 Jul 2020, 11:21

            @Robert-Hairgrove said in How to detect GCC version in qmake (variable for .pro file)?:

            This works now:

            Just for my understanding, what's wrong with QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION, QMAKE_CXX.QMAKE_GCC_MINOR_VERSION and QMAKE_CXX.QMAKE_GCC_PATCH_VERSION?

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 6 Jul 2020, 11:34 last edited by
            #9

            @KroMignon said in How to detect GCC version in qmake (variable for .pro file)?:

            QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION

            Where in docs are those listed?
            I think it what poster was after so there might be nothing wrong with them at all. :)

            K 1 Reply Last reply 6 Jul 2020, 11:41
            1
            • M mrjj
              6 Jul 2020, 11:34

              @KroMignon said in How to detect GCC version in qmake (variable for .pro file)?:

              QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION

              Where in docs are those listed?
              I think it what poster was after so there might be nothing wrong with them at all. :)

              K Offline
              K Offline
              KroMignon
              wrote on 6 Jul 2020, 11:41 last edited by
              #10

              @mrjj said in How to detect GCC version in qmake (variable for .pro file)?:

              Where in docs are those listed?

              Hmm, don't rememder where I found them, but depending on current compiler there are differente variables which are setup during qmake call:

              • GCC: QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION, QMAKE_CXX.QMAKE_GCC_MINOR_VERSION and QMAKE_CXX.QMAKE_GCC_PATCH_VERSION
              • CLANG: QMAKE_CXX.QMAKE_CLANG_MAJOR_VERSION, QMAKE_CXX.QMAKE_CLANG_MINOR_VERSION and QMAKE_CXX.QMAKE_CLANG_PATCH_VERSION

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              R 1 Reply Last reply 6 Jul 2020, 11:46
              3
              • K KroMignon
                6 Jul 2020, 11:41

                @mrjj said in How to detect GCC version in qmake (variable for .pro file)?:

                Where in docs are those listed?

                Hmm, don't rememder where I found them, but depending on current compiler there are differente variables which are setup during qmake call:

                • GCC: QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION, QMAKE_CXX.QMAKE_GCC_MINOR_VERSION and QMAKE_CXX.QMAKE_GCC_PATCH_VERSION
                • CLANG: QMAKE_CXX.QMAKE_CLANG_MAJOR_VERSION, QMAKE_CXX.QMAKE_CLANG_MINOR_VERSION and QMAKE_CXX.QMAKE_CLANG_PATCH_VERSION
                R Offline
                R Offline
                Robert Hairgrove
                wrote on 6 Jul 2020, 11:46 last edited by
                #11

                @KroMignon Thank you ... just what I was looking for. Like @mrjj said, though, I never saw this before anywhere. And typing a dot after QMAKE_CXX doesn't give any autocomplete entry, either.

                I suppose this is an undocumented feature?

                K 1 Reply Last reply 6 Jul 2020, 11:50
                0
                • R Robert Hairgrove
                  6 Jul 2020, 11:46

                  @KroMignon Thank you ... just what I was looking for. Like @mrjj said, though, I never saw this before anywhere. And typing a dot after QMAKE_CXX doesn't give any autocomplete entry, either.

                  I suppose this is an undocumented feature?

                  K Offline
                  K Offline
                  KroMignon
                  wrote on 6 Jul 2020, 11:50 last edited by
                  #12

                  @Robert-Hairgrove said in How to detect GCC version in qmake (variable for .pro file)?:

                  I suppose this is an undocumented feature?

                  Maybe, I am only a Qt user, I am not involved in Qt development, so I don't know if those variables are "hidden features".
                  But as Qt is moving from qmake to cmake as main build system, they may be obsolete.

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply
                  1
                  • R Offline
                    R Offline
                    Robert Hairgrove
                    wrote on 6 Jul 2020, 12:04 last edited by
                    #13

                    Actually, I just discoverd that it also works just as well without the QMAKE_CXX prefix. So now the entry in my .pro file looks like this:

                    gcc {
                      greaterThan(QMAKE_GCC_MAJOR_VERSION, 7): QMAKE_CXXFLAGS += -Wno-deprecated-copy
                    }
                    

                    Now it is perfect!

                    1 Reply Last reply
                    4
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 6 Jul 2020, 12:18 last edited by
                      #14

                      @KroMignon said in How to detect GCC version in qmake (variable for .pro file)?:

                      But as Qt is moving from qmake to cmake as main build system, they may be obsolete.

                      That only for building Qt itself. Not for building apps with Qt as that would break many, many projects and
                      also my heart.

                      1 Reply Last reply
                      2

                      14/14

                      6 Jul 2020, 12:18

                      • Login

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