From 50cdf2a5199e18014d0e1e5b6643c191210c210b Mon Sep 17 00:00:00 2001 From: Vishwa Shah Date: Thu, 22 Aug 2024 19:15:12 -0700 Subject: [PATCH] chore: c++ 17 compatibility (#430) * feat: c++ 17 compatibility * Apply suggestions from code review Co-authored-by: kyle-cochran --------- Co-authored-by: kyle-cochran --- CMakeLists.txt | 40 +++++++++++++++++++++++++++++++++-- docker/development/Dockerfile | 14 ++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 63dc41227..08c57002c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ OPTION (BUILD_DOCUMENTATION "Build documentation" OFF) OPTION (BUILD_WITH_DEBUG_SYMBOLS "Build with debug symbols" ON) OPTION (BUILD_BENCHMARK "Build benchmark" ON) OPTION (BUILD_SCRIPT "Build script" OFF) +OPTION (BUILD_WITH_CXX_17 "Build with C++ 17 support." OFF) ## Setup @@ -129,9 +130,44 @@ IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") ENDIF () -### C++ 20 support +### C++ 17/20 support + +IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + + IF (BUILD_WITH_CXX_17) + + SET (CMAKE_CXX_STANDARD 17) + + MESSAGE (STATUS "C++17 support enabled") + + IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0) + + MESSAGE (FATAL_ERROR "GCC version must be at least 7.0 to build with C++17") + + ENDIF () + + ELSE () + + MESSAGE (STATUS "C++20 support enabled") + + SET (CMAKE_CXX_STANDARD 20) + + IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0) + + MESSAGE (FATAL_ERROR "GCC version must be at least 13.0 to build with C++20") + + ENDIF () + + ENDIF () + + SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Wno-deprecated") + +ELSE () + + SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow") + +ENDIF () -SET (CMAKE_CXX_STANDARD 20) SET (CMAKE_CXX_STANDARD_REQUIRED ON) SET (CMAKE_CXX_EXTENSIONS OFF) diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile index 97872b55a..39b725386 100644 --- a/docker/development/Dockerfile +++ b/docker/development/Dockerfile @@ -16,6 +16,20 @@ RUN apt-get update \ && apt-get install -y unzip jq git-lfs locales \ && rm -rf /var/lib/apt/lists/* +## fmt + +ARG FMT_VERSION="5.2.0" + +RUN cd /tmp \ + && git clone --branch ${FMT_VERSION} --depth 1 https://github.com/fmtlib/fmt.git \ + && cd fmt \ + && mkdir build \ + && cd build \ + && cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE .. \ + && make --silent -j $(nproc) \ + && make install \ + && rm -rf /tmp/fmt + ## ordered-map ARG ORDERED_MAP_VERSION="0.6.0"