From: Vladislav Shchapov Date: Fri, 9 Jan 2026 19:47:20 +0000 (+0500) Subject: Replace deprecated FetchContent_Populate with FetchContent_MakeAvailable X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f8c8f2553e77ec71249923ca4932814a892cf33;p=thirdparty%2Fzlib-ng.git Replace deprecated FetchContent_Populate with FetchContent_MakeAvailable Signed-off-by: Vladislav Shchapov --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a5cb2db3..7ad76f580 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,6 @@ cmake_minimum_required(VERSION 3.14...4.2.1) message(STATUS "Using CMake version ${CMAKE_VERSION}") -if(POLICY CMP0169) - cmake_policy(SET CMP0169 OLD) # CMake 3.30: call FetchContent_Populate() with just the name of a dependency -endif() - # If not specified on the command line, enable C11 as the default # Configuration items that affect the global compiler environment standards # should be issued before the "project" command. diff --git a/cmake/fallback-macros.cmake b/cmake/fallback-macros.cmake index e8af0d4fe..d2375cdcc 100644 --- a/cmake/fallback-macros.cmake +++ b/cmake/fallback-macros.cmake @@ -1,4 +1,29 @@ # fallback-macros.cmake -- CMake fallback macros -# Copyright (C) 2022 Nathan Moinvaziri +# Copyright (C) 2026 Vladislav Shchapov # Licensed under the Zlib license, see LICENSE.md for details +# Workaround for FetchContent EXCLUDE_FROM_ALL implementation for CMake before 3.28. +# The EXCLUDE_FROM_ALL argument for FetchContent_Declare added in version 3.28. +# Before CMake 3.28, FetchContent_MakeAvailable would add dependencies to the ALL target. +macro(ZNG_FetchContent_MakeAvailable) + if(CMAKE_VERSION VERSION_LESS 3.28) + foreach(__zng_contentName IN ITEMS ${ARGV}) + string(TOLOWER ${__zng_contentName} __zng_contentNameLower) + FetchContent_GetProperties(${__zng_contentName}) + if(NOT ${__zng_contentNameLower}_POPULATED) + FetchContent_Populate(${__zng_contentName}) + add_subdirectory(${${__zng_contentNameLower}_SOURCE_DIR} ${${__zng_contentNameLower}_BINARY_DIR} EXCLUDE_FROM_ALL) + endif() + endforeach() + unset(__zng_contentName) + unset(__zng_contentNameLower) + else() + FetchContent_MakeAvailable(${ARGV}) + endif() +endmacro() + +if(CMAKE_VERSION VERSION_LESS 3.28) + set(ZNG_FetchContent_Declare_EXCLUDE_FROM_ALL) +else() + set(ZNG_FetchContent_Declare_EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL) +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eacea5ead..9a2342a37 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -134,13 +134,10 @@ if(WITH_GTEST) message(STATUS "Git checking out GoogleTest ${GTEST_TAG}") FetchContent_Declare(googletest GIT_REPOSITORY ${GTEST_REPOSITORY} - GIT_TAG ${GTEST_TAG}) + GIT_TAG ${GTEST_TAG} + ${ZNG_FetchContent_Declare_EXCLUDE_FROM_ALL}) - FetchContent_GetProperties(googletest) - if(NOT googletest_POPULATED) - FetchContent_Populate(googletest) - add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) - endif() + ZNG_FetchContent_MakeAvailable(googletest) add_library(GTest::GTest ALIAS gtest) add_library(GTest::Main ALIAS gtest_main) endif() diff --git a/test/benchmarks/CMakeLists.txt b/test/benchmarks/CMakeLists.txt index 832b30615..62585da78 100644 --- a/test/benchmarks/CMakeLists.txt +++ b/test/benchmarks/CMakeLists.txt @@ -28,13 +28,10 @@ if(NOT benchmark_FOUND) FetchContent_Declare(benchmark GIT_REPOSITORY ${GBENCHMARK_REPOSITORY} - GIT_TAG ${GBENCHMARK_TAG}) + GIT_TAG ${GBENCHMARK_TAG} + ${ZNG_FetchContent_Declare_EXCLUDE_FROM_ALL}) - FetchContent_GetProperties(benchmark) - if(NOT benchmark_POPULATED) - FetchContent_Populate(benchmark) - add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} EXCLUDE_FROM_ALL) - endif() + ZNG_FetchContent_MakeAvailable(benchmark) endif() add_executable(benchmark_zlib @@ -74,14 +71,11 @@ if(WITH_BENCHMARK_APPS) if(NOT PNG_FOUND) FetchContent_Declare(PNG - GIT_REPOSITORY https://github.com/glennrp/libpng.git) - - FetchContent_GetProperties(PNG) - if(NOT PNG_POPULATED) - FetchContent_Populate(PNG) - set(PNG_INCLUDE_DIR ${png_SOURCE_DIR}) - add_subdirectory(${png_SOURCE_DIR} ${png_BINARY_DIR}) - endif() + GIT_REPOSITORY https://github.com/glennrp/libpng.git + ${ZNG_FetchContent_Declare_EXCLUDE_FROM_ALL}) + + ZNG_FetchContent_MakeAvailable(PNG) + set(PNG_INCLUDE_DIR ${png_SOURCE_DIR}) endif() set(BENCH_APP_SRCS diff --git a/test/pigz/CMakeLists.txt b/test/pigz/CMakeLists.txt index bd4395acd..42f1f43d4 100644 --- a/test/pigz/CMakeLists.txt +++ b/test/pigz/CMakeLists.txt @@ -65,10 +65,7 @@ FetchContent_Declare(pigz GIT_REPOSITORY https://github.com/madler/pigz.git GIT_TAG ${PIGZ_TAG}) -FetchContent_GetProperties(pigz) -if(NOT pigz_POPULATED) - FetchContent_Populate(pigz) -endif() +FetchContent_MakeAvailable(pigz) set(PIGZ_SRCS ${pigz_SOURCE_DIR}/pigz.c