How to enable C++17 in CMake

前端 未结 6 1656
旧时难觅i
旧时难觅i 2020-12-05 22:45

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:

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 22:54

    You can also use target_compile_options to set /std:c++latest flag for Visual Studio 2019

    if (MSVC_VERSION GREATER_EQUAL "1900")
        include(CheckCXXCompilerFlag)
        CHECK_CXX_COMPILER_FLAG("/std:c++latest" _cpp_latest_flag_supported)
        if (_cpp_latest_flag_supported)
            target_compile_options(${TARGET_NAME} PRIVATE "/std:c++latest")
        endif()
    endif()
    

    Replace ${TARGET_NAME} with the actual target name.

提交回复
热议问题