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)?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 3.8k Views
  • 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 Offline
    R Offline
    Robert Hairgrove
    wrote on 5 Jul 2020, 15:46 last edited by
    #1

    I would like to turn off a specific warning in the .pro file depending on what version of GCC is used. Specifically, if GCC version is 9.x. or greater, I would like to add the line QMAKE_CXXFLAGS += -Wno-deprecated-copy and otherwise leave it alone.

    However, I can't seem to find the correct variable syntax in the docs. Something similar to this?

    if ($GCC_VERSION >= 9) {
      QMAKE_CXXFLAGS += -Wno-deprecated-copy
    }
    

    But what would go inside the if (...) part?

    1 Reply Last reply
    1
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 5 Jul 2020, 15:50 last edited by
      #2

      Hi
      I dont know if there is a newer/ better way but i used
      https://stackoverflow.com/questions/801279/finding-compiler-vendor-version-using-qmake
      the "system" way.

      R 1 Reply Last reply 5 Jul 2020, 16:14
      3
      • M mrjj
        5 Jul 2020, 15:50

        Hi
        I dont know if there is a newer/ better way but i used
        https://stackoverflow.com/questions/801279/finding-compiler-vendor-version-using-qmake
        the "system" way.

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

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

        M 1 Reply Last reply 5 Jul 2020, 16:22
        0
        • R Robert Hairgrove
          5 Jul 2020, 16:14

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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 5 Jul 2020, 16:22 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 5 Jul 2020, 16:41
          1
          • 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

                              5/14

                              5 Jul 2020, 16:41

                              topic:navigator.unread, 9
                              • Login

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