diff --git a/CMakeLists.txt b/CMakeLists.txt index 939763bfa..ce432a085 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,12 +51,15 @@ option(BRPC_ENABLE_CPU_PROFILER "Enable brpc cpu profiler" OFF) option(XDPROCKS_PATH "Enable xdprocks raw engine") option(BUILD_PYTHON_SDK "Build python sdk" OFF) + message(STATUS CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}) 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 +107,33 @@ 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 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.") + 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 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: