TestCXXAcceptsFlag¶
自 3.0 版本起已弃用: 此模块不应再使用。它已被 CheckCXXCompilerFlag 模块取代。截至 CMake 3.19,CheckCompilerFlag 模块也可用,用于检查跨多种语言的标志。
此模块提供一个命令来测试 C++ (CXX) 编译器是否支持特定标志。
在 CMake 项目中加载此模块,使用
include(TestCXXAcceptsFlag)
命令¶
此模块提供以下命令
- check_cxx_accepts_flag¶
检查 CXX 编译器是否接受指定的标志
check_cxx_accepts_flag(<flags> <result-variable>)
<flags>要测试的一个或多个编译器标志。对于多个标志,请将它们提供为一个空格分隔的字符串。
<result-variable>存储结果的内部缓存变量的名称。如果编译器接受标志,则设置为布尔值 true,否则设置为 false。
示例¶
检查 C++ 编译器是否支持特定标志
include(TestCXXAcceptsFlag)
check_cxx_accepts_flag("-fno-common -fstack-clash-protection" HAVE_FLAGS)
迁移到 CheckCompilerFlag 模块
include(CheckCompilerFlag)
check_compiler_flag(CXX "-fno-common;-fstack-clash-protection" HAVE_FLAGS)