如何在CMake中启用C ++ 17

编程入门 行业动态 更新时间:2024-10-20 05:37:02
本文介绍了如何在CMake中启用C ++ 17的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用VS 15.3,它支持集成的CMake 3.8.在不为每个特定的编译器编写标志的情况下,如何定位C ++ 17?我当前的全局设置无效:

I'm using VS 15.3, which supports integrated CMake 3.8. How can I target C++17 without writing flags for each specific compilers? My current global settings don't work:

# cmake/cmake/help/latest/prop_tgt/CXX_STANDARD.html set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # expected behaviour #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++lastest")

我希望CMake在生成VS解决方案文件时添加"/std:c ++ lastest"或等效名称,但未找到c ++ 17标志,导致编译器错误:

I expected CMake to add "/std:c++lastest" or equivalents when generating VS solution files, but no c++17 flags was found, resulted in compiler error:

C1189 #error: class template optional is only available with C++17.

推荐答案

您的方法是正确的,但不适用于3.10之前版本的CMake上的MSVC.

Your approach is the correct one, but it will not work for MSVC on versions of CMake prior to 3.10.

从 CMake 3.9 文档:

对于没有标准级别概念的编译器(例如MSVC),这无效.

For compilers that have no notion of a standard level, such as MSVC, this has no effect.

简而言之,尚未对CMake进行更新以适应添加到VC ++ 2017的标准标志.

In short, CMake haven't been updated to accommodate for the standard flags added to VC++ 2017.

您必须检测是否使用了VC ++ 2017(或更高版本),现在自己添加相应的标志.

You have to detect if VC++ 2017 (or later) is used and add the corresponding flags yourself for now.

在CMake 3.10(及更高版本)中,此问题已在VC ++的较新版本中得到修复.请参见 3.10文档.

In CMake 3.10 (and later) this have been fixed for newer version of VC++. See the 3.10 documentation.

更多推荐

如何在CMake中启用C ++ 17

本文发布于:2023-11-29 20:29:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647545.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   CMake

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!