问题描述
有什么办法可以通过qmake获取用户使用的编译器的版本和厂商吗?我需要的是在使用 g++ 3.x 时禁用构建我的项目的某些目标,并在使用 g++ 4.x 时启用它们.
Is there any way to get the version and vendor of the compiler used by the user through qmake? What I need is to disable building some targets of my project when g++ 3.x is used and enable them when g++ 4.x is used.
更新:大多数答案都针对预处理器.这是我想要避免的.我不希望为特定的编译器版本构建目标,我希望由构建系统做出这个决定.
Update: Most answers targeted the preprocessor. This is something that I want to avoid. I don't want a target to be build for a specific compiler version and I want this decision to be made by the build system.
推荐答案
除了 ashcatch 的答案,qmake
允许您查询命令行 并将响应作为变量返回.所以你可以这样做:
In addition to ashcatch's answer, qmake
allows you to query the command line and get the response back as a variable. So you could to something like this:
linux-g++ {
system( g++ --version | grep -e "<4.[0-9]" ) {
message( "g++ version 4.x found" )
CONFIG += g++4
}
else system( g++ --version | grep -e "<3.[0-9]" ) {
message( "g++ version 3.x found" )
CONFIG += g++3
}
else {
error( "Unknown system/compiler configuration" )
}
}
然后,当你想用它来指定目标时,你可以使用配置范围规则:
Then later, when you want to use it to specify targets, you can use the config scoping rules:
SOURCES += blah blah2 blah3
g++4: SOURCES += blah4 blah5
这篇关于使用 qmake 查找编译器供应商/版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!