From 28801f108f73890edd8e7baffa3c5d592c33d43b Mon Sep 17 00:00:00 2001 From: AriDEV Date: Sun, 7 Jan 2024 16:35:24 +0100 Subject: [PATCH] Cmake: Set c++23 as default. --- cmake/compiler/gcc/settings.cmake | 29 ++++++++++++++++++----------- cmake/compiler/msvc/settings.cmake | 10 ++++++++-- cmake/options.cmake | 3 ++- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/cmake/compiler/gcc/settings.cmake b/cmake/compiler/gcc/settings.cmake index d93f5128a89..b1f536991dd 100644 --- a/cmake/compiler/gcc/settings.cmake +++ b/cmake/compiler/gcc/settings.cmake @@ -6,27 +6,34 @@ # Set build-directive (used in core to tell which buildtype we used) add_definitions(-D_BUILD_DIRECTIVE='"${CMAKE_BUILD_TYPE}"') -# Check C++20 compiler support +# Check C++23 compiler support include(CheckCXXCompilerFlag) -CHECK_CXX_COMPILER_FLAG("-std=c++20" COMPILER_SUPPORTS_CXX20) -if(COMPILER_SUPPORTS_CXX20) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a") #c++20 +CHECK_CXX_COMPILER_FLAG("-std=c++23" COMPILER_SUPPORTS_CXX20) +if(COMPILER_SUPPORTS_CXX23) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23") #c++23 else() - message(FATAL_ERROR "Error, SkyFire requires a compiler that supports C++20!") + message(FATAL_ERROR "Error, SkyFire requires a compiler that supports C++23!") endif() - if(WITH_CXX_20_STD) - if(NOT WITH_CXX_DRAFT_STD) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a") #c++20 + if(NOT WITH_CXX_DRAFT_STD AND NOT WITH_CXX_23_STD) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20") #c++20 message(STATUS "GCC: C++20 Standard Enabled.") else() message(FATAL_ERROR "GCC: Only 1 CXX Standard can be used!") endif() endif() +if(WITH_CXX_23_STD) + if(NOT WITH_CXX_DRAFT_STD AND NOT WITH_CXX_20_STD) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23") #c++23 + message(STATUS "GCC: C++23 Standard Enabled.") + else() + message(FATAL_ERROR "GCC: Only 1 CXX Standard can be used!") + endif() +endif() if(WITH_CXX_DRAFT_STD) - if(NOT WITH_CXX_20_STD) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2b") #c++23 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++2b") #c++23 + if(NOT WITH_CXX_23_STD AND NOT WITH CXX_20_STD) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2c") #c++26 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++2c") #c++26 message(STATUS "GCC: C++ Draft Standard Enabled.") endif() endif() diff --git a/cmake/compiler/msvc/settings.cmake b/cmake/compiler/msvc/settings.cmake index 35e49f50352..ca016b9bd53 100644 --- a/cmake/compiler/msvc/settings.cmake +++ b/cmake/compiler/msvc/settings.cmake @@ -61,9 +61,15 @@ if(NOT WITH_WARNINGS) message(STATUS "MSVC: Disabled generic compiletime warnings") endif() +if(WITH_CXX_23_STD) + if(NOT WITH_CXX_20_STD) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest") #c++latest is currently c++23 in msvc 2022 + message(STATUS "MSVC: C++23 Draft Standard Enabled.") + endif() +endif() if(WITH_CXX_20_STD) if(NOT WITH_CXX_DRAFT_STD) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20") #c++20 message(STATUS "MSVC: C++20 Standard Enabled.") else() message(FATAL_ERROR "MSVC: Only 1 CXX Standard can be used!") @@ -71,7 +77,7 @@ if(WITH_CXX_20_STD) endif() if(WITH_CXX_DRAFT_STD) if(NOT WITH_CXX_20_STD) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest") #c++23 message(STATUS "MSVC: C++ Draft Standard Enabled.") endif() endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index 47d8cbdc036..bb811afc83d 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -11,6 +11,7 @@ option(USE_COREPCH "Use precompiled headers when compiling servers" option(WITH_WARNINGS "Show all warnings during compile" 0) option(WITH_COREDEBUG "Include additional debug-code in core" 0) option(WITHOUT_GIT "Disable the GIT testing routines" 0) -option(WITH_CXX_20_STD "Use c++20 standard" 1) +option(WITH_CXX_20_STD "Use c++20 standard" 0) +option(WITH_CXX_23_STD "Use c++23 standard" 1) option(WITH_CXX_DRAFT_STD "Use c++ draft standard" 0)