简体   繁体   English

尽管我将 target_compile_features 设置为 cxx_std_17

[英]CMake does not set the compiler option -std to gnu17 or c++17 although I set the target_compile_features to cxx_std_17

I updated the versions of GCC and CMake.我更新了 GCC 和 CMake 的版本。 After the update CMake no longer sets the right command line option for the c++ standard.更新后 CMake 不再为 c++ 标准设置正确的命令行选项。

Here is how I set it:这是我的设置方式:

add_library(project_options INTERFACE)
target_compile_features(project_options INTERFACE cxx_std_17)

and then I link to the project_options然后我链接到 project_options

target_link_libraries(app PRIVATE project_options)

With GCC 8.3 (on rhel) this sets the std compile flag to -std=gnu17使用 GCC 8.3(在 rhel 上)这会将 std 编译标志设置为-std=gnu17

Now it is set to -std=c++11现在设置为-std=c++11

If I set the compiler globally it works as expected:如果我全局设置编译器,它会按预期工作:

set(CMAKE_CXX_STANDARD 17)

What am I missing?我错过了什么? Or is this a bug in the new Tools?或者这是新工具中的错误?

My System:我的系统:

  • GCC: 11.1.0 GCC:11.1.0
  • CMake: 3.20.2 CMake:3.20.2

You need to set the target property CXX_STANDARD to an appropriate value.您需要将目标属性CXX_STANDARD设置为适当的值。

set_target_properties(project_options PROPERTIES CXX_STANDARD 17)

See documentation and here for further details.有关更多详细信息,请参阅 文档此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM