Generate CMake package configuration files

* 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
This commit is contained in:
Mika Lindqvist 2024-01-23 07:42:29 +02:00 committed by Hans Kristian Rosbach
parent 8c8cca7638
commit e2c4179bdd
3 changed files with 42 additions and 0 deletions

View File

@ -42,6 +42,7 @@ include(CheckCSourceCompiles)
include(CheckCSourceRuns) include(CheckCSourceRuns)
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
include(CMakeDependentOption) include(CMakeDependentOption)
include(CMakePackageConfigHelpers)
include(FeatureSummary) include(FeatureSummary)
include(cmake/detect-arch.cmake) include(cmake/detect-arch.cmake)
@ -1225,6 +1226,27 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
install(EXPORT ${EXPORT_NAME} install(EXPORT ${EXPORT_NAME}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${EXPORT_NAME}"
NAMESPACE ${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() endif()
#============================================================================ #============================================================================

10
zlib-config.cmake.in Normal file
View File

@ -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
zlib-ng-config.cmake.in Normal file
View File

@ -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)