1+ cmake_minimum_required (VERSION 3.8 )
2+ project (common_interfaces_cpp)
3+
4+ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
5+ add_compile_options (-Wall -Wextra -Wpedantic )
6+ endif ()
7+
8+ # Define a list of dependencies for easy modularity and future additions
9+ set (ros2_dependencies
10+ rclcpp
11+ nav_msgs
12+ )
13+
14+ # Find ament_cmake (required for the build system itself)
15+ find_package (ament_cmake REQUIRED )
16+
17+ # Loop through the list to find all specified packages automatically
18+ foreach (dependency IN LISTS ros2_dependencies)
19+ find_package (${dependency} REQUIRED )
20+ endforeach ()
21+
22+ # Create the shared library from the source files
23+ add_library (${PROJECT_NAME} SHARED
24+ src/odometry.cpp
25+ )
26+
27+ # Specify the include directories so the compiler finds the .hpp files
28+ target_include_directories (${PROJECT_NAME} PUBLIC
29+ $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /include >
30+ $<INSTALL_INTERFACE :include >
31+ )
32+
33+ # Link all listed dependencies to the library
34+ ament_target_dependencies (${PROJECT_NAME} ${ros2_dependencies} )
35+
36+ # Install the include directory so other packages can do #include
37+ install (DIRECTORY include/
38+ DESTINATION include
39+ )
40+
41+ # Install the library and export the target for downstream usage
42+ install (TARGETS ${PROJECT_NAME}
43+ EXPORT ${PROJECT_NAME}
44+ ARCHIVE DESTINATION lib
45+ LIBRARY DESTINATION lib
46+ RUNTIME DESTINATION bin
47+ )
48+
49+ # Export include directories, targets, and dependencies
50+ ament_export_include_directories (include )
51+ ament_export_targets (${PROJECT_NAME} HAS_LIBRARY_TARGET )
52+ ament_export_dependencies (${ros2_dependencies} )
53+
54+ ament_package ()
0 commit comments