From 4568e079af0d6cbdf2e06c561a545d136e351738 Mon Sep 17 00:00:00 2001 From: marc-adaptive Date: Fri, 9 Aug 2024 13:28:36 -0400 Subject: [PATCH] [C] Add Cmake library aliases to better integrate FetchContent with find_package --- CMakeLists.txt | 58 ++++++++++--------- aeron-archive/src/main/cpp/CMakeLists.txt | 7 ++- aeron-client/src/main/c/CMakeLists.txt | 4 +- aeron-client/src/main/cpp/CMakeLists.txt | 4 +- .../src/main/cpp_wrapper/CMakeLists.txt | 7 ++- Config.cmake.in => aeron-config.cmake.in | 4 +- aeron-driver/src/main/c/CMakeLists.txt | 4 +- 7 files changed, 49 insertions(+), 39 deletions(-) rename Config.cmake.in => aeron-config.cmake.in (51%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d3687e86c..5f084ed624 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -356,44 +356,46 @@ if (AERON_BUILD_DOCUMENTATION AND DOXYGEN_FOUND) endif () endif () -########################################################## -# package target - -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") -set(CPACK_PACKAGE_VERSION_MAJOR "${aeron_VERSION_MAJOR}") -set(CPACK_PACKAGE_VERSION_MINOR "${aeron_VERSION_MINOR}") -set(CPACK_PACKAGE_VERSION_PATCH "${aeron_VERSION_PATCH}") - -set(CPACK_GENERATOR "TGZ;STGZ") -include(CPack) - ########################################################## # export targets + if (AERON_INSTALL_TARGETS) include(CMakePackageConfigHelpers) install( - EXPORT AeronTargets - FILE AeronTargets.cmake - NAMESPACE Aeron:: - DESTINATION lib/cmake/Aeron) + EXPORT aeron-targets + FILE aeron-targets.cmake + NAMESPACE aeron:: + DESTINATION lib/cmake/aeron) write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/AeronConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/aeron-config-version.cmake" VERSION "${AERON_VERSION_FROM_FILE}" - COMPATIBILITY ExactVersion) + COMPATIBILITY AnyNewerVersion) configure_package_config_file( - ${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in - "${CMAKE_CURRENT_BINARY_DIR}/AeronConfig.cmake" - INSTALL_DESTINATION lib/cmake/Aeron) + ${CMAKE_CURRENT_SOURCE_DIR}/aeron-config.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/aeron-config.cmake" + INSTALL_DESTINATION lib/cmake/aeron) install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/AeronConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/AeronConfigVersion.cmake" - DESTINATION lib/cmake/Aeron) - - export(EXPORT AeronTargets - FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/AeronTargets.cmake" - NAMESPACE Aeron::) -endif () \ No newline at end of file + "${CMAKE_CURRENT_BINARY_DIR}/aeron-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/aeron-config-version.cmake" + DESTINATION lib/cmake/aeron) + + export(EXPORT aeron-targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/aeron-targets.cmake" + NAMESPACE aeron::) +endif () + +########################################################## +# package target + +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_PACKAGE_VERSION_MAJOR "${aeron_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${aeron_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${aeron_VERSION_PATCH}") + +set(CPACK_GENERATOR "TGZ;STGZ") +include(CPack) + diff --git a/aeron-archive/src/main/cpp/CMakeLists.txt b/aeron-archive/src/main/cpp/CMakeLists.txt index 2e2a87c805..08d07fbfae 100644 --- a/aeron-archive/src/main/cpp/CMakeLists.txt +++ b/aeron-archive/src/main/cpp/CMakeLists.txt @@ -98,7 +98,9 @@ SET(HEADERS # static library add_library(aeron_archive_client STATIC ${SOURCE} ${HEADERS}) +add_library(aeron::aeron_archive_client ALIAS aeron_archive_client) add_library(aeron_archive_client_wrapper STATIC ${SOURCE} ${HEADERS}) +add_library(aeron::aeron_archive_client_wrapper ALIAS aeron_archive_client_wrapper) add_dependencies(aeron_archive_client codecs) add_dependencies(aeron_archive_client_wrapper codecs) @@ -126,11 +128,10 @@ target_link_libraries(aeron_archive_client_wrapper if (AERON_INSTALL_TARGETS) install( - TARGETS aeron_archive_client aeron_archive_client_wrapper - EXPORT AeronTargets + TARGETS aeron_archive_client + EXPORT aeron-targets RUNTIME DESTINATION lib LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(DIRECTORY ./ DESTINATION include FILES_MATCHING PATTERN "*.h") - install(DIRECTORY ${ARCHIVE_CODEC_TARGET_DIR}/ DESTINATION include FILES_MATCHING PATTERN "*.h") endif () diff --git a/aeron-client/src/main/c/CMakeLists.txt b/aeron-client/src/main/c/CMakeLists.txt index 4bbebe2eff..0126a97309 100644 --- a/aeron-client/src/main/c/CMakeLists.txt +++ b/aeron-client/src/main/c/CMakeLists.txt @@ -197,10 +197,12 @@ set(HEADERS aeronc.h) add_library(aeron SHARED ${SOURCE} ${HEADERS}) +add_library(aeron::aeron ALIAS aeron) target_include_directories(aeron PUBLIC "$" "$") add_library(aeron_static STATIC ${SOURCE} ${HEADERS}) +add_library(aeron::aeron_static ALIAS aeron_static) target_include_directories(aeron_static PUBLIC "$" "$") @@ -234,7 +236,7 @@ target_link_libraries( if (AERON_INSTALL_TARGETS) install( TARGETS aeron aeron_static - EXPORT AeronTargets + EXPORT aeron-targets RUNTIME DESTINATION lib LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) diff --git a/aeron-client/src/main/cpp/CMakeLists.txt b/aeron-client/src/main/cpp/CMakeLists.txt index 91c79ff960..d5a08247bb 100644 --- a/aeron-client/src/main/cpp/CMakeLists.txt +++ b/aeron-client/src/main/cpp/CMakeLists.txt @@ -138,7 +138,9 @@ SET(HEADERS # static library add_library(aeron_client STATIC ${SOURCE} ${HEADERS}) +add_library(aeron::aeron_client ALIAS aeron_client) add_library(aeron_client_shared SHARED ${SOURCE} ${HEADERS}) +add_library(aeron::aeron_client_shared ALIAS aeron_client_shared) target_include_directories(aeron_client PUBLIC "$" "$") @@ -176,7 +178,7 @@ target_link_libraries(aeron_client_shared if (AERON_INSTALL_TARGETS) install(TARGETS aeron_client_shared aeron_client - EXPORT AeronTargets + EXPORT aeron-targets RUNTIME DESTINATION lib LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) diff --git a/aeron-client/src/main/cpp_wrapper/CMakeLists.txt b/aeron-client/src/main/cpp_wrapper/CMakeLists.txt index 84dc22ed22..998ffb8e00 100644 --- a/aeron-client/src/main/cpp_wrapper/CMakeLists.txt +++ b/aeron-client/src/main/cpp_wrapper/CMakeLists.txt @@ -78,10 +78,11 @@ SET(HEADERS # header only library add_library(aeron_client_wrapper INTERFACE) +add_library(aeron::aeron_client_wrapper ALIAS aeron_client_wrapper) target_include_directories(aeron_client_wrapper INTERFACE "$" "$") -target_sources(aeron_client_wrapper INTERFACE FILE_SET HEADERS FILES ${HEADERS}) +#target_sources(aeron_client_wrapper INTERFACE FILE_SET HEADERS FILES ${HEADERS}) if (MSVC) string(REPLACE "/" "\\\\" NATIVE_PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}") @@ -99,6 +100,6 @@ target_link_libraries(aeron_client_wrapper INTERFACE ${CMAKE_THREAD_LIBS_INIT}) if (AERON_INSTALL_TARGETS) install( TARGETS aeron_client_wrapper - EXPORT AeronTargets - FILE_SET HEADERS DESTINATION include/wrapper) + EXPORT aeron-targets) + install(DIRECTORY ./ DESTINATION include/wrapper FILES_MATCHING PATTERN "*.h") endif () diff --git a/Config.cmake.in b/aeron-config.cmake.in similarity index 51% rename from Config.cmake.in rename to aeron-config.cmake.in index 2d2e72de2b..770c80c0ab 100644 --- a/Config.cmake.in +++ b/aeron-config.cmake.in @@ -4,6 +4,6 @@ include(CMakeFindDependencyMacro) find_package(Threads) find_package(Java) -include("${CMAKE_CURRENT_LIST_DIR}/AeronTargets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/aeron-targets.cmake") -check_required_components(Aeron) \ No newline at end of file +check_required_components(aeron) \ No newline at end of file diff --git a/aeron-driver/src/main/c/CMakeLists.txt b/aeron-driver/src/main/c/CMakeLists.txt index 0a8bbdec30..b0fb7c895a 100644 --- a/aeron-driver/src/main/c/CMakeLists.txt +++ b/aeron-driver/src/main/c/CMakeLists.txt @@ -349,11 +349,13 @@ SET(HEADERS aeronmd.h) add_library(aeron_driver SHARED ${SOURCE} ${HEADERS}) +add_library(aeron::aeron_driver ALIAS aeron_driver) target_include_directories(aeron_driver PUBLIC "$" "$") add_library(aeron_driver_static STATIC ${SOURCE} ${HEADERS}) +add_library(aeron::aeron_driver_static ALIAS aeron_driver_static) target_include_directories(aeron_driver_static PUBLIC "$" "$") @@ -441,7 +443,7 @@ if (AERON_INSTALL_TARGETS) endif () install( TARGETS aeron_driver aeron_driver_static - EXPORT AeronTargets + EXPORT aeron-targets RUNTIME DESTINATION lib LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)