diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ff57480a..f0bcb128c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,8 @@ message(STATUS THIRD_PARTY_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}) SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -g3 -ggdb") SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g3 -ggdb") +message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}") + # xdprocks if(XDPROCKS_PATH) message(STATUS "Enable xdprocks, path: ${XDPROCKS_PATH}") @@ -104,19 +106,44 @@ if(ENABLE_COVERAGE) endif() include(CheckCXXCompilerFlag) -check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17) -if(COMPILER_SUPPORTS_CXX17) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +if (CMAKE_CXX_STANDARD EQUAL 23) + check_cxx_compiler_flag("-std=c++23" COMPILER_SUPPORTS_CXX23) + if(COMPILER_SUPPORTS_CXX23) + set(CMAKE_CXX_STANDARD 23) + set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + else() + message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++23 support. Please use a different C++ compiler.") + endif() +elseif(CMAKE_CXX_STANDARD EQUAL 20) + check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20) + if(COMPILER_SUPPORTS_CXX20) + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + else() + message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++20 support. Please use a different C++ compiler.") + endif() else() - message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.") + message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD} change to c++17") + check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17) + if(COMPILER_SUPPORTS_CXX17) + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + else() + message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.") + endif() endif() if(THIRD_PARTY_BUILD_TYPE MATCHES "Debug") set(CMAKE_STATIC_LIBRARY_SUFFIX "d.a") endif() -set(CMAKE_CXX_STANDARD 17) +if (CMAKE_CXX_STANDARD EQUAL 23) + set(CMAKE_CXX_STANDARD 23) +elseif(CMAKE_CXX_STANDARD EQUAL 20) + set(CMAKE_CXX_STANDARD 20) +else() + set(CMAKE_CXX_STANDARD 17) +endif() # set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24: