<i id='m38vr'><tr id='m38vr'><dt id='m38vr'><q id='m38vr'><span id='m38vr'><b id='m38vr'><form id='m38vr'><ins id='m38vr'></ins><ul id='m38vr'></ul><sub id='m38vr'></sub></form><legend id='m38vr'></legend><bdo id='m38vr'><pre id='m38vr'><center id='m38vr'></center></pre></bdo></b><th id='m38vr'></th></span></q></dt></tr></i><div id='m38vr'><tfoot id='m38vr'></tfoot><dl id='m38vr'><fieldset id='m38vr'></fieldset></dl></div>

  • <legend id='m38vr'><style id='m38vr'><dir id='m38vr'><q id='m38vr'></q></dir></style></legend>
        <tfoot id='m38vr'></tfoot>
        • <bdo id='m38vr'></bdo><ul id='m38vr'></ul>

        <small id='m38vr'></small><noframes id='m38vr'>

        如何使用 CMake 在 VS2017 中启用/std:c++17

        How to enable /std:c++17 in VS2017 with CMake(如何使用 CMake 在 VS2017 中启用/std:c++17)

            <small id='u6zFV'></small><noframes id='u6zFV'>

            <legend id='u6zFV'><style id='u6zFV'><dir id='u6zFV'><q id='u6zFV'></q></dir></style></legend>

              <tfoot id='u6zFV'></tfoot>
                  <tbody id='u6zFV'></tbody>
                <i id='u6zFV'><tr id='u6zFV'><dt id='u6zFV'><q id='u6zFV'><span id='u6zFV'><b id='u6zFV'><form id='u6zFV'><ins id='u6zFV'></ins><ul id='u6zFV'></ul><sub id='u6zFV'></sub></form><legend id='u6zFV'></legend><bdo id='u6zFV'><pre id='u6zFV'><center id='u6zFV'></center></pre></bdo></b><th id='u6zFV'></th></span></q></dt></tr></i><div id='u6zFV'><tfoot id='u6zFV'></tfoot><dl id='u6zFV'><fieldset id='u6zFV'></fieldset></dl></div>

                  <bdo id='u6zFV'></bdo><ul id='u6zFV'></ul>
                • 本文介绍了如何使用 CMake 在 VS2017 中启用/std:c++17的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 CMake 将 /std:c++17 编译器标志添加到 VS2017.到目前为止,我正在使用现代"跨平台方式:

                  I'm trying to add the /std:c++17 compiler flag to VS2017 with CMake. I'm using the "modern" cross-platform way so far:

                  set(CMAKE_CXX_STANDARD 14)
                  set(CMAKE_CXX_STANDARD_REQUIRED ON)
                  set(CMAKE_CXX_EXTENSIONS OFF) # -std=c++11 instead of -std=gnu++11
                  set(MY_CXX_COMPILE_FEATURES cxx_generic_lambdas cxx_range_for cxx_strong_enums)
                  
                  add_library(mylib INTERFACE)
                  target_compile_features(mylib INTERFACE ${MY_CXX_COMPILE_FEATURES})
                  

                  这在 VS2017 中添加了 /std:c++14(这可能是默认值?).但是,我无法将其切换到 C++17(即添加 /std:c++17).如果我只是手动添加它,我会收到不太好的警告,因为两个标志都存在:

                  This adds /std:c++14 in VS2017 (which might be the default anyway?). However I'm having trouble switching this to C++17 (i.e. having it add /std:c++17). If I just add it manually, I get the not-so-nice warning because both flags are present:

                  1>cl : 命令行警告 D9025: 用 '/std:c++17' 覆盖 '/std:c++14'

                  我试过 set(CMAKE_CXX_STANDARD 17) 但它没有效果,事实上 CMake 文档提到 CMAKE_CXX_STANDARD 无论如何对 VS 没有影响.

                  I've tried set(CMAKE_CXX_STANDARD 17) but it has no effect, in fact the CMake documentation mentions that CMAKE_CXX_STANDARD has no effect on VS anyway.

                  至于向 target_compile_features 添加 C++17 特性,似乎还没有(即使在 CMake-3.9.0-rc5 中),即使有,我专门只使用 C++17 中的 std::optional,并且没有像 std::optional 这样的库功能的 target_compile_features 标志.

                  As for adding a C++17 feature to target_compile_features, it doesn't seem like there are any yet (even in CMake-3.9.0-rc5), and even if there were, I'm specifically only using std::optional from C++17, and there's no target_compile_features flags for library features like std::optional.

                  所以我的问题是,使用 CMake 执行此操作的最佳(或最不丑陋)方法是什么?在某种程度上,它也适用于 gcc 和 clang?我很高兴使用最新的 CMake 版本(3.8 或 3.9).我更喜欢它不错",而不是手动循环遍历 CXX_COMPILE_FLAGS 并删除字符串/std:c++14"或类似的一些hack.

                  So my question is, what's the best (or least ugly) way to do this with CMake? And in a way so it'll also work for gcc and clang? I'm happy to use a very recent CMake version (3.8 or 3.9). I prefer it to be "nice" and not manually looping through CXX_COMPILE_FLAGS and removing the string "/std:c++14" or some hack like that.

                  (编辑:它也可以是 VS/std:c++latest 开关 - 以可能的为准.两者都适用.)

                  (Edit: It can also be the VS/std:c++latest switch - whichever is possible. Both work for the purpose.)

                  推荐答案

                  将我的评论转化为答案

                  1. CMake 团队正在为 VS2017 开发它(对于 2017 年 7 月,即将推出的 CMake 版本 3.10):

                  1. The CMake team is working on it for VS2017 (as for July 2017, for upcoming CMake version 3.10):

                  CMake:MSVC 标准版本切换

                  那些标志似乎是相当新的开关(与此问题的日期有关):

                  Those flags seem to be rather new switches (as related to the date of this question):

                  VS 2017 15.3 预览版现在支持/std:c++17

                  VS 2017 15.3 preview now supports /std:c++17

                  因此,对于 Visual Studio,您必须手动"替换或附加编译器开关,直到 CMake 正式支持它为止.

                  So for Visual Studio you have to "manually" replace or append the compiler switches until CMake officially does support it.

                  这是我为 std:c++latest 测试的代码片段(已经支持,例如在我的 CMake 3.8.0 版本中):

                  Here is a code snippet that I've tested for std:c++latest (which is already supported e.g. in my CMake 3.8.0 version):

                  if (MSVC_VERSION GREATER_EQUAL "1900")
                      include(CheckCXXCompilerFlag)
                      CHECK_CXX_COMPILER_FLAG("/std:c++latest" _cpp_latest_flag_supported)
                      if (_cpp_latest_flag_supported)
                          add_compile_options("/std:c++latest")
                      endif()
                  endif()
                  

                • 对于 CLang 和 GNU 的支持已于 2017 年初合并到主要源代码分支中,并且是 CMake 3.8 及更高版本的一部分:

                • For CLang and GNU the support was merged into the main source code branch begin of 2017 and is part of CMake version 3.8 and above:

                  CMake:特性:添加对 C++ 17 语言标准的支持

                  这篇关于如何使用 CMake 在 VS2017 中启用/std:c++17的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!
                • 相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                      • <bdo id='qLDkt'></bdo><ul id='qLDkt'></ul>

                        <legend id='qLDkt'><style id='qLDkt'><dir id='qLDkt'><q id='qLDkt'></q></dir></style></legend>

                        <small id='qLDkt'></small><noframes id='qLDkt'>

                        <i id='qLDkt'><tr id='qLDkt'><dt id='qLDkt'><q id='qLDkt'><span id='qLDkt'><b id='qLDkt'><form id='qLDkt'><ins id='qLDkt'></ins><ul id='qLDkt'></ul><sub id='qLDkt'></sub></form><legend id='qLDkt'></legend><bdo id='qLDkt'><pre id='qLDkt'><center id='qLDkt'></center></pre></bdo></b><th id='qLDkt'></th></span></q></dt></tr></i><div id='qLDkt'><tfoot id='qLDkt'></tfoot><dl id='qLDkt'><fieldset id='qLDkt'></fieldset></dl></div>

                              <tbody id='qLDkt'></tbody>
                          • <tfoot id='qLDkt'></tfoot>