From 12ceb014850d2a7bbaf7f23cd4a1ab8f6571b17f Mon Sep 17 00:00:00 2001 From: Joel Johnson Date: Tue, 31 Dec 2019 16:07:22 -0700 Subject: [PATCH] Always use consistent CXX_STANDARD Since CMake has subdirectory variable scope, unilaterally set the CMAKE_CXX_STANDARD variable to use C++11. This covers cases with the library being included externally, both in cases of only C++98 being specified, as well as later versions being specified (since the CXX_STANDARD itself isn't a library dependency, only the PUBLIC target_compile_features on jsoncpp_lib). The previous direct check for C++98 is handled by requiring C++11 on this library; should the compiler being used not support C++11 then CMake will issue an error. --- CMakeLists.txt | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f3b601..e636eeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,24 +37,11 @@ foreach(pold "") # Currently Empty endif() endforeach() -# ==== Define language standard configurations requiring at least c++11 standard -if(CMAKE_CXX_STANDARD EQUAL "98") - message(FATAL_ERROR "CMAKE_CXX_STANDARD:STRING=98 is not supported.") -endif() - -##### -## Set the default target properties -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 11) # Supported values are ``11``, ``14``, and ``17``. -endif() -if(NOT CMAKE_CXX_STANDARD_REQUIRED) - set(CMAKE_CXX_STANDARD_REQUIRED ON) -endif() -if(NOT CMAKE_CXX_EXTENSIONS) - set(CMAKE_CXX_EXTENSIONS OFF) -endif() - -# ==== +# Build the library with C++11 standard support, independent from other including +# software which may use a different CXX_STANDARD or CMAKE_CXX_STANDARD. +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD_REQUIRED ON) # Ensure that CMAKE_BUILD_TYPE has a value specified for single configuration generators. if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES)