From 92f44407c69355966d62b546fabb3b3fb4a89d7b Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 10 Apr 2020 18:59:16 -1000 Subject: [PATCH] Exclude CMake CXX standard from MSVC --- CMakeLists.txt | 29 +++++++++++++++++++---------- Editor/CMakeLists.txt | 23 +++++++++++++++-------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3341e53..db0c01d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) # because of c++17 project(amuse) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +if (NOT MSVC) + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD_REQUIRED ON) +endif() if(NOT MSVC) add_compile_options(-Wno-narrowing) @@ -98,20 +100,27 @@ endif() if (MSVC) target_compile_options(amuse PRIVATE # Enforce various standards compliant behavior. - /permissive- + $<$:/permissive-> # Enable standard volatile semantics. - /volatile:iso + $<$:/volatile:iso> # Reports the proper value for the __cplusplus preprocessor macro. - /Zc:__cplusplus + $<$:/Zc:__cplusplus> - # Allow constexpr variables to have explicit external linkage. - /Zc:externConstexpr - - # Assume that new throws exceptions, allowing better code generation. - /Zc:throwingNew + # Use latest C++ standard. + $<$:/std:c++latest> ) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # Flags for MSVC (not clang-cl) + target_compile_options(amuse PRIVATE + # Allow constexpr variables to have explicit external linkage. + $<$:/Zc:externConstexpr> + + # Assume that new throws exceptions, allowing better code generation. + $<$:/Zc:throwingNew> + ) + endif() else() target_compile_options(amuse PRIVATE -Wno-unknown-pragmas) endif() diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index 9d9b344..e13a8f1 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -84,20 +84,27 @@ target_compile_definitions(amuse-gui PRIVATE if (MSVC) target_compile_options(amuse-gui PRIVATE # Enforce various standards compliant behavior. - /permissive- + $<$:/permissive-> # Enable standard volatile semantics. - /volatile:iso + $<$:/volatile:iso> # Reports the proper value for the __cplusplus preprocessor macro. - /Zc:__cplusplus + $<$:/Zc:__cplusplus> - # Allow constexpr variables to have explicit external linkage. - /Zc:externConstexpr - - # Assume that new throws exceptions, allowing better code generation. - /Zc:throwingNew + # Use latest C++ standard. + $<$:/std:c++latest> ) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # Flags for MSVC (not clang-cl) + target_compile_options(amuse-gui PRIVATE + # Allow constexpr variables to have explicit external linkage. + $<$:/Zc:externConstexpr> + + # Assume that new throws exceptions, allowing better code generation. + $<$:/Zc:throwingNew> + ) + endif() endif() if(WIN32)