]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Replace deprecated FetchContent_Populate with FetchContent_MakeAvailable
authorVladislav Shchapov <vladislav@shchapov.ru>
Fri, 9 Jan 2026 19:47:20 +0000 (00:47 +0500)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Sun, 11 Jan 2026 09:32:39 +0000 (10:32 +0100)
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
CMakeLists.txt
cmake/fallback-macros.cmake
test/CMakeLists.txt
test/benchmarks/CMakeLists.txt
test/pigz/CMakeLists.txt

index 4a5cb2db3a7b75ef8bf76ff43a35622ea2fb80e4..7ad76f580636cb7a2c8dbc36e9f5ad45772bd4af 100644 (file)
@@ -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.
index e8af0d4fe5cc8c811b55ce1ad42fbccae17412ad..d2375cdcc75a7bab0386f60e4bc0935db9c24639 100644 (file)
@@ -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()
index eacea5ead70df90675df06513b8faf770f3ea222..9a2342a37918b7fdd94794375d3b2e78877991e8 100644 (file)
@@ -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()
index 832b3061527d3c04213e9d77a825947ba8846b3f..62585da78d29168b5074e22d753308035d8bbde1 100644 (file)
@@ -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
index bd4395acd47f032107b63338fdd954e2cb0ca7c4..42f1f43d47b93e5d27e91ad53c9245c6b87370ab 100644 (file)
@@ -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