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.
# 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()
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()
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
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
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