CMake6-跨平台编译特性设置1-构建参数2:target_compile_features【向target添加编译器版本(例如:cxx_std_14、cxx_std_17)】

在这里插入图片描述

#402target_compile_features/CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(compile_features)
file(WRITE main.cpp [=[
int main()
{
    return 0;
}
]=]
)
add_executable(main main.cpp)
# c++ 17
#target_compile_features(main PRIVATE cxx_std_17)
# vs2022 有效 ubuntu 20.04 gcc无效
#target_compile_features(main PRIVATE cxx_std_23)

# 支持的特征数组
message("CMAKE_CXX_COMPILE_FEATURES =  ${CMAKE_CXX_COMPILE_FEATURES} ")
foreach(var IN LISTS CMAKE_CXX_COMPILE_FEATURES)
    message(${var})
endforeach()
#判断当前编译器是否支持此特性
message("--------------------------------------------")
set(f1 cxx_std_23)
if(f1 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
    message("${f1} OK!")
    target_compile_features(main PRIVATE ${f1})
else()
    message("${f1} FAILED!")
endif()



CMake中target_compile_features的使用

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值