Skip to content

Commit

Permalink
[feat][cmake] Support c++20. default c++17.
Browse files Browse the repository at this point in the history
  • Loading branch information
Haijun Yu committed Feb 28, 2024
1 parent f2a9bea commit 2400c9f
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2400c9f

Please sign in to comment.