使用qmake查找编译器供应商/版本 [英] Finding compiler vendor / version using qmake

查看:100
本文介绍了使用qmake查找编译器供应商/版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以获得用户通过qmake使用的编译器的版本和供应商?我需要的是在使用g ++ 3.x时禁用构建我的项目的一些目标,并在使用g ++ 4.x时启用它们。



更新: 大多数答案针对预处理器。这是我想避免的。我不想为一个特定的编译器版本构建一个目标,我想这个决定是由构建系统。

解决方案

除了 ashcatch 的答案, code> qmake 可让您查询命令行,并将响应作为变量获取。所以你可以这样:

  linux-g ++ {
system(g ++ --version | grep -e \< 4。[0-9]){
message(g ++ version 4.x found)
CONFIG + = g ++ 4
}
else {
message(g ++ version 3.x found)
CONFIG + = g + +3
}
else {
错误(未知系统/编译器配置)
}
}
pre>

然后,当您想要使用它来指定目标时,可以使用配置范围规则:

  SOURCES + = blah blah2 blah3 
g ++ 4:SOURCES + = blah4 blah5


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.

解决方案

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查找编译器供应商/版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