Skip to content

Commit

Permalink
update cmake for increase portability and add ability to use with fin…
Browse files Browse the repository at this point in the history
…d_package
  • Loading branch information
prateek9623 committed Mar 30, 2021
1 parent 584a486 commit d0c1c93
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down Expand Up @@ -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} $<$<BOOL:${Boost_Dynamic_Linking_ENABLED}>:Boost::dynamic_linking>)
target_link_libraries(SimpleAmqpClient rabbitmq::rabbitmq-static ${SOCKET_LIBRARY} Boost::chrono Boost::system $<$<BOOL:${Boost_Dynamic_Linking_ENABLED}>:Boost::dynamic_linking>)

if (WIN32)
set_target_properties(SimpleAmqpClient PROPERTIES VERSION ${SAC_VERSION} OUTPUT_NAME SimpleAmqpClient.${SAC_SOVERSION})
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}")

0 comments on commit d0c1c93

Please sign in to comment.