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: use modern cmake #70

Merged
merged 6 commits into from
Feb 24, 2024
Merged
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
150 changes: 109 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.19)
wep21 marked this conversation as resolved.
Show resolved Hide resolved
project(filters)

# Default to C++14
Expand All @@ -17,58 +17,127 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(Boost REQUIRED)
find_package(Boost REQUIRED COMPONENTS headers)

##############################################################################
# Build
##############################################################################

add_library(real_time_circular_buffer INTERFACE)
target_include_directories(real_time_circular_buffer INTERFACE
include
${Boost_INCLUDE_DIRS})
add_library(realtime_circular_buffer
INTERFACE
include/filters/realtime_circular_buffer.h
include/filters/realtime_circular_buffer.hpp
)
target_link_libraries(realtime_circular_buffer
INTERFACE
Boost::boost
)
target_include_directories(realtime_circular_buffer
Copy link

Choose a reason for hiding this comment

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

Instead of repeating this call, consider using a for loop and giving a list of targets to set up the includes for.
This would reduce code duplication.

Copy link
Author

Choose a reason for hiding this comment

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

address here

INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

add_library(filter_base
INTERFACE
include/filters/filter_base.h
include/filters/filter_base.hpp
)
target_link_libraries(filter_base
INTERFACE
rclcpp::rclcpp
)
target_include_directories(filter_base
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

add_library(filter_chain
INTERFACE
include/filters/filter_chain.h
include/filters/filter_chain.hpp
)
target_link_libraries(filter_chain
INTERFACE
filter_base
pluginlib::pluginlib
)
target_include_directories(filter_chain
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

# Plugins
add_library(mean SHARED src/mean.cpp)
target_link_libraries(mean
real_time_circular_buffer)
ament_target_dependencies(mean
"pluginlib"
"rclcpp"
realtime_circular_buffer
Copy link

Choose a reason for hiding this comment

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

Can you specify PUBLIC or PRIVATE for the linkage type?

Copy link
Author

Choose a reason for hiding this comment

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

address here

filter_base
pluginlib::pluginlib
)
target_include_directories(mean
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

add_library(params SHARED src/test_params.cpp)
target_link_libraries(params
real_time_circular_buffer)
ament_target_dependencies(params
"pluginlib"
"rclcpp"
filter_base
pluginlib::pluginlib
)
target_include_directories(params
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

add_library(increment SHARED src/increment.cpp)
target_link_libraries(increment
real_time_circular_buffer)
ament_target_dependencies(increment
"pluginlib"
"rclcpp"
realtime_circular_buffer
filter_base
pluginlib::pluginlib
)
target_include_directories(increment
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

add_library(median SHARED src/median.cpp)
target_link_libraries(median
real_time_circular_buffer)
ament_target_dependencies(median
"pluginlib"
"rclcpp"
realtime_circular_buffer
filter_base
pluginlib::pluginlib
)
target_include_directories(median
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

add_library(transfer_function SHARED src/transfer_function.cpp)
target_link_libraries(transfer_function
real_time_circular_buffer)
ament_target_dependencies(transfer_function
"pluginlib"
"rclcpp"
realtime_circular_buffer
filter_base
pluginlib::pluginlib
)
target_include_directories(transfer_function
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)

install(TARGETS realtime_circular_buffer filter_base filter_chain mean increment median transfer_function
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)

install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME})

if(BUILD_TESTING)
# TODO(hidmic): use ament_lint_common once ament_copyright complains are resolved
find_package(ament_cmake_cppcheck REQUIRED)
Expand Down Expand Up @@ -104,7 +173,7 @@ if(BUILD_TESTING)

# Test realtime safe buffer class
ament_add_gtest(realtime_buffer_test test/test_realtime_circular_buffer.cpp)
target_link_libraries(realtime_buffer_test real_time_circular_buffer)
target_link_libraries(realtime_buffer_test realtime_circular_buffer)

# Pluginlib specific testing for filter chain
set(test_prefix "${CMAKE_CURRENT_BINARY_DIR}/pluginlib_test_prefix")
Expand Down Expand Up @@ -141,29 +210,28 @@ if(BUILD_TESTING)
foreach(test_plugin_target IN LISTS test_plugin_targets)
add_dependencies(chain_test "copy_${test_plugin_target}_for_testing")
endforeach()
ament_target_dependencies(chain_test
"rclcpp"
"pluginlib"
target_link_libraries(chain_test
filter_chain
)
endif()

##############################################################################
# Install
##############################################################################

# Install libraries
install(
TARGETS mean increment median transfer_function
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
# Export old-style CMake variables
ament_export_include_directories("include/${PROJECT_NAME}")
ament_export_libraries(${PROJECT_NAME})

# Export modern CMake targets
ament_export_targets(export_${PROJECT_NAME})

# Install headers
install(DIRECTORY include/
DESTINATION include)
ament_export_dependencies(
Boost
pluginlib
rclcpp
)

# Install pluginlib xml
pluginlib_export_plugin_description_file(filters "default_plugins.xml")
ament_export_include_directories(include)
ament_package()