From c22551b903d513e3094e60887861b68b52d4ed72 Mon Sep 17 00:00:00 2001 From: Taylor Braun-Jones Date: Thu, 9 Apr 2020 17:13:39 -0400 Subject: [PATCH] Generate a better CMake Package Config file --- build/cmake/CMakeLists.txt | 36 +++++++++++++++++++++++++++++++++ build/cmake/lib/CMakeLists.txt | 15 -------------- build/cmake/lib/config.cmake.in | 7 ------- build/cmake/zstdConfig.cmake | 1 + 4 files changed, 37 insertions(+), 22 deletions(-) delete mode 100644 build/cmake/lib/config.cmake.in create mode 100644 build/cmake/zstdConfig.cmake diff --git a/build/cmake/CMakeLists.txt b/build/cmake/CMakeLists.txt index be5ce1518..ac499133f 100644 --- a/build/cmake/CMakeLists.txt +++ b/build/cmake/CMakeLists.txt @@ -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} + ) diff --git a/build/cmake/lib/CMakeLists.txt b/build/cmake/lib/CMakeLists.txt index e92647bf1..86abf593d 100644 --- a/build/cmake/lib/CMakeLists.txt +++ b/build/cmake/lib/CMakeLists.txt @@ -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( diff --git a/build/cmake/lib/config.cmake.in b/build/cmake/lib/config.cmake.in deleted file mode 100644 index 3a22756fc..000000000 --- a/build/cmake/lib/config.cmake.in +++ /dev/null @@ -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() diff --git a/build/cmake/zstdConfig.cmake b/build/cmake/zstdConfig.cmake new file mode 100644 index 000000000..ebbfcc38f --- /dev/null +++ b/build/cmake/zstdConfig.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/zstdTargets.cmake") -- 2.47.2