Skip to content

Commit 9c15e12

Browse files
committed
Improve cmakelists
Signed-off-by: Alberto Tudela <[email protected]>
1 parent 0e55393 commit 9c15e12

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

CMakeLists.txt

+38-30
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
2626
endif()
2727

2828
option(COVERAGE_ENABLED "Enable code coverage" FALSE)
29+
2930
if(COVERAGE_ENABLED)
3031
add_compile_options(--coverage)
3132
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
@@ -60,40 +61,42 @@ find_package(slg_msgs REQUIRED) # formerly simple_laser_geometry
6061
# ##########
6162
# # Build ##
6263
# ##########
63-
# # Specify additional locations of header files
64-
# # Your package locations should be listed before other locations
65-
include_directories(
66-
include
67-
)
68-
6964
set(source
7065
src/segmentation/jump_distance.cpp
7166
src/segmentation/jump_distance_merge.cpp
7267
src/parameter_handler.cpp
7368
src/laser_segmentation.cpp
7469
)
7570

76-
set(dependencies
77-
rclcpp
78-
rclcpp_lifecycle
79-
rclcpp_components
80-
std_msgs
81-
sensor_msgs
82-
visualization_msgs
83-
slg_msgs
84-
)
71+
set(library_name ${PROJECT_NAME}_core)
8572

86-
set(library_name ${PROJECT_NAME}_component)
73+
# Library node
74+
add_library(${library_name} SHARED ${source})
75+
target_include_directories(${library_name}
76+
PUBLIC
77+
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
78+
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
79+
target_link_libraries(${library_name} PUBLIC
80+
rclcpp::rclcpp
81+
rclcpp_lifecycle::rclcpp_lifecycle
82+
${rclcpp_components_TARGETS}
83+
${std_msgs_TARGETS}
84+
${sensor_msgs_TARGETS}
85+
${visualization_msgs_TARGETS}
86+
${slg_msgs_TARGETS}
87+
)
8788

8889
# Add executables
8990
add_executable(${PROJECT_NAME} src/main.cpp)
90-
ament_target_dependencies(${PROJECT_NAME} ${dependencies})
91-
target_link_libraries(${PROJECT_NAME} ${library_name})
92-
93-
# Library node
94-
add_library(${library_name} SHARED ${source})
95-
ament_target_dependencies(${library_name} ${dependencies})
96-
target_link_libraries(${library_name})
91+
target_include_directories(${PROJECT_NAME}
92+
PUBLIC
93+
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>"
94+
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
95+
target_link_libraries(${PROJECT_NAME} PUBLIC
96+
rclcpp::rclcpp
97+
rclcpp_lifecycle::rclcpp_lifecycle
98+
${library_name}
99+
)
97100

98101
rclcpp_components_register_nodes(${library_name} "laser_segmentation::LaserSegmentation")
99102

@@ -110,11 +113,8 @@ install(TARGETS ${PROJECT_NAME}
110113
RUNTIME DESTINATION lib/${PROJECT_NAME}
111114
)
112115

113-
install(DIRECTORY include/${PROJECT_NAME}/
116+
install(DIRECTORY include/
114117
DESTINATION include/${PROJECT_NAME}
115-
FILES_MATCHING PATTERN "*.hpp"
116-
117-
# PATTERN ".svn" EXCLUDE
118118
)
119119

120120
install(DIRECTORY launch params
@@ -136,7 +136,15 @@ endif()
136136
# ##################################
137137
# # ament specific configuration ##
138138
# ##################################
139-
ament_export_include_directories(include)
140-
ament_export_libraries(${PROJECT_NAME}_component)
141-
ament_export_dependencies(${dependencies})
139+
ament_export_include_directories(include/${PROJECT_NAME})
140+
ament_export_libraries(${library_name})
141+
ament_export_dependencies(
142+
rclcpp
143+
rclcpp_lifecycle
144+
rclcpp_components
145+
std_msgs
146+
sensor_msgs
147+
visualization_msgs
148+
slg_msgs
149+
)
142150
ament_package()

0 commit comments

Comments
 (0)