From d5043fc31972c722b3c1046a2c42196d13e6f14f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 7 Apr 2020 07:28:43 -0400 Subject: [PATCH] CMakeLists: Specify /std:c++latest on MSVC Makes use of the latest standards on MSVC, allowing potential compilation issues to be diagnosed as soon as possible --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a25102e2f..ba71b695e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,8 +36,15 @@ endif() project(urde VERSION 0.1.0) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +# MSVC has a "latest" flag, which always uses the newest standard +# when available. GCC and Clang posess no such flag, and must be +# manually enforced. CMake, curiously, also doesn't have a "latest" +# standard flag either. +if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) +endif() + set(BUILD_SHARED_LIBS OFF CACHE BOOL "Force shared libs off" FORCE) set(BUILD_STATIC_LIBS ON CACHE BOOL "Force static libs on" FORCE) @@ -88,6 +95,7 @@ if(MSVC) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") add_compile_options( + /std:c++latest # Use latest C++ standard. /permissive- # Enforce various standards compliance features. /Zc:externConstexpr # Allow extern constexpr variables according to the standard. /Zc:throwingNew # Assume new throws, allowing for better code generation.