Generate a better CMake Package Config file

This commit is contained in:
Taylor Braun-Jones 2020-04-09 17:13:39 -04:00
parent 5fcbc484c8
commit c22551b903
4 changed files with 37 additions and 22 deletions

View File

@ -158,3 +158,39 @@ add_custom_target(clean-all
COMMAND ${CMAKE_BUILD_TOOL} clean
COMMAND rm -rf ${CMAKE_BINARY_DIR}/
)
#-----------------------------------------------------------------------------
# Generate Package Config files
#
# This section is based on the boiler plate code from:
# https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-packages
#-----------------------------------------------------------------------------
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfigVersion.cmake"
VERSION ${zstd_VERSION}
COMPATIBILITY SameMajorVersion
)
# A Package Config file that works from the build directory
export(EXPORT zstdExports
FILE "${CMAKE_CURRENT_BINARY_DIR}/zstdTargets.cmake"
NAMESPACE zstd::
)
configure_file(zstdConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
COPYONLY
)
# A Package Config file that works from the installation directory
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/zstd)
install(EXPORT zstdExports
FILE zstdTargets.cmake
NAMESPACE zstd::
DESTINATION ${ConfigPackageLocation}
)
install(FILES
zstdConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
)

View File

@ -169,21 +169,6 @@ if (ZSTD_BUILD_STATIC)
)
endif ()
# export targets + find config
configure_file(
"config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
@ONLY
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zstd"
)
install(EXPORT zstdExports
NAMESPACE zstd::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zstd"
)
# uninstall target
if (NOT TARGET uninstall)
configure_file(

View File

@ -1,7 +0,0 @@
include(FindPackageHandleStandardArgs)
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE})
find_package_handle_standard_args(zstd CONFIG_MODE)
if(NOT TARGET zstd::libzstd_shared)
include("${CMAKE_CURRENT_LIST_DIR}/zstdExports.cmake")
endif()

View File

@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/zstdTargets.cmake")