How to detect GCC version in qmake (variable for .pro file)?
-
@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)?@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. -
@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.@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 whatg++ --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).
-
@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 whatg++ --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).
@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. -
@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 whatg++ --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).
@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.
-
@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.
@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
andQMAKE_CXX.QMAKE_GCC_PATCH_VERSION
? -
@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
andQMAKE_CXX.QMAKE_GCC_PATCH_VERSION
?@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. :) -
@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. :)@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
-
@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
@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?
-
@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?
@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 fromqmake
tocmake
as main build system, they may be obsolete. -
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!
-
@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.