Skip to content

Commit

Permalink
CMake now uses C++17 if supported by the compiler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zeux committed Oct 30, 2024
1 parent ae163d5 commit 0f22f71
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<NOT:$<BOOL:${PUGIXML_STATIC_CRT}>>:DLL>)
endif()

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

if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
elseif (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()

Expand Down

0 comments on commit 0f22f71

Please sign in to comment.