Skip to content

Commit 0f22f71

Browse files
committed
CMake now uses C++17 if supported by the compiler
We only set this when C++ version or requirement flag is not overridden externally to be able to rely on CMake automatically downgrading the standard version when the compiler doesn't support it. CXX_STANDARD 17 also requires CMake 3.8 or later; on earlier versions we use the old behavior and set C++11.
1 parent ae163d5 commit 0f22f71

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
6464
MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<NOT:$<BOOL:${PUGIXML_STATIC_CRT}>>:DLL>)
6565
endif()
6666

67-
if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
68-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
69-
endif()
67+
# Set the default C++ standard to C++17 if not set; CMake will automatically downgrade this if the compiler does not support it
68+
# When CMAKE_CXX_STANDARD_REQUIRED is set, we fall back to C++11 to avoid breaking older compilers
69+
if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED AND NOT DEFINED CMAKE_CXX_STANDARD AND NOT CMAKE_VERSION VERSION_LESS 3.8)
7070

71-
if (NOT DEFINED CMAKE_CXX_STANDARD)
71+
set(CMAKE_CXX_STANDARD 17)
72+
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
73+
elseif (NOT DEFINED CMAKE_CXX_STANDARD)
7274
set(CMAKE_CXX_STANDARD 11)
7375
endif()
7476

0 commit comments

Comments
 (0)