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.
  • R Robert Hairgrove

    @mrjj Thank you very much ... it looks like most of the suggested solutions rely on calling system(), so I shall try that, too (strange that this value is not already available [somehow] from the kit being used)?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @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 1 Reply Last reply
    1
    • mrjjM mrjj

      @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 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).

      mrjjM R 2 Replies Last reply
      0
      • R Robert Hairgrove

        @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).

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on 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

          @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 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.

          KroMignonK 1 Reply Last reply
          2
          • R Robert Hairgrove

            @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.

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on 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)

            mrjjM 1 Reply Last reply
            5
            • KroMignonK KroMignon

              @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?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on 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. :)

              KroMignonK 1 Reply Last reply
              1
              • mrjjM mrjj

                @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. :)

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on 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
                3
                • KroMignonK KroMignon

                  @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 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?

                  KroMignonK 1 Reply Last reply
                  0
                  • R Robert Hairgrove

                    @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?

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on 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 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
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 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

                        • Login

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