From 98204b17a6b431ba660a6f1d9f21faf65a390d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kalle=20Kiet=C3=A4v=C3=A4inen?= <1026741+kietavainen@users.noreply.github.com> Date: Sun, 17 Nov 2024 22:18:28 +0200 Subject: [PATCH] Set CMake C++ standard (#3688) Instead of setting `-std` compiler flag directly, set the `CMAKE_CXX_STANDARD` variable. This lets CMake know the required C++ standard and evaluate the final compiler flag correctly, taking into account compile features set by `target_compile_features()`. This change preserves the existing behavior, where compiler extensions are disabled for other targets than Cygwin. --- cmake/CXXSniffer.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/CXXSniffer.cmake b/cmake/CXXSniffer.cmake index 07c06cdae..ef1ec6511 100644 --- a/cmake/CXXSniffer.cmake +++ b/cmake/CXXSniffer.cmake @@ -6,7 +6,8 @@ include (CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++17" _HAS_CXX17) if (_HAS_CXX17) - set (_CXX14_FLAGS "-std=c++17") + set (CMAKE_CXX_STANDARD 17) + set (CMAKE_CXX_EXTENSIONS OFF) else (_HAS_CXX17) message (FATAL_ERROR "C++17 support missing. Try upgrading your C++ compiler. If you have a good reason for using an outdated compiler, please let us know at support@gothenburgbitfactory.org.") endif (_HAS_CXX17) @@ -32,7 +33,7 @@ elseif (${CMAKE_SYSTEM_NAME} STREQUAL "GNU") set (GNUHURD true) elseif (${CMAKE_SYSTEM_NAME} STREQUAL "CYGWIN") set (CYGWIN true) - set (_CXX14_FLAGS "-std=gnu++17") + set (CMAKE_CXX_EXTENSIONS ON) else (${CMAKE_SYSTEM_NAME} MATCHES "Linux") set (UNKNOWN true) endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")