Skip to content

Make find_package work for rmqcpp #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/rmq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ endif()

target_compile_definitions(rmq PRIVATE USES_LIBRMQ_EXPERIMENTAL_FEATURES)

target_include_directories(rmq PUBLIC rmqt rmqp rmqa)
target_include_directories(rmq PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rmqt>)
target_include_directories(rmq PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rmqp>)
target_include_directories(rmq PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rmqa>)
Comment on lines +26 to +28
Copy link
Contributor Author

@ahsanabbas123 ahsanabbas123 Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These generator expressions are required if we are creating a relocatable package (with no absolute paths) which uses install(TARGETS) and install(EXPORT) later to produce the rmqcppTargets.cmake file.



file(GLOB RMQ_PUBLIC_HEADERS rmqa/*h rmqp/*h rmqt/*h)
set_target_properties(rmq PROPERTIES PUBLIC_HEADER "${RMQ_PUBLIC_HEADERS}")

install(
TARGETS rmq
EXPORT rmqcppTargets
ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT librmq-dev
Expand All @@ -38,6 +42,17 @@ install(
COMPONENT librmq-dev
)

install(EXPORT rmqcppTargets
FILE rmqcppTargets.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/rmqcpp
NAMESPACE rmqcpp::)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to go with rmqcpp::rmq be how users link to rmqcpp, with rmqcpp::rmqtestmocks a possibility in future.


include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses Config.cmake.in as input and produces the rmqcppConfig.cmake which find_package looks for.

"${CMAKE_CURRENT_BINARY_DIR}/rmqcppConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/share/rmqcpp)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rmqcppConfig.cmake" DESTINATION ${CMAKE_INSTALL_PREFIX}/share/rmqcpp)

# Emit some metadata required internally
set(RMQ_PC_DEP_NAMES bsl bdl bal openssl)
find_package(GenBDEMetadata QUIET)
Expand All @@ -47,4 +62,4 @@ endif()
find_package(EmitPkgConfigFile QUIET)
if (EmitPkgConfigFile_FOUND)
emit_pkgconfig_file(PKG rmq INSTALL_COMPONENT librmq-dev DEPS "${RMQ_PC_DEP_NAMES}")
endif()
endif()
11 changes: 11 additions & 0 deletions src/rmq/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@PACKAGE_INIT@

if(NOT TARGET rmqcpp)
foreach(dep bal;OpenSSL;ZLIB)
find_package(${dep})
endforeach()
Comment on lines +4 to +6
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are needed so that the consuming upstream application does not need to explicitly do find_package(dep) for deps of rmqcpp.

endif()

include("${CMAKE_CURRENT_LIST_DIR}/rmqcppTargets.cmake")

check_required_components(rmqcpp)