Skip to content

Commit 45c8e65

Browse files
Merge pull request #194 from cjee21/cmake
CMake: Version compatibility fixes 2
2 parents e6c8c98 + 22b7f45 commit 45c8e65

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Project/CMake/Modules/EnableLatestCXX.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ if(NOT "${CMAKE_VERSION}" VERSION_LESS "3.8")
1515
# Select highest available from list of supported
1616
set(_known_standards 26 23 20 17 14 11)
1717
foreach(std ${_known_standards})
18-
if("cxx_std_${std}" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
18+
list(FIND CMAKE_CXX_COMPILE_FEATURES "cxx_std_${std}" _index)
19+
if(NOT _index EQUAL -1)
1920
target_compile_features(${target} PRIVATE cxx_std_${std})
2021
message(STATUS "'${target}' is using latest available C++ standard: C++${std}")
2122
return()
@@ -24,6 +25,13 @@ if(NOT "${CMAKE_VERSION}" VERSION_LESS "3.8")
2425

2526
# Unsupported C++ version
2627
message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} does not support C++11 or newer.")
28+
else()
29+
set_target_properties(${target} PROPERTIES
30+
CXX_STANDARD 11
31+
CXX_STANDARD_REQUIRED YES
32+
CXX_EXTENSIONS NO
33+
)
34+
message(STATUS "${target}: Use CMake > 3.8 to automatically use the latest available C++ standard.")
2735
endif()
2836

2937
endfunction()

0 commit comments

Comments
 (0)