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

export targets #403

Merged
merged 17 commits into from
May 20, 2020
Merged
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
24 changes: 10 additions & 14 deletions rosbag2_compression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ find_package(rcutils REQUIRED)
find_package(rosbag2_cpp)
find_package(rosbag2_storage REQUIRED)
find_package(zstd_vendor REQUIRED)
find_package(zstd REQUIRED)

add_library(${PROJECT_NAME}_zstd
SHARED
Expand All @@ -34,13 +35,12 @@ add_library(${PROJECT_NAME}_zstd
target_include_directories(${PROJECT_NAME}_zstd
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${zstd_vendor_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME}_zstd ${zstd_vendor_LIBRARIES})
$<INSTALL_INTERFACE:include>)
ament_target_dependencies(${PROJECT_NAME}_zstd
rcpputils
rcutils
rosbag2_storage)
rosbag2_storage
zstd)
# Causes the visibility macros to use dllexport rather than dllimport.
# This is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME}_zstd
Expand Down Expand Up @@ -70,21 +70,17 @@ install(
DESTINATION include)

install(
TARGETS ${PROJECT_NAME}_zstd
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

install(
TARGETS ${PROJECT_NAME}
TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_zstd
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME}_zstd)
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(rosbag2_storage rcutils zstd_vendor)
ament_export_libraries(${PROJECT_NAME} ${PROJECT_NAME}_zstd)
ament_export_targets(export_${PROJECT_NAME})
# order matters here, first vendor, then zstd
ament_export_dependencies(rcpputils rcutils rosbag2_cpp rosbag2_storage zstd_vendor zstd)

if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)
Expand Down
5 changes: 4 additions & 1 deletion rosbag2_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ ament_target_dependencies(${PROJECT_NAME}
rosbag2_storage
rosidl_runtime_c
rosidl_runtime_cpp
rosidl_typesupport_introspection_cpp
rosidl_typesupport_cpp
rosidl_typesupport_introspection_cpp
)

