Skip to content

Commit

Permalink
Generate CMake package configuration files
Browse files Browse the repository at this point in the history
* For COMPAT mode, zlib-config.cmake and zlib-config-version.cmake
* For non-COMPAT mode, zlib-ng-config.cmake and zlib-ng-config-version.cmake
  • Loading branch information
mtl1979 authored and Dead2 committed Jan 30, 2024
1 parent 8c8cca7 commit e2c4179
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(CheckCCompilerFlag)
include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(FeatureSummary)

include(cmake/detect-arch.cmake)
Expand Down Expand Up @@ -1225,6 +1226,27 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
install(EXPORT ${EXPORT_NAME}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}"
NAMESPACE ${EXPORT_NAME}::)
# Use GNU-style variable names
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
if (ZLIB_COMPAT)
set(PACKAGE_CONFIGNAME zlib)
set(PACKAGE_VERSION ${ZLIB_HEADER_VERSION})
else()
set(PACKAGE_CONFIGNAME zlib-ng)
set(PACKAGE_VERSION ${ZLIBNG_HEADER_VERSION})
endif()
configure_package_config_file(${PACKAGE_CONFIGNAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIGNAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}
PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIGNAME}-config-version.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIGNAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIGNAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME})
endif()

#============================================================================
Expand Down
10 changes: 10 additions & 0 deletions zlib-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(ZLIB_VERSION @ZLIB_HEADER_VERSION@)

@PACKAGE_INIT@

set_and_check(ZLIB_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(ZLIB_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@")

include("${CMAKE_CURRENT_LIST_DIR}/ZLIB.cmake")

check_required_components(ZLIB)
10 changes: 10 additions & 0 deletions zlib-ng-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(zlib-ng_VERSION @ZLIBNG_HEADER_VERSION@)

@PACKAGE_INIT@

set_and_check(zlib-ng_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(zlib-ng_LIB_DIR "@PACKAGE_LIB_INSTALL_DIR@")

include("${CMAKE_CURRENT_LIST_DIR}/zlib-ng.cmake")

check_required_components(zlib-ng)

0 comments on commit e2c4179

Please sign in to comment.