Skip to content

Commit 1e520ff

Browse files
authored
Merge pull request #81 from lf-lang/fix-ros2-cpp-build
Fix ROS2 C++ build with proper ament CMake exports
2 parents d568ddd + 09b9058 commit 1e520ff

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ endif()
99

1010
project(${LIB_TARGET} LANGUAGES CXX VERSION 0.0.1)
1111

12+
if (NOT DEFINED LF_REACTOR_CPP_SUFFIX)
13+
find_package(ament_cmake QUIET)
14+
if(ament_cmake_FOUND)
15+
set(REACTOR_CPP_USE_AMENT ON)
16+
endif()
17+
endif()
18+
1219
# require C++17
1320
set(CMAKE_CXX_STANDARD 17)
1421
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -71,3 +78,17 @@ if (DEFINED LF_REACTOR_CPP_SUFFIX)
7178
else()
7279
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
7380
endif()
81+
82+
if (REACTOR_CPP_USE_AMENT)
83+
# Install the export file - must be in root CMakeLists.txt for ament compatibility
84+
install(EXPORT ${LIB_TARGET} DESTINATION share/${LIB_TARGET}/cmake NAMESPACE ${LIB_TARGET}::)
85+
ament_export_targets(${LIB_TARGET} HAS_LIBRARY_TARGET)
86+
ament_export_include_directories(include)
87+
ament_export_libraries(${LIB_TARGET})
88+
ament_package()
89+
else()
90+
# For non-ament builds, install export file from here
91+
if(REACTOR_CPP_INSTALL)
92+
install(EXPORT ${LIB_TARGET} DESTINATION share/${LIB_TARGET}/cmake)
93+
endif()
94+
endif()

lib/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ if(REACTOR_CPP_INSTALL)
6161
install(FILES "${PROJECT_BINARY_DIR}/include/reactor-cpp/config.hh" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/reactor-cpp")
6262
endif()
6363

64-
install(TARGETS ${LIB_TARGET} EXPORT ${LIB_TARGET}Config
64+
install(TARGETS ${LIB_TARGET} EXPORT ${LIB_TARGET}
6565
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" OPTIONAL
6666
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" OPTIONAL
6767
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" OPTIONAL)
68-
69-
install(EXPORT ${LIB_TARGET}Config DESTINATION share/${LIB_TARGET}/cmake)
70-
71-
export(TARGETS ${PROJECT_NAME} FILE ${LIB_TARGET}Config.cmake)
68+
# Note: install(EXPORT ...) moved to root CMakeLists.txt for ament compatibility
7269
endif()

package.xml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,8 @@
66
<description>A C++ reactor runtime</description>
77
<maintainer email="christian.menard@tu-dresden.de">user</maintainer>
88
<license>ISC License</license>
9+
<buildtool_depend>ament_cmake</buildtool_depend>
910
<export>
10-
<build_type>cmake</build_type>
11-
</export>
12-
</package>
13-
<package format="3">
14-
<name>reactor-cpp-foo</name>
15-
<version>0.0.0</version>
16-
<description>A C++ reactor runtime</description>
17-
<maintainer email="christian.menard@tu-dresden.de">user</maintainer>
18-
<license>ISC License</license>
19-
<export>
20-
<build_type>cmake</build_type>
11+
<build_type>ament_cmake</build_type>
2112
</export>
2213
</package>

0 commit comments

Comments
 (0)