Skip to content

Commit ed288b4

Browse files
authored
feat: add autoware_ament_auto_package() macro (#37)
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
1 parent 99d7992 commit ed288b4

3 files changed

Lines changed: 127 additions & 0 deletions

File tree

autoware_cmake/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,45 @@ autoware_package()
1717
1818
ament_auto_add_library(...)
1919
```
20+
21+
### autoware_ament_auto_package.cmake
22+
23+
Use `autoware_ament_auto_package()` as a replacement for `ament_auto_package()` to maintain Autoware's include structure across ROS 2 Humble, Jazzy, and Kilted.
24+
25+
This macro addresses a naming convention conflict between Autoware packages (which use `autoware_<module>` as package names) and Autoware include paths (which use `autoware/<module>/`). Starting with ROS 2 Kilted, `ament_auto_package()` will install headers to `include/${PROJECT_NAME}/`, which would create incorrect paths like `include/autoware_interpolation/autoware/interpolation/`.
26+
27+
#### Why use this?
28+
29+
- **Eliminates deprecation warnings** on ROS 2 Humble and Jazzy
30+
- **Future-proof**: Works with ROS 2 Kilted+ without breaking changes
31+
- **Maintains conventions**: Preserves `autoware/<module>/` include structure
32+
- **Drop-in replacement**: Zero behavior change from `ament_auto_package()`
33+
34+
#### Example
35+
36+
```cmake
37+
cmake_minimum_required(VERSION 3.14)
38+
project(autoware_interpolation)
39+
40+
find_package(autoware_cmake REQUIRED)
41+
autoware_package()
42+
43+
ament_auto_add_library(autoware_interpolation SHARED
44+
src/linear_interpolation.cpp
45+
src/spline_interpolation.cpp
46+
)
47+
48+
if(BUILD_TESTING)
49+
# ... tests ...
50+
endif()
51+
52+
# Use autoware_ament_auto_package() instead of ament_auto_package()
53+
autoware_ament_auto_package()
54+
```
55+
56+
#### Migration from ament_auto_package()
57+
58+
Simply replace `ament_auto_package()` with `autoware_ament_auto_package()` at the end of your `CMakeLists.txt`. All parameters supported by `ament_auto_package()` are also supported:
59+
60+
- `INSTALL_TO_PATH`: Install executables to `bin/` instead of `lib/${PROJECT_NAME}/`
61+
- `INSTALL_TO_SHARE`: Install additional directories to `share/${PROJECT_NAME}/`

autoware_cmake/autoware_cmake-extras.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
# limitations under the License.
1414

1515
include("${autoware_cmake_DIR}/autoware_package.cmake")
16+
include("${autoware_cmake_DIR}/autoware_ament_auto_package.cmake")
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright 2025 The Autoware Contributors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
macro(autoware_ament_auto_package)
16+
# cSpell:ignore ARGN
17+
cmake_parse_arguments(_ARG_AUTOWARE_AMENT_AUTO_PACKAGE
18+
"INSTALL_TO_PATH"
19+
""
20+
"INSTALL_TO_SHARE"
21+
${ARGN})
22+
23+
# Export all found build dependencies which are also run dependencies
24+
set(_run_depends
25+
${${PROJECT_NAME}_BUILD_EXPORT_DEPENDS}
26+
${${PROJECT_NAME}_BUILDTOOL_EXPORT_DEPENDS}
27+
${${PROJECT_NAME}_EXEC_DEPENDS})
28+
foreach(_dep
29+
${${PROJECT_NAME}_FOUND_BUILD_DEPENDS}
30+
${${PROJECT_NAME}_FOUND_BUILDTOOL_DEPENDS})
31+
if(_dep IN_LIST _run_depends)
32+
ament_export_dependencies("${_dep}")
33+
endif()
34+
endforeach()
35+
36+
# Export and install include directory maintaining Autoware structure
37+
# Always use "include" as destination (not "include/${PROJECT_NAME}")
38+
# to maintain Autoware's naming convention across all ROS 2 versions
39+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include")
40+
ament_export_include_directories("include")
41+
install(DIRECTORY include/ DESTINATION include
42+
FILES_MATCHING
43+
PATTERN "*.h"
44+
PATTERN "*.hpp"
45+
PATTERN "*.hh"
46+
PATTERN "*.hxx"
47+
)
48+
endif()
49+
50+
# Export and install all libraries
51+
if(NOT ${PROJECT_NAME}_LIBRARIES STREQUAL "")
52+
ament_export_libraries(${${PROJECT_NAME}_LIBRARIES})
53+
install(
54+
TARGETS ${${PROJECT_NAME}_LIBRARIES}
55+
ARCHIVE DESTINATION lib
56+
LIBRARY DESTINATION lib
57+
RUNTIME DESTINATION bin
58+
)
59+
endif()
60+
61+
# Install executables
62+
if(NOT ${PROJECT_NAME}_EXECUTABLES STREQUAL "")
63+
if(_ARG_AUTOWARE_AMENT_AUTO_PACKAGE_INSTALL_TO_PATH)
64+
set(_executable_destination "bin")
65+
else()
66+
set(_executable_destination "lib/${PROJECT_NAME}")
67+
endif()
68+
install(
69+
TARGETS ${${PROJECT_NAME}_EXECUTABLES}
70+
DESTINATION ${_executable_destination}
71+
)
72+
endif()
73+
74+
# Install additional directories to share
75+
foreach(_dir ${_ARG_AUTOWARE_AMENT_AUTO_PACKAGE_INSTALL_TO_SHARE})
76+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_dir}")
77+
install(DIRECTORY "${_dir}/" DESTINATION "share/${PROJECT_NAME}/${_dir}")
78+
endif()
79+
endforeach()
80+
81+
# Call ament_package with any unparsed arguments
82+
set(_unparsed_args ${_ARG_AUTOWARE_AMENT_AUTO_PACKAGE_UNPARSED_ARGUMENTS})
83+
ament_package(${_unparsed_args})
84+
endmacro()

0 commit comments

Comments
 (0)