Build zlib using modern CMake and override the FindZLIB
module
Option | Default | Description |
---|---|---|
ZLIB_INSTALL |
OFF |
Install zlib and CMake targets |
ZLIB_TEST |
OFF |
Enable testing and build tests |
ZLIB_VERBOSE |
OFF |
Print result variables of FindZLIB module |
CPM_SOURCE_CACHE
- Set to
/path/to/cache
to reuse downloaded source code
- Set to
cmake --list-presets all # List all CMake presets
cmake --preset windows # Configure
cmake --build --preset windows # Build
ctest --preset windows # Test
cmake --build --preset windows -t install # Install
include(FetchContent)
# Set options before FetchContent_MakeAvailable()
set(ZLIB_TEST ON)
FetchContent_Declare(
zlib-cmake
URL https://github.com/jimmy-park/zlib-cmake/archive/main.tar.gz
)
# This line must be preceded before find_package(ZLIB)
FetchContent_MakeAvailable(zlib-cmake)
# If you're using CPM.cmake
# CPMAddPackage(
# NAME zlib-cmake
# URL https://github.com/jimmy-park/zlib-cmake/archive/main.tar.gz
# OPTIONS "ZLIB_TEST ON"
# )
# Use same target as FindZLIB module
add_executable(main main.cpp)
target_link_libraries(main PRIVATE ZLIB::ZLIB)