Skip to content
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

Added PackageConfigHelpers to make the library easier to use #13

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 38 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -56,7 +71,7 @@ set(OPENDDS_TARGETS
OpenDDS::Rtps_Udp
)

target_include_directories(OpenDDW INTERFACE src)
#target_include_directories(OpenDDW INTERFACE src)
iguessthislldo marked this conversation as resolved.
Show resolved Hide resolved

target_link_libraries(OpenDDW
${OPENDDS_TARGETS}
Expand All @@ -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}
)
iguessthislldo marked this conversation as resolved.
Show resolved Hide resolved

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)