From bb5449c8fcf05d917620b64aa6a0e1a36dd4d440 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 30 Sep 2026 18:11:01 +0200 Subject: [PATCH] Silence the CMP0169 deprecation in cmake_fetch_content, fix stale guards tests/cmake_fetch_content/project calls the single-argument FetchContent_Populate(json) after FetchContent_Declare(), which CMake 3.30 deprecated as CMP0169. Since the project declares cmake_minimum_required(VERSION 3.11...3.14), the policy stays unset, so every configure with a current CMake prints the deprecation warning. The test is kept on purpose: it is the only coverage of the FetchContent_Populate + add_subdirectory pattern for CMake 3.11-3.13 users, which the docs still describe as supported. Explicitly set CMP0169 to OLD, with a comment explaining why. Also fix two stale version guards: - tests/cmake_fetch_content/CMakeLists.txt guarded the test with VERSION_GREATER "3.11.0", which is dead now that tests/CMakeLists.txt requires CMake 3.13. - tests/cmake_fetch_content2/CMakeLists.txt guarded with VERSION_GREATER "3.14.0", which skips exactly 3.14.0, the first version with FetchContent_MakeAvailable. Change it to VERSION_GREATER_EQUAL "3.14". Verified locally: `ctest -R cmake_fetch_content` passes with CMake 4.1, and the CMP0169 deprecation warning that appeared before this change is gone. Closes #5714 item 5. Signed-off-by: Niels Lohmann --- tests/cmake_fetch_content/CMakeLists.txt | 30 +++++++++---------- .../project/CMakeLists.txt | 8 +++++ tests/cmake_fetch_content2/CMakeLists.txt | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/tests/cmake_fetch_content/CMakeLists.txt b/tests/cmake_fetch_content/CMakeLists.txt index 211a49cee..42fcb5816 100644 --- a/tests/cmake_fetch_content/CMakeLists.txt +++ b/tests/cmake_fetch_content/CMakeLists.txt @@ -1,21 +1,19 @@ -if (${CMAKE_VERSION} VERSION_GREATER "3.11.0") - add_test(NAME cmake_fetch_content_configure - COMMAND ${CMAKE_COMMAND} +add_test(NAME cmake_fetch_content_configure + COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -Dnlohmann_json_source=${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/project - ) - add_test(NAME cmake_fetch_content_build - COMMAND ${CMAKE_COMMAND} --build . - ) - set_tests_properties(cmake_fetch_content_configure PROPERTIES - FIXTURES_SETUP cmake_fetch_content - LABELS "git_required;not_reproducible" - ) - set_tests_properties(cmake_fetch_content_build PROPERTIES - FIXTURES_REQUIRED cmake_fetch_content - LABELS "git_required;not_reproducible" - ) -endif() +) +add_test(NAME cmake_fetch_content_build + COMMAND ${CMAKE_COMMAND} --build . +) +set_tests_properties(cmake_fetch_content_configure PROPERTIES + FIXTURES_SETUP cmake_fetch_content + LABELS "git_required;not_reproducible" +) +set_tests_properties(cmake_fetch_content_build PROPERTIES + FIXTURES_REQUIRED cmake_fetch_content + LABELS "git_required;not_reproducible" +) diff --git a/tests/cmake_fetch_content/project/CMakeLists.txt b/tests/cmake_fetch_content/project/CMakeLists.txt index 9f7488157..ad8a05045 100644 --- a/tests/cmake_fetch_content/project/CMakeLists.txt +++ b/tests/cmake_fetch_content/project/CMakeLists.txt @@ -4,6 +4,14 @@ project(DummyImport CXX) include(FetchContent) +# This test deliberately covers the pre-3.14 FetchContent_Populate pattern +# (see FetchContent_MakeAvailable in ../../cmake_fetch_content2/project for +# the 3.14+ alternative), which CMake 3.30 deprecated as CMP0169. Silence the +# deprecation warning on purpose instead of switching to the new pattern. +if(POLICY CMP0169) + cmake_policy(SET CMP0169 OLD) +endif() + get_filename_component(GIT_REPOSITORY_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. ABSOLUTE) FetchContent_Declare(json GIT_REPOSITORY ${GIT_REPOSITORY_DIRECTORY} GIT_TAG HEAD) diff --git a/tests/cmake_fetch_content2/CMakeLists.txt b/tests/cmake_fetch_content2/CMakeLists.txt index b35f93cfd..9b24fee01 100644 --- a/tests/cmake_fetch_content2/CMakeLists.txt +++ b/tests/cmake_fetch_content2/CMakeLists.txt @@ -1,4 +1,4 @@ -if (${CMAKE_VERSION} VERSION_GREATER "3.14.0") +if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14") add_test(NAME cmake_fetch_content2_configure COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"