Skip to content

Commit

Permalink
Merge pull request #13 from doug1234/PackageConfigHelpers
Browse files Browse the repository at this point in the history
Added PackageConfigHelpers to make the library easier to use
  • Loading branch information
iguessthislldo authored Oct 2, 2023
2 parents 468682b + 5d5166c commit 8753ddf
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
62 changes: 61 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +25,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}
Expand Down Expand Up @@ -56,7 +72,15 @@ set(OPENDDS_TARGETS
OpenDDS::Rtps_Udp
)

target_include_directories(OpenDDW INTERFACE src)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

set_property(TARGET ${PROJECT_NAME}
APPEND PROPERTY PUBLIC_HEADER
${MANAGER_HEADER}
)

target_link_libraries(OpenDDW
${OPENDDS_TARGETS}
Expand All @@ -65,7 +89,43 @@ target_link_libraries(OpenDDW

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}
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}"
)
64 changes: 64 additions & 0 deletions openddw-config.in.cmake
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 8753ddf

Please sign in to comment.