From af1a5e9300b7b2e8487251f850d6a0fca28b8b67 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 3 Jan 2025 00:25:45 +0100 Subject: [PATCH] Build: Update to C++17 version The immediate driver for this change is related when fetching GTest. Currently we are stuck with GTest-1.12.1 because is the latest version supporting C++11. Later versions require C++14. However, GTest-1.12.1 has a CMakeLists.txt with ``cmake_minimum_required(VERSION 3.5)`` which causes the following warning with modern CMake versions: ``` CMake Deprecation Warning at build/_deps/googletest-src/CMakeLists.txt:4 (cmake_minimum_required): Compatibility with CMake < 3.10 will be removed from a future version of CMake. ``` Updating to >= C++14 allows us to use GTest-1.15.2 which has a ``cmake_minimum_required(VERSION 3.13)`` --- .github/workflows/windows.yml | 5 +++-- CMakeLists.txt | 4 ++-- docs/source/install.rst | 4 ++-- test/unit/CMakeLists.txt | 4 +++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 59be3bdd84..902fed8c33 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -71,12 +71,13 @@ jobs: cd %PROJ_BUILD% set PROJ_DIR=%GITHUB_WORKSPACE%\proj_dir :: Not directly linked to BUILD_SHARED_LIBS, but a way to test different C++ standard versions - if "${{ env.BUILD_SHARED_LIBS }}"=="ON" (set EXTRA_CXX_FLAGS="/std:c++20") + if "${{ env.BUILD_SHARED_LIBS }}"=="ON" (set CMAKE_CXX_STANDARD="-DCMAKE_CXX_STANDARD=20") if "${{ env.BUILD_TYPE }}"=="Release" (set CMAKE_UNITY_BUILD_OPT="-DCMAKE_UNITY_BUILD=ON") cmake -D CMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}" ^ -D BUILD_SHARED_LIBS="${{ env.BUILD_SHARED_LIBS }}" ^ -D CMAKE_C_FLAGS="/WX" ^ - -D CMAKE_CXX_FLAGS="/WX %EXTRA_CXX_FLAGS%" ^ + -D CMAKE_CXX_FLAGS="/WX" ^ + %CMAKE_CXX_STANDARD% ^ -D CMAKE_TOOLCHAIN_FILE=c:/vcpkg/scripts/buildsystems/vcpkg.cmake ^ -D CMAKE_INSTALL_PREFIX="%PROJ_DIR%" ^ -D PROJ_DB_CACHE_DIR=%PROJ_DB_CACHE_DIR% ^ diff --git a/CMakeLists.txt b/CMakeLists.txt index b6cf51b3ee..62aebc9979 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,8 +21,8 @@ cmake_policy(SET CMP0054 NEW) # Set C++ version # Make CMAKE_CXX_STANDARD available as cache option overridable by user -set(CMAKE_CXX_STANDARD 11 - CACHE STRING "C++ standard version to use (default is 11)") +set(CMAKE_CXX_STANDARD 17 + CACHE STRING "C++ standard version to use (default is 17)") message(STATUS "Requiring C++${CMAKE_CXX_STANDARD}") set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/docs/source/install.rst b/docs/source/install.rst index 8c5a95a4b0..e280159fdc 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -146,7 +146,7 @@ Build requirements ++++++++++++++++++ - C99 compiler -- C++11 compiler +- C++17 compiler - CMake >= 3.16 - SQLite3 >= 3.11: headers and library for target architecture, and sqlite3 executable for build architecture - libtiff >= 4.0 (optional but recommended) @@ -160,7 +160,7 @@ Test requirements These are only required if testing is built (see :option:`BUILD_TESTING`, default ON) -- GoogleTest (GTest) >= 1.8.1; if not found and :option:`TESTING_USE_NETWORK` is ON, then version 1.12.1 is fetched from GitHub and locally installed +- GoogleTest (GTest) >= 1.8.1; if not found and :option:`TESTING_USE_NETWORK` is ON, then version 1.15.2 is fetched from GitHub and locally installed - Python >= 3.7 - `importlib_metadata `_ only needed for Python 3.7 - One of either `PyYAML `_ or `ruamel.yaml `_ diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 860927fefd..09d0c5ef16 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -60,10 +60,12 @@ elseif(HAS_NETWORK) cmake_policy(SET CMP0135 NEW) # for DOWNLOAD_EXTRACT_TIMESTAMP option endif() + set(GTEST_VERSION "1.15.2") + include(FetchContent) FetchContent_Declare( googletest - URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip + URL https://github.com/google/googletest/archive/refs/tags/v${GTEST_VERSION}.zip EXCLUDE_FROM_ALL # ignored before CMake 3.28 )