diff --git a/Project/CMake/Modules/EnableLatestCXX.cmake b/Project/CMake/Modules/EnableLatestCXX.cmake index 0f7f0e6..49d6f50 100644 --- a/Project/CMake/Modules/EnableLatestCXX.cmake +++ b/Project/CMake/Modules/EnableLatestCXX.cmake @@ -15,7 +15,8 @@ if(NOT "${CMAKE_VERSION}" VERSION_LESS "3.8") # Select highest available from list of supported set(_known_standards 26 23 20 17 14 11) foreach(std ${_known_standards}) - if("cxx_std_${std}" IN_LIST CMAKE_CXX_COMPILE_FEATURES) + list(FIND CMAKE_CXX_COMPILE_FEATURES "cxx_std_${std}" _index) + if(NOT _index EQUAL -1) target_compile_features(${target} PRIVATE cxx_std_${std}) message(STATUS "'${target}' is using latest available C++ standard: C++${std}") return() @@ -24,6 +25,13 @@ if(NOT "${CMAKE_VERSION}" VERSION_LESS "3.8") # Unsupported C++ version message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} does not support C++11 or newer.") +else() + set_target_properties(${target} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO + ) + message(STATUS "${target}: Use CMake > 3.8 to automatically use the latest available C++ standard.") endif() endfunction()