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

Revamp CMake to make compilation significantly faster #4357

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dfa7ce5
Revamp nav2_util CMakeLists.txt to use modern idioms.
clalancette May 17, 2024
02efe70
Update nav2_behavior_tree to use modern CMake idioms.
clalancette May 19, 2024
9716133
Switch nav2_voxel_grid to modern CMake idioms.
clalancette May 19, 2024
55d26a9
Switch nav2_map_server to modern CMake idioms.
clalancette May 19, 2024
096928b
Switch nav2_amcl to modern CMake idioms.
clalancette May 20, 2024
3679802
Convert nav2_costmap_2d to modern CMake idioms.
clalancette May 20, 2024
58d9e36
Small updates to nav2_core.
clalancette May 20, 2024
e55df65
Update nav2_behaviors to use modern CMake idioms.
clalancette May 20, 2024
a98e0b3
Switch nav2_bt_navigator to modern CMake idioms.
clalancette May 20, 2024
92301f2
Swithc nav2_collision_monitor to modern CMake idioms.
clalancette May 20, 2024
8044841
Revamp nav2_constrained_smoother to use modern CMake idioms.
clalancette May 20, 2024
63d3b6f
Switch nav_2d_utils to use modern CMake idioms.
clalancette May 20, 2024
9d3e628
Switch nav2_controller to modern CMake idioms.
clalancette May 20, 2024
9e3ed8d
Switch nav2_lifecycle_manager to modern CMake idioms.
clalancette May 20, 2024
2f5fdfe
Switch nav2_mppi_controller to use modern CMake idioms.
clalancette May 20, 2024
eda8ba3
Switch nav2_navfn_planner to modern CMake idioms.
clalancette May 20, 2024
3b87d7c
Switch nav2_planner to modern CMake idioms.
clalancette May 20, 2024
7e66b91
Switch nav2_regulated_pure_pursuit_controller to modern CMake idioms.
clalancette May 20, 2024
55477b5
Switch nav2_rotation_shim_controller to modern CMake idioms.
clalancette May 20, 2024
a30efd0
Switch nav2_rviz_plugins to modern CMake idioms.
clalancette May 20, 2024
2038f2b
Rewrite nav2_system_tests to use modern CMake idioms.
clalancette May 20, 2024
41ee273
Switch nav2_smoother to modern CMake idioms.
clalancette May 21, 2024
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
130 changes: 85 additions & 45 deletions nav2_amcl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,72 +20,111 @@ find_package(pluginlib REQUIRED)

nav2_package()

include_directories(
include
)

include(CheckSymbolExists)
check_symbol_exists(drand48 stdlib.h HAVE_DRAND48)

add_subdirectory(src/pf)
add_subdirectory(src/map)
add_subdirectory(src/motion_model)
add_subdirectory(src/sensors)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-gnu-folding-constant)
Copy link
Member

@SteveMacenski SteveMacenski May 21, 2024

Choose a reason for hiding this comment

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

Can you explain this added for AMCL specifically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is a good question. The honest truth is that for reasons I don't totally understand, having the targets in the subdirectory doesn't produce nav2_amcl targets that "worked". In particular, the downstream package linking against it (nav2_system_tests) would fail to properly find the target. Moving this all together into the main CMakeLists.txt seemed to make it work. It bears more investigation into why that is happening.

endif()

set(executable_name amcl)
add_library(pf_lib SHARED
src/pf/pf.c
src/pf/pf_kdtree.c
src/pf/pf_pdf.c
src/pf/pf_vector.c
src/pf/eig3.c
src/pf/pf_draw.c
)
target_include_directories(pf_lib
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
if(HAVE_DRAND48)
target_compile_definitions(pf_lib PRIVATE "HAVE_DRAND48")
endif()

add_executable(${executable_name}
src/main.cpp
add_library(map_lib SHARED
src/map/map.c
src/map/map_range.c
src/map/map_draw.c
src/map/map_cspace.cpp
)
target_include_directories(map_lib
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")

add_library(motions_lib SHARED
src/motion_model/omni_motion_model.cpp
src/motion_model/differential_motion_model.cpp
)
target_include_directories(motions_lib
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(motions_lib pf_lib pluginlib::pluginlib nav2_util::nav2_util_core)

add_library(sensors_lib SHARED
src/sensors/laser/laser.cpp
src/sensors/laser/beam_model.cpp
src/sensors/laser/likelihood_field_model.cpp
src/sensors/laser/likelihood_field_model_prob.cpp
)
target_include_directories(sensors_lib
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(sensors_lib pf_lib map_lib)

set(executable_name amcl)

set(library_name ${executable_name}_core)

add_library(${library_name} SHARED
src/amcl_node.cpp
)

target_include_directories(${library_name} PRIVATE src/include)

if(HAVE_DRAND48)
target_compile_definitions(${library_name} PRIVATE "HAVE_DRAND48")
endif()

set(dependencies
rclcpp
rclcpp_lifecycle
rclcpp_components
message_filters
tf2_geometry_msgs
geometry_msgs
nav_msgs
sensor_msgs
std_srvs
tf2_ros
tf2
nav2_util
nav2_msgs
pluginlib
)

ament_target_dependencies(${executable_name}
${dependencies}
target_include_directories(${library_name}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${library_name} PUBLIC
${geometry_msgs_TARGETS}
message_filters::message_filters
nav2_util::nav2_util_core
${sensor_msgs_TARGETS}
${std_srvs_TARGETS}
pluginlib::pluginlib
sensors_lib
rclcpp::rclcpp
rclcpp_lifecycle::rclcpp_lifecycle
${nav_msgs_TARGETS}
tf2_ros::tf2_ros
tf2::tf2
${nav2_msgs_TARGETS}
)

target_link_libraries(${executable_name}
${library_name}
target_link_libraries(${library_name} PRIVATE
rclcpp_components::component
${tf2_geometry_msgs_TARGETS}
)

ament_target_dependencies(${library_name}
${dependencies}
add_executable(${executable_name}
src/main.cpp
)

target_link_libraries(${library_name}
map_lib pf_lib sensors_lib
target_include_directories(${executable_name}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${executable_name} PRIVATE
${library_name}
)

rclcpp_components_register_nodes(${library_name} "nav2_amcl::AmclNode")

install(TARGETS ${library_name}
install(TARGETS ${library_name} pf_lib map_lib motions_lib sensors_lib
EXPORT ${library_name}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
Expand All @@ -96,7 +135,7 @@ install(TARGETS ${executable_name}
)

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

if(BUILD_TESTING)
Expand All @@ -109,6 +148,7 @@ endif()

ament_export_include_directories(include)
ament_export_libraries(${library_name} pf_lib sensors_lib motions_lib map_lib)
ament_export_dependencies(${dependencies})
ament_export_dependencies(geometry_msgs message_filters nav2_util sensor_msgs std_srvs pluginlib rclcpp rclcpp_lifecycle nav_msgs tf2_ros tf2 nav2_msgs)
ament_export_targets(${library_name})
pluginlib_export_plugin_description_file(nav2_amcl plugins.xml)
ament_package()
13 changes: 0 additions & 13 deletions nav2_amcl/src/map/CMakeLists.txt

This file was deleted.

16 changes: 0 additions & 16 deletions nav2_amcl/src/motion_model/CMakeLists.txt

This file was deleted.

24 changes: 0 additions & 24 deletions nav2_amcl/src/pf/CMakeLists.txt

This file was deleted.

15 changes: 0 additions & 15 deletions nav2_amcl/src/sensors/CMakeLists.txt

This file was deleted.

Loading