From e781482af324c1464b0805a3f98862c8ab2e482b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jiri=20Dan=C4=9Bk?= Date: Sat, 22 Oct 2022 17:39:42 +0200 Subject: [PATCH] QPID-7148 Use more modern CMake install machinery for better QpidConfig.cmake Turns out, CMake is happy to generate a lot of the QpidConfig.cmake file for us, see * https://gitlab.kitware.com/cmake/cmake/-/issues/19560 * https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-packages * https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#exporting-targets * https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#example-generating-package-files * https://cmake.org/cmake/help/latest/guide/tutorial/Packaging%20Debug%20and%20Release.html This is analogous change to PROTON-2254 for Qpid Proton. --- src/CMakeLists.txt | 32 +++++++++++++++++++++++++------- src/QpidConfig.cmake.in | 12 ++++++++---- src/QpidConfigVersion.cmake.in | 30 ------------------------------ 3 files changed, 33 insertions(+), 41 deletions(-) delete mode 100644 src/QpidConfigVersion.cmake.in diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4c7a8ac61..b7200137d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -855,6 +855,7 @@ set_target_properties (qpidcommon PROPERTIES SOVERSION ${qpidcommon_version_major}) install (TARGETS qpidcommon + EXPORT QpidTargets RUNTIME DESTINATION ${QPID_INSTALL_BINDIR} COMPONENT ${QPID_COMPONENT_COMMON} LIBRARY DESTINATION ${QPID_INSTALL_LIBDIR} COMPONENT ${QPID_COMPONENT_COMMON} ARCHIVE DESTINATION ${QPID_INSTALL_LIBDIR} COMPONENT ${QPID_COMPONENT_COMMON}) @@ -880,6 +881,7 @@ set_target_properties (qpidtypes PROPERTIES SOVERSION ${qpidtypes_version_major}) install(TARGETS qpidtypes + EXPORT QpidTargets RUNTIME DESTINATION ${QPID_INSTALL_BINDIR} COMPONENT ${QPID_COMPONENT_COMMON} LIBRARY DESTINATION ${QPID_INSTALL_LIBDIR} COMPONENT ${QPID_COMPONENT_COMMON} ARCHIVE DESTINATION ${QPID_INSTALL_LIBDIR} COMPONENT ${QPID_COMPONENT_COMMON}) @@ -939,6 +941,7 @@ set_target_properties (qpidclient PROPERTIES SOVERSION ${qpidclient_version_major}) install (TARGETS qpidclient + EXPORT QpidTargets RUNTIME DESTINATION ${QPID_INSTALL_BINDIR} COMPONENT ${QPID_COMPONENT_CLIENT} LIBRARY DESTINATION ${QPID_INSTALL_LIBDIR} COMPONENT ${QPID_COMPONENT_CLIENT} ARCHIVE DESTINATION ${QPID_INSTALL_LIBDIR} COMPONENT ${QPID_COMPONENT_CLIENT}) @@ -1006,6 +1009,7 @@ set_target_properties (qpidmessaging PROPERTIES VERSION ${qpidmessaging_version} SOVERSION ${qpidmessaging_version_major}) install (TARGETS qpidmessaging + EXPORT QpidTargets RUNTIME DESTINATION ${QPID_INSTALL_BINDIR} COMPONENT ${QPID_COMPONENT_CLIENT} LIBRARY DESTINATION ${QPID_INSTALL_LIBDIR} COMPONENT ${QPID_COMPONENT_CLIENT} ARCHIVE DESTINATION ${QPID_INSTALL_LIBDIR} COMPONENT ${QPID_COMPONENT_CLIENT}) @@ -1311,11 +1315,25 @@ set(QPIDTYPESLIB ${CMAKE_SHARED_LIBRARY_PREFIX}qpidtypes${CMAKE_SHARED_LIBRARY_S set(QPIDTYPESLIBDEBUG ${CMAKE_SHARED_LIBRARY_PREFIX}qpidtypes${CMAKE_DEBUG_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}) endif () -configure_file(QpidConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/QpidConfig.cmake @ONLY) -configure_file(QpidConfigVersion.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/QpidConfigVersion.cmake @ONLY) +install(EXPORT QpidTargets + FILE QpidTargets.cmake + NAMESPACE Qpid:: + DESTINATION ${QPID_INSTALL_LIBDIR}/cmake/Qpid) + +include(CMakePackageConfigHelpers) +include(WriteBasicConfigVersionFile) + +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/QpidConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/QpidConfig.cmake + PATH_VARS includedir + INSTALL_DESTINATION ${QPID_INSTALL_LIBDIR}/cmake/Qpid) +write_basic_config_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/QpidConfigVersion.cmake + VERSION ${VERSION} + COMPATIBILITY AnyNewerVersion) install (FILES - ${CMAKE_CURRENT_BINARY_DIR}/QpidConfig.cmake - ${CMAKE_CURRENT_BINARY_DIR}/QpidConfigVersion.cmake - DESTINATION ${QPID_INSTALL_LIBDIR}/cmake/Qpid - COMPONENT ${QPID_COMPONENT_COMMON}) - + ${CMAKE_CURRENT_BINARY_DIR}/QpidConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/QpidConfigVersion.cmake + DESTINATION ${QPID_INSTALL_LIBDIR}/cmake/Qpid + COMPONENT ${QPID_COMPONENT_COMMON}) diff --git a/src/QpidConfig.cmake.in b/src/QpidConfig.cmake.in index f8ad07842..0970944e0 100644 --- a/src/QpidConfig.cmake.in +++ b/src/QpidConfig.cmake.in @@ -22,13 +22,16 @@ # Version: @VERSION@ # URL: http://qpid.apache.org/ -set (Qpid_VERSION @VERSION@) +@PACKAGE_INIT@ +include("${CMAKE_CURRENT_LIST_DIR}/QpidTargets.cmake") -set (Qpid_INCLUDE_DIRS @includedir@) -set (Qpid_LIBRARIES optimized @libdir@/@QPIDMSGLIB@ @libdir@/@QPIDTYPESLIB@ debug @libdir@/@QPIDMSGLIBDEBUG@ @libdir@/@QPIDTYPESLIBDEBUG@) +set(Qpid_VERSION @VERSION@) + +set_and_check (Qpid_INCLUDE_DIRS @PACKAGE_includedir@) +set (Qpid_LIBRARIES Qpid::qpidmessaging Qpid::qpidtypes) # Can't make this compatible with CMake 2.8.12 as Qpid::qpid really is an interface target -# (because it has multiple libraries). So only allow for later versions of CMake +# (because it has multiple libraries). So only allow for later versions of CMake if (NOT TARGET Qpid::qpid AND CMAKE_VERSION VERSION_GREATER "3.0") add_library(Qpid::qpid INTERFACE IMPORTED) target_link_libraries(Qpid::qpid INTERFACE ${Qpid_LIBRARIES}) @@ -36,3 +39,4 @@ if (NOT TARGET Qpid::qpid AND CMAKE_VERSION VERSION_GREATER "3.0") endif() set (Qpid_FOUND True) +check_required_components(Qpid) diff --git a/src/QpidConfigVersion.cmake.in b/src/QpidConfigVersion.cmake.in deleted file mode 100644 index d85924ab7..000000000 --- a/src/QpidConfigVersion.cmake.in +++ /dev/null @@ -1,30 +0,0 @@ -# This is a basic version file for the Config-mode of find_package(). -# It is used by write_basic_package_version_file() as input file for configure_file() -# to create a version-file which can be installed along a config.cmake file. -# -# The created file sets PACKAGE_VERSION_EXACT if the current version string and -# the requested version string are exactly the same and it sets -# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version. - -set(PACKAGE_VERSION "@VERSION@") - -if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) - set(PACKAGE_VERSION_COMPATIBLE FALSE) -else() - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") - set(PACKAGE_VERSION_EXACT TRUE) - endif() -endif() - -# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: -if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "") - return() -endif() - -# check that the installed version has the same 32/64bit-ness as the one which is currently searching: -if(NOT "${CMAKE_SIZEOF_VOID_P}" STREQUAL "@CMAKE_SIZEOF_VOID_P@") - math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8") - set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") - set(PACKAGE_VERSION_UNSUITABLE TRUE) -endif()