如果无法满足CMAKE_CXX_STANDARD,如何在CMake中干净地错误?
Cmake提供 CMAKE_CXX_STANDARD
用于指定所需的C ++标准。
set(cmake_cxx_standard 17)
但是,如果您的编译器旧了...说GCC4 ...它仍然会尝试编译来源,并且由于缺少丢失的奇异错误消息,它当然会失败编译器功能。
有没有干净的方法使CMAKE检测到这种缺失的支持并以更明显的方式失败?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用target_compile_features进行更多控制
,如 kamilcuk 10149169“>他们的答案,您可以检查CXX_STD_17。
此外,您可以在目标上设置需求:
源
https://cmake.org/cmake/help/help/latest/manual/cmake-compile-features.7.html#requiring-language-standards只有一些目标需要某些标准。同样的语法也可以仅需仅需要特定功能,在。
Simpler option for CMAKE_CXX_STANDARD, set CXX_STANDARD_REQUIRED
However, if you're using
您会收到一个错误,看起来像:
Using target_compile_features for more control
As KamilCuk mentioned in their answer, you can check for cxx_std_17.
Additionally, you can set the requirement on a target with:
Source https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html#requiring-language-standards
This is more verbose, but it allows you to specify that only some targets need certain standards. The same syntax can also be used to require only specific features, full list found in CMAKE_CXX_KNOWN_FEATURES.
Simpler option for CMAKE_CXX_STANDARD, set CXX_STANDARD_REQUIRED
However, if you're using
CMAKE_CXX_STANDARD
, it's much easier to just setCMAKE_CXX_STANDARD_REQUIRED
, e.g.:You'll get an error that looks something like:
From https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD .html :
来自 https://cmake.org/cmake/help/help/latest/manual/cmake-compile-features.7.html#manual:Cmake-compile-features(7):
来自 https://cmake.org/cmake/help/help/latest/prop_gbl/cmake_cxx_nown_nown_nown_features.html#prop_gbl:cmake_cxx_features
noreferrer
From https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_STANDARD.html :
From https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.html#manual:cmake-compile-features(7) :
From https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES :
Check: