Files
cppcourse/deps/Findzlib.cmake
2026-10-04 22:48:25 +02:00

54 lines
1.6 KiB
CMake

# ==============================================================================
# Findzlib.cmake
# ==============================================================================
# This module fetches and builds the zlib compression library.
# https://github.com/madler/zlib
#
# Targets provided:
# ZLIB::ZLIBSTATIC - Static library target
#
# Variables set:
# zlib_FOUND - TRUE if zlib is available
# zlib_LIBRARIES - The library target (ZLIB::ZLIBSTATIC)
# zlib_INCLUDE_DIR - Include directories for zlib
# ==============================================================================
if (DEFINED _FINDZLIB_INCLUDED)
return()
endif()
set(_FINDZLIB_INCLUDED TRUE)
if (DEFINED zlib_FIND_VERSION AND NOT zlib_FIND_VERSION STREQUAL "")
set(ZLIB_TAG "v${zlib_FIND_VERSION}")
else()
set(ZLIB_TAG "v1.3.2")
endif()
message(STATUS "Fetching zlib @ ${ZLIB_TAG}")
include(FetchContent)
find_program(GIT_EXECUTABLE git)
if (NOT GIT_EXECUTABLE)
message(FATAL_ERROR "Fetch with zip not supported.")
endif()
FetchContent_Declare(
zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG ${ZLIB_TAG}
GIT_SHALLOW TRUE
EXCLUDE_FROM_ALL
)
set(ZLIB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(zlib)
# zlib's CMakeLists provides ZLIB::ZLIBSTATIC for the static build
set(zlib_FOUND TRUE)
set(zlib_LIBRARIES ZLIB::ZLIBSTATIC)
set(zlib_INCLUDE_DIR "${zlib_SOURCE_DIR};${zlib_BINARY_DIR}")
set(ZLIB_LICENSE_FILE "${zlib_SOURCE_DIR}/LICENSE" CACHE FILEPATH "Path to zlib license file")