From 6d1de917c0e1055605c2597075567da28f242ab1 Mon Sep 17 00:00:00 2001 From: Douglas Ayers Date: Fri, 22 Sep 2023 15:41:37 -0400 Subject: [PATCH 1/2] Added PackageConfigHelpers to make the library easier to use. --- CMakeLists.txt | 39 ++++++++++++++++++++++++- openddw-config.in.cmake | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 openddw-config.in.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2937834..732af97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,21 @@ set(MANAGER_SOURCE src/qos_dictionary.cpp ) +SET(CONFIG_FILE_INSTALL_LOCATION "share/cmake/${PROJECT_NAME}") +SET(PROJECT_PACKAGE_NAME "${PROJECT_NAME}") + +STRING(TOLOWER "${PROJECT_PACKAGE_NAME}" PROJECT_PACKAGE_NAME) +STRING(TOUPPER "${PROJECT_NAME}" PROJECT_MACRO_PREFIX) + +SET(PROJECT_PACKAGE_CONFIG_IN_FILE "${PROJECT_PACKAGE_NAME}-config.in.cmake") +SET(PROJECT_PACKAGE_CONFIG_FILE "${PROJECT_PACKAGE_NAME}-config.cmake") +SET(PROJECT_PACKAGE_CONFIG_VERSION_FILE "${PROJECT_PACKAGE_NAME}-config-version.cmake") +SET(PROJECT_TARGET_FILE "${PROJECT_PACKAGE_NAME}-targets.cmake") +SET(PROJECT_TARGET_PREFIX ${PROJECT_NAME}) +SET(PROJECT_TARGET_LIST ${PROJECT_NAME}) + +SET(PROJECT_PUBLIC_HEADER_LOCATION "include/${PROJECT_NAME}") + add_library(OpenDDW ${MANAGER_HEADER} ${MANAGER_SOURCE} @@ -56,7 +71,7 @@ set(OPENDDS_TARGETS OpenDDS::Rtps_Udp ) -target_include_directories(OpenDDW INTERFACE src) +#target_include_directories(OpenDDW INTERFACE src) target_link_libraries(OpenDDW ${OPENDDS_TARGETS} @@ -65,7 +80,29 @@ target_link_libraries(OpenDDW OPENDDS_TARGET_SOURCES(OpenDDW idl/std_qos.idl) +INCLUDE(CMakePackageConfigHelpers) + +INSTALL(EXPORT ${PROJECT_NAME} + NAMESPACE ${PROJECT_TARGET_PREFIX}:: + FILE ${PROJECT_TARGET_FILE} + DESTINATION ${CONFIG_FILE_INSTALL_LOCATION} +) + +CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_PACKAGE_CONFIG_IN_FILE} + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PACKAGE_CONFIG_FILE}" + INSTALL_DESTINATION ${CONFIG_FILE_INSTALL_LOCATION} + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO +) + +WRITE_BASIC_PACKAGE_VERSION_FILE( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PACKAGE_CONFIG_VERSION_FILE}" + COMPATIBILITY AnyNewerVersion +) + INSTALL(FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PACKAGE_CONFIG_FILE}" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PACKAGE_CONFIG_VERSION_FILE}" "${PROJECT_SOURCE_DIR}/idl2library.cmake" DESTINATION "share/cmake/${PROJECT_NAME}" ) diff --git a/openddw-config.in.cmake b/openddw-config.in.cmake new file mode 100644 index 0000000..344c192 --- /dev/null +++ b/openddw-config.in.cmake @@ -0,0 +1,64 @@ +@PACKAGE_INIT@ + +set(@PROJECT_NAME@_TARGET_LIST + @PROJECT_TARGET_LIST@ +) + +include(CMakeFindDependencyMacro) + +# Find OpenDDS +#This allows DDS_ROOT to be set off OpenDDSConfig.cmake location +option(OPENDDS_ALLOW_ENV_CHANGE "Allow multiple find_package(opendds) calls." ON) +option(OPENDDS_FILENAME_ONLY_INCLUDES "No directory info in generated #includes." ON) +find_package(OpenDDS REQUIRED) + +#Include idl2dll.cmake so it can be used if/when needed +include(${CMAKE_CURRENT_LIST_DIR}/idl2library.cmake) + +list(GET ${@PROJECT_NAME@_TARGET_LIST} 0 _FIRST_TARGET) +if(NOT TARGET ${_FIRST_TARGET}) + # Include the CMake targets file for @PROJECT_NAME@. + # All targets are specified in this file. + include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_TARGET_FILE@) +endif(NOT TARGET ${_FIRST_TARGET}) + +# Iterate over all targets and set appropriate properties. +# Most projects will only have one target, but some may include multiple targets that can be imported with one find_package call. +set(_TARGET_FULL_NAME "") +foreach(_TARGET_NAME IN LISTS @PROJECT_NAME@_TARGET_LIST) + set(_TARGET_FULL_NAME "@PROJECT_TARGET_PREFIX@::${_TARGET_NAME}") + get_target_property(_IMPORTED_CONFIGS ${_TARGET_FULL_NAME} IMPORTED_CONFIGURATIONS) + #Release config is required, so assume it is present + #RelWithDebInfo is optional + #Debug is optional + #MinSizeRel is normally not required, but covered as optional here for completeness' sake + if(NOT "RELWITHDEBINFO" IN_LIST _IMPORTED_CONFIGS) + set_target_properties(${_TARGET_FULL_NAME} PROPERTIES + MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release + ) + endif(NOT "RELWITHDEBINFO" IN_LIST _IMPORTED_CONFIGS) + + if(NOT "DEBUG" IN_LIST _IMPORTED_CONFIGS) + if ("RELWITHDEBINFO" IN_LIST _IMPORTED_CONFIGS) + set_target_properties(${_TARGET_FULL_NAME} PROPERTIES + MAP_IMPORTED_CONFIG_DEBUG RelWithDebInfo + ) + else("RELWITHDEBINFO" IN_LIST _IMPORTED_CONFIGS) + set_target_properties(${_TARGET_FULL_NAME} PROPERTIES + MAP_IMPORTED_CONFIG_DEBUG Release + ) + endif("RELWITHDEBINFO" IN_LIST _IMPORTED_CONFIGS) + endif(NOT "DEBUG" IN_LIST _IMPORTED_CONFIGS) + + if(NOT "MINSIZEREL" IN_LIST _IMPORTED_CONFIGS) + set_target_properties(${_TARGET_FULL_NAME} PROPERTIES + MAP_IMPORTED_CONFIG_MINSIZEREL Release + ) + endif(NOT "MINSIZEREL" IN_LIST _IMPORTED_CONFIGS) +endforeach(_TARGET_NAME) + +set(_TARGET_FULL_NAME) +set(_IMPORTED_CONFIGS) +set(@PROJECT_NAME@_TARGET_LIST) +set(_FIRST_TARGET) + From 5d5166cf35ac6069455a27e7cbbc657393aecf41 Mon Sep 17 00:00:00 2001 From: Douglas Ayers Date: Mon, 2 Oct 2023 10:30:22 -0400 Subject: [PATCH 2/2] Several improvements to the cmake file. This should fix the CI build errors. --- CMakeLists.txt | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 732af97..9d9c622 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set(MANAGER_HEADER src/participant_monitor.h src/platformIndependent.h src/qos_dictionary.h + src/dds_manager.hpp ) set(MANAGER_SOURCE @@ -71,7 +72,15 @@ set(OPENDDS_TARGETS OpenDDS::Rtps_Udp ) -#target_include_directories(OpenDDW INTERFACE src) +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +) + +set_property(TARGET ${PROJECT_NAME} + APPEND PROPERTY PUBLIC_HEADER + ${MANAGER_HEADER} +) target_link_libraries(OpenDDW ${OPENDDS_TARGETS} @@ -82,12 +91,26 @@ OPENDDS_TARGET_SOURCES(OpenDDW idl/std_qos.idl) INCLUDE(CMakePackageConfigHelpers) +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME} + + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + PUBLIC_HEADER DESTINATION include +) + INSTALL(EXPORT ${PROJECT_NAME} NAMESPACE ${PROJECT_TARGET_PREFIX}:: FILE ${PROJECT_TARGET_FILE} DESTINATION ${CONFIG_FILE_INSTALL_LOCATION} ) +INSTALL(FILES + idl/std_qos.idl + DESTINATION idl +) + CONFIGURE_PACKAGE_CONFIG_FILE(${PROJECT_PACKAGE_CONFIG_IN_FILE} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PACKAGE_CONFIG_FILE}" INSTALL_DESTINATION ${CONFIG_FILE_INSTALL_LOCATION}