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

feat: add option to export libraries as cmake targets #455

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions ament_cmake_auto/cmake/ament_auto_add_library.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ macro(ament_auto_add_library target)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include")
if(ARG_INTERFACE)
target_include_directories("${target}" INTERFACE
"${CMAKE_CURRENT_SOURCE_DIR}/include")
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
else()
target_include_directories("${target}" PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/include")
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
endif()
endif()
# link against other libraries of this package
Expand Down
40 changes: 29 additions & 11 deletions ament_cmake_auto/cmake/ament_auto_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#

macro(ament_auto_package)
cmake_parse_arguments(_ARG "INSTALL_TO_PATH" "" "INSTALL_TO_SHARE" ${ARGN})
cmake_parse_arguments(_ARG "INSTALL_TO_PATH;EXPORT_LIBRARY_TARGETS" "" "INSTALL_TO_SHARE" ${ARGN})
# passing all unparsed arguments to ament_package()

# export all found build dependencies which are also run dependencies
Expand All @@ -66,22 +66,40 @@ macro(ament_auto_package)
endif()

# export and install all libraries
if(NOT ${PROJECT_NAME}_LIBRARIES STREQUAL "")
set(without_interfaces "")
foreach(library_name ${${PROJECT_NAME}_LIBRARIES})
get_target_property(library_type ${library_name} TYPE)
if(NOT "${library_type}" STREQUAL "INTERFACE_LIBRARY")
list(APPEND without_interfaces ${library_name})
endif()
endforeach()
if (_ARG_EXPORT_LIBRARY_TARGETS)
# will export all libraries using modern cmake targets
list(APPEND ${PROJECT_NAME}_TARGETS "${${PROJECT_NAME}_LIBRARIES}")
else()
# old style library export
if(NOT ${PROJECT_NAME}_LIBRARIES STREQUAL "")
set(without_interfaces "")
foreach(library_name ${${PROJECT_NAME}_LIBRARIES})
get_target_property(library_type ${library_name} TYPE)
if(NOT "${library_type}" STREQUAL "INTERFACE_LIBRARY")
list(APPEND without_interfaces ${library_name})
endif()
endforeach()

ament_export_libraries(${without_interfaces})
ament_export_libraries(${without_interfaces})
install(
TARGETS ${without_interfaces}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
endif()
endif()

# export all targets for downstream packages
if(NOT "${${PROJECT_NAME}_TARGETS}" STREQUAL "")
install(
TARGETS ${without_interfaces}
TARGETS ${${PROJECT_NAME}_TARGETS}
EXPORT ${PROJECT_NAME}Targets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
ament_export_targets(${PROJECT_NAME}Targets)
endif()

# install all executables
Expand Down