Is there a way to disallow “experimental” C++17 in CMake configuration?

自古美人都是妖i 提交于 2020-06-11 08:02:28

问题


I have set the following in my CMakeLists.txt:

set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)

However, CMake still allows g++ 6, even though it doesn't fully support c++17 (it has a c++1z standard, but not a c++17 standard). Is there a way to tell CMake to only allow compilers that fully support the standard and not just pieces of it?

FWIW, I also tried setting cxx_relaxed_constexpr, which I think should have been the relevant language feature, but that still allowed g++ 6. But it clearly can't compile code like

if constexpr (ENABLE_LOGGING) { do_loggy_stuff() };

So I'm not sure if there is a newer constexpr feature I should be looking for (there doesn't seem to be one in the latest cmake) or if CMake is just confused about what GCC 6 can do.

Edit: It seems I was slightly confused. Even though GCC 6 doesn't document c++17 as a value of -std, it does accept it as a synonym for c++-1z. So I guess what I'm looking for is a way to only look for "non-experimental" c++17 support.

Also, looking at the GCC documentation, it seems the feature I want is "constexpr if". Unfortunately, CMake doesn't recognize cxx_constexpr_if or cxx_if_constexpr as valid compile features.


回答1:


Is there a way to tell CMake to only allow compilers that fully support the standard and not just pieces of it?

No. CMake does not have that information.



来源:https://stackoverflow.com/questions/58332786/is-there-a-way-to-disallow-experimental-c17-in-cmake-configuration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!