target_include_directories(${PROJECT_NAME}
Expand All @@ -87,16 +87,19 @@ install(

install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)

ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_export_targets(export_${PROJECT_NAME})
ament_export_dependencies(pluginlib
rosbag2_storage
rosidl_runtime_c
rosidl_runtime_cpp
rosidl_typesupport_cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to the change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding, when importing a cmake target, all dependencies have to present at cmake's generation step as opposed to using ${<pkg>_LIBRARIES} which is applied during linking. It's therefore important to export all necessary dependencies.

rosidl_typesupport_introspection_cpp
)

Expand Down
26 changes: 16 additions & 10 deletions rosbag2_storage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,38 @@ find_package(rcutils REQUIRED)
find_package(yaml_cpp_vendor REQUIRED)

add_library(
rosbag2_storage
${PROJECT_NAME}
SHARED
src/rosbag2_storage/metadata_io.cpp
src/rosbag2_storage/ros_helper.cpp
src/rosbag2_storage/storage_factory.cpp
src/rosbag2_storage/base_io_interface.cpp)
target_include_directories(rosbag2_storage PUBLIC include)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
ament_target_dependencies(
rosbag2_storage
${PROJECT_NAME}
pluginlib
rcpputils
rcutils
yaml_cpp_vendor)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(rosbag2_storage PRIVATE "ROSBAG2_STORAGE_BUILDING_DLL")
target_compile_definitions(${PROJECT_NAME} PRIVATE "ROSBAG2_STORAGE_BUILDING_DLL")

# prevent pluginlib from using boost
target_compile_definitions(rosbag2_storage PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
target_compile_definitions(${PROJECT_NAME} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")

install(
DIRECTORY include/
DESTINATION include)

install(
TARGETS rosbag2_storage
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
Expand All @@ -64,6 +69,7 @@ install(

ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_export_targets(export_${PROJECT_NAME})
ament_export_dependencies(pluginlib yaml_cpp_vendor)

if(BUILD_TESTING)
Expand All @@ -78,7 +84,7 @@ if(BUILD_TESTING)
SHARED
test/rosbag2_storage/test_plugin.cpp
test/rosbag2_storage/test_read_only_plugin.cpp)
target_link_libraries(test_plugin rosbag2_storage)
target_link_libraries(test_plugin ${PROJECT_NAME})
install(
TARGETS test_plugin
ARCHIVE DESTINATION lib
Expand All @@ -90,21 +96,21 @@ if(BUILD_TESTING)
test/rosbag2_storage/test_storage_factory.cpp)
if(TARGET test_storage_factory)
target_include_directories(test_storage_factory PRIVATE include)
target_link_libraries(test_storage_factory rosbag2_storage)
target_link_libraries(test_storage_factory ${PROJECT_NAME})
endif()

ament_add_gmock(test_ros_helper
test/rosbag2_storage/test_ros_helper.cpp)
if(TARGET test_ros_helper)
target_include_directories(test_ros_helper PRIVATE include)
target_link_libraries(test_ros_helper rosbag2_storage)
target_link_libraries(test_ros_helper ${PROJECT_NAME})
endif()

ament_add_gmock(test_metadata_serialization
test/rosbag2_storage/test_metadata_serialization.cpp)
if(TARGET test_metadata_serialization)
target_include_directories(test_metadata_serialization PRIVATE include)
target_link_libraries(test_metadata_serialization rosbag2_storage)
target_link_libraries(test_metadata_serialization ${PROJECT_NAME})
ament_target_dependencies(test_metadata_serialization rosbag2_test_common)
endif()
endif()
Expand Down
6 changes: 5 additions & 1 deletion rosbag2_test_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(${PROJECT_NAME} INTERFACE rclcpp rcutils)
ament_target_dependencies(${PROJECT_NAME} INTERFACE rclcpp rcutils)

install(
TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME})
install(
DIRECTORY include/
DESTINATION include)
Expand All @@ -42,4 +45,5 @@ endif()
ament_export_dependencies(rclcpp rcutils)

ament_export_include_directories(include)
ament_export_targets(export_${PROJECT_NAME})
ament_package()
22 changes: 11 additions & 11 deletions rosbag2_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ find_package(ament_index_cpp REQUIRED)
if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)
find_package(ament_lint_auto REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rcpputils REQUIRED)
find_package(rmw_fastrtps_cpp QUIET)
find_package(rosbag2_compression REQUIRED)
find_package(rosbag2_cpp REQUIRED)
find_package(rosbag2_storage REQUIRED)
find_package(rosbag2_storage_default_plugins REQUIRED)
find_package(rosbag2_test_common REQUIRED)
find_package(std_msgs REQUIRED)
find_package(test_msgs REQUIRED)

ament_lint_auto_find_test_dependencies()

find_package(rmw_fastrtps_cpp QUIET)
# disable tests that depends on rosbag2_converter_default_plugins at runtime
if(rmw_fastrtps_cpp_FOUND)
find_package(rclcpp REQUIRED)
find_package(rcpputils REQUIRED)
find_package(rosbag2_compression REQUIRED)
find_package(rosbag2_cpp REQUIRED)
find_package(rosbag2_storage REQUIRED)
find_package(rosbag2_storage_default_plugins REQUIRED)
find_package(rosbag2_test_common REQUIRED)
find_package(std_msgs REQUIRED)
find_package(test_msgs REQUIRED)

ament_add_gmock(test_rosbag2_record_end_to_end
test/rosbag2_tests/test_rosbag2_record_end_to_end.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
34 changes: 24 additions & 10 deletions shared_queues_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ find_package(ament_cmake REQUIRED)

include(ExternalProject)
# Single producer single consumer queue by moodycamel - header only, don't build, install
ExternalProject_Add(singleproducerconsumer
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/single
ExternalProject_Add(ext-singleproducerconsumer
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deliberately left in these changes because the cmake target of the ExternalProject_Add would collide with add_library.

PREFIX singleproducerconsumer
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/download
URL https://github.com/cameron314/readerwriterqueue/archive/ef7dfbf553288064347d51b8ac335f1ca489032a.zip
URL_MD5 64c673dd381b8fae9254053ad7b2be4d
TIMEOUT 60
Expand All @@ -17,8 +18,9 @@ ExternalProject_Add(singleproducerconsumer
)

# Concurrent and blocking concurrent queue by moodycamel - header only, don't build, install
ExternalProject_Add(concurrentqueue
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/multiple
ExternalProject_Add(ext-concurrentqueue
PREFIX concurrentqueue
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/download
URL https://github.com/cameron314/concurrentqueue/archive/8f65a8734d77c3cc00d74c0532efca872931d3ce.zip
URL_MD5 71a0d932cc89150c2ade85f0d9cac9dc
TIMEOUT 60
Expand All @@ -28,16 +30,28 @@ ExternalProject_Add(concurrentqueue
INSTALL_COMMAND ""
)

add_library(singleproducerconsumer INTERFACE)
target_include_directories(singleproducerconsumer INTERFACE $<INSTALL_INTERFACE:include/moodycamel>)

add_library(concurrentqueue INTERFACE)
target_include_directories(concurrentqueue INTERFACE $<INSTALL_INTERFACE:include/moodycamel>)

install(
TARGETS singleproducerconsumer concurrentqueue
EXPORT export_${PROJECT_NAME}
INCLUDES DESTINATION include
)

# Install headers
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/singleproducerconsumer-prefix/src/singleproducerconsumer/atomicops.h"
"${CMAKE_CURRENT_BINARY_DIR}/singleproducerconsumer-prefix/src/singleproducerconsumer/readerwriterqueue.h"
"${CMAKE_CURRENT_BINARY_DIR}/concurrentqueue-prefix/src/concurrentqueue/concurrentqueue.h"
"${CMAKE_CURRENT_BINARY_DIR}/concurrentqueue-prefix/src/concurrentqueue/blockingconcurrentqueue.h"
"${CMAKE_CURRENT_BINARY_DIR}/singleproducerconsumer/src/ext-singleproducerconsumer/atomicops.h"
"${CMAKE_CURRENT_BINARY_DIR}/singleproducerconsumer/src/ext-singleproducerconsumer/readerwriterqueue.h"
"${CMAKE_CURRENT_BINARY_DIR}/concurrentqueue/src/ext-concurrentqueue/concurrentqueue.h"
"${CMAKE_CURRENT_BINARY_DIR}/concurrentqueue/src/ext-concurrentqueue/blockingconcurrentqueue.h"
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/moodycamel
)

ament_export_include_directories(include)

ament_package()
ament_export_targets(export_${PROJECT_NAME})
ament_package()
16 changes: 11 additions & 5 deletions sqlite3_vendor/cmake/Modules/FindSQLite3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@

# First attempt to find Config-file package
find_package(SQLite3 CONFIG QUIET)

if (NOT SQLite3_FOUND)


if (SQLite3_FOUND)
message("Found SQLite3 from installed package in ${SQLite3_DIR}")
# https://cmake.org/cmake/help/latest/module/FindSQLite3.html
list(APPEND SQLite3_TARGETS SQLite::SQLite3)
else()
# Get package location hint from environment variable (if any)
if(NOT SQLite3_ROOT_DIR AND DEFINED ENV{SQLite3_ROOT_DIR})
set(SQLite3_ROOT_DIR "$ENV{SQLite3_ROOT_DIR}" CACHE PATH
Expand Down Expand Up @@ -74,11 +75,16 @@ if (NOT SQLite3_FOUND)
find_package_handle_standard_args(SQLite3 DEFAULT_MSG SQLite3_LIBRARY
SQLite3_INCLUDE_DIR)

set(SQLite3_FOUND ${SQLITE3_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
set(SQLite3_FOUND ${SQLite3_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
unset(SQLITE3_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args

if(SQLite3_FOUND)
set(SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR})
set(SQLite3_LIBRARIES ${SQLite3_LIBRARY})

add_library(SQLite::SQLite3 UNKNOWN IMPORTED)
set_property(TARGET SQLite::SQLite3 PROPERTY IMPORTED_LOCATION ${SQLite3_LIBRARY})
set_property(TARGET SQLite::SQLite3 PROPERTY INCLUDE_DIRECTORIES ${SQLite3_INCLUDE_DIR})
list(APPEND SQLite3_TARGETS SQLite::SQLite3)
endif()
endif()
8 changes: 5 additions & 3 deletions zstd_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ macro(build_zstd)
SOURCE_SUBDIR build/cmake
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_install
-DZSTD_BUILD_STATIC=OFF
-DZSTD_BUILD_SHARED=ON
-DZSTD_BUILD_PROGRAMS=OFF
${extra_cmake_args})

install(
Expand All @@ -49,7 +52,6 @@ else()
message(STATUS "Found Zstd, skipping build.")
endif()

ament_export_libraries(zstd)
ament_export_include_directories(include)
install(DIRECTORY cmake DESTINATION share/${PROJECT_NAME})

ament_package()
ament_package(CONFIG_EXTRAS zstd_vendor-extras.cmake)
41 changes: 41 additions & 0 deletions zstd_vendor/cmake/Modules/Findzstd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Get package location hint from environment variable (if any)
if(NOT zstd_ROOT_DIR AND DEFINED ENV{zstd_ROOT_DIR})
set(zstd_ROOT_DIR "$ENV{zstd_ROOT_DIR}" CACHE PATH
"zstd base directory location (optional, used for nonstandard installation paths)")
endif()

# Search path for nonstandard package locations
if(zstd_ROOT_DIR)
set(zstd_INCLUDE_PATH PATHS "${zstd_ROOT_DIR}/include" NO_DEFAULT_PATH)
set(zstd_LIBRARY_PATH PATHS "${zstd_ROOT_DIR}/lib" NO_DEFAULT_PATH)
else()
set(zstd_INCLUDE_PATH "")
set(zstd_LIBRARY_PATH "")
endif()

# Find headers and libraries
find_path(zstd_INCLUDE_DIR NAMES zstd.h PATH_SUFFIXES "zstd" ${zstd_INCLUDE_PATH})
find_library(zstd_LIBRARY NAMES zstd PATH_SUFFIXES "zstd" ${zstd_LIBRARY_PATH})

mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY)

# Output variables generation
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(zstd DEFAULT_MSG zstd_LIBRARY zstd_INCLUDE_DIR)

set(zstd_FOUND ${ZSTD_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
unset(ZSTD_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args

if(zstd_FOUND)
set(zstd_INCLUDE_DIRS ${zstd_INCLUDE_DIR})
set(zstd_LIBRARIES ${zstd_LIBRARY})

if(NOT TARGET zstd::zstd)
add_library(zstd::zstd UNKNOWN IMPORTED)
set_property(TARGET zstd::zstd PROPERTY IMPORTED_LOCATION ${zstd_LIBRARY})
set_property(TARGET zstd::zstd PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${zstd_INCLUDE_DIR})
endif()
list(APPEND zstd_TARGETS zstd::zstd)
elseif(zstd_FIND_REQUIRED)
message(FATAL_ERROR "Unable to find zstd")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I usually try to exit early to avoid indentation, like:

if(NOT zstd_FOUND)
  message(FATAL_ERROR "Unable to find zstd")
endif()

...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exiting early is preferred.

There was actually another problem in here though, in that it would fail (FATAL_ERROR) regardless whether find_package(zstd) was called with REQUIRED or not. So I've changed that. With this however, I don't see a good way of exiting earlier anymore.

endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this package doesn't use linters yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not and but can be added in a follow up PR.

1 change: 1 addition & 0 deletions zstd_vendor/zstd_vendor-extras.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list(INSERT CMAKE_MODULE_PATH 0 "${zstd_vendor_DIR}/Modules")