如何添加最低编译器版本必备? [英] How can I add a minimum compiler version requisite?
问题描述
我想在C ++ 11中创建一个项目,我使用CMake作为我的构建系统。
I want to create a project in C++11 and I use CMake as my build system.
如何在CMake中添加最小编译器版本必备config文件?
How can I add a minimum compiler version requisite in the CMake config files?
推荐答案
AFAIK,没有内置支持这样的东西,但你可以自己写:
AFAIK, there is no built-in support for something like this, but you could certainly write it yourself:
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "your.required.gcc.version")
message(FATAL_ERROR "Insufficient gcc version")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "your.required.msvc.version")
message(FATAL_ERROR "Insufficient msvc version")
endif()
elseif(...)
# etc.
endif()
但是,我建议你实际上考虑一个特征检测方法。也就是说,使用 try_compile()
来验证编译器是否支持你需要的特性,如果它不支持你的特性,则使用 FATAL_ERROR
t。它在CMake更惯用,并有额外的好处,你不必找到适当的最小版本的所有编译器在那里。
However, I suggest you actually consider a feature-detection approach instead. That is, use try_compile()
to verify that the compiler supports the features you need, and FATAL_ERROR
if it doesn't. It's more idiomatic in CMake, and has the added benefit you don't have to discover the appropriate minimal version for all compilers out there.
这篇关于如何添加最低编译器版本必备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!