diff --git a/CMakeLists.txt b/CMakeLists.txt index 838c0ac..7d81859 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,11 +49,13 @@ if(Boost_Dynamic_Linking_ENABLED) endif() find_package(Boost 1.47.0 COMPONENTS chrono system REQUIRED) +set(PROJECT_DEP_PKG "Boost 1.47.0 COMPONENTS chrono system") include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Modules) find_package(rabbitmq-c CONFIG REQUIRED) +list(APPEND PROJECT_DEP_PKG "rabbitmq-c") option(ENABLE_SSL_SUPPORT "Enable SSL support." ${Rabbitmqc_SSL_ENABLED}) @@ -134,7 +136,7 @@ set(SAC_LIB_SRCS add_library(SimpleAmqpClient ${SAC_LIB_SRCS}) -target_link_libraries(SimpleAmqpClient rabbitmq::rabbitmq-static ${SOCKET_LIBRARY} ${Boost_LIBRARIES} $<$:Boost::dynamic_linking>) +target_link_libraries(SimpleAmqpClient rabbitmq::rabbitmq-static ${SOCKET_LIBRARY} Boost::chrono Boost::system $<$:Boost::dynamic_linking>) if (WIN32) set_target_properties(SimpleAmqpClient PROPERTIES VERSION ${SAC_VERSION} OUTPUT_NAME SimpleAmqpClient.${SAC_SOVERSION}) @@ -194,6 +196,7 @@ endif () include(GNUInstallDirs) install(TARGETS SimpleAmqpClient + EXPORT ${PROJECT_NAME}Targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -243,3 +246,42 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libSimpleAmqpClient.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) + +include(CMakePackageConfigHelpers) +# create and install target cmake file +install( + EXPORT ${PROJECT_NAME}Targets + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + +# create main config file for find_package +# create project config file +set(PROJECT_CONFIG_CONTENT "@PACKAGE_INIT@\n") +# appending find_dependency for each dependency +if(PROJECT_DEP_PKG) + string(APPEND PROJECT_CONFIG_CONTENT "include(CMakeFindDependencyMacro)\n") + foreach(PKG_NAME ${PROJECT_DEP_PKG}) + string(APPEND PROJECT_CONFIG_CONTENT + "find_dependency(${PKG_NAME} REQUIRED)\n") + endforeach() +endif() +string(APPEND PROJECT_CONFIG_CONTENT + "include(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake\")") +file(WRITE PROJECT_CONFIG_FILE ${PROJECT_CONFIG_CONTENT}) + +configure_package_config_file( + PROJECT_CONFIG_FILE ${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + +file(REMOVE PROJECT_CONFIG_FILE) + +# create version file +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${SAC_VERSION} + COMPATIBILITY SameMajorVersion) + +# install cmake configs +install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")