Skip to content

Commit

Permalink
[C] Add Cmake library aliases to better integrate FetchContent with f…
Browse files Browse the repository at this point in the history
…ind_package
  • Loading branch information
marc-adaptive committed Aug 9, 2024
1 parent dc86699 commit 4568e07
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 39 deletions.
58 changes: 30 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
"${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)

7 changes: 4 additions & 3 deletions aeron-archive/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ()
4 changes: 3 additions & 1 deletion aeron-client/src/main/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" "$<INSTALL_INTERFACE:include/aeron>")

add_library(aeron_static STATIC ${SOURCE} ${HEADERS})
add_library(aeron::aeron_static ALIAS aeron_static)
target_include_directories(aeron_static
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" "$<INSTALL_INTERFACE:include/aeron>")

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion aeron-client/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" "$<INSTALL_INTERFACE:include>")
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions aeron-client/src/main/cpp_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>" "$<INSTALL_INTERFACE:include/wrapper>")

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}")
Expand All @@ -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 ()
4 changes: 2 additions & 2 deletions Config.cmake.in → aeron-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
check_required_components(aeron)
4 changes: 3 additions & 1 deletion aeron-driver/src/main/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};${AERON_C_CLIENT_SOURCE_PATH}>"
"$<INSTALL_INTERFACE:include/aeronmd;include/aeron>")

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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};${AERON_C_CLIENT_SOURCE_PATH}>"
"$<INSTALL_INTERFACE:include/aeronmd;include/aeron>")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4568e07

Please sign in to comment.