-
Notifications
You must be signed in to change notification settings - Fork 34
/
CMakeLists.txt
160 lines (136 loc) · 5.14 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
cmake_minimum_required(VERSION 3.5)
project(rosidl_typesupport_cpp)
# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
find_package(ament_cmake_ros REQUIRED)
find_package(rcutils REQUIRED)
find_package(rcpputils REQUIRED)
find_package(rosidl_runtime_c REQUIRED)
find_package(rosidl_typesupport_c REQUIRED)
ament_export_dependencies(rcutils)
ament_export_dependencies(rcpputils)
ament_export_dependencies(rosidl_runtime_c)
ament_export_dependencies(rosidl_typesupport_c)
ament_python_install_package(${PROJECT_NAME})
add_library(${PROJECT_NAME}
src/identifier.cpp
src/message_type_support_dispatch.cpp
src/service_type_support_dispatch.cpp)
if(WIN32)
target_compile_definitions(${PROJECT_NAME}
PRIVATE "ROSIDL_TYPESUPPORT_CPP_BUILDING_DLL")
endif()
target_include_directories(${PROJECT_NAME} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
target_link_libraries(${PROJECT_NAME} PUBLIC
rosidl_runtime_c::rosidl_runtime_c
rosidl_typesupport_c::rosidl_typesupport_c)
target_link_libraries(${PROJECT_NAME} PRIVATE
rcpputils::rcpputils
rcutils::rcutils)
# Export old-style CMake variables
ament_export_include_directories("include/${PROJECT_NAME}")
ament_export_libraries(${PROJECT_NAME})
# Export modern CMake targets
ament_export_targets(${PROJECT_NAME})
ament_index_register_resource("rosidl_runtime_packages")
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
find_package(performance_test_fixture REQUIRED)
# Give cppcheck hints about macro definitions coming from outside this package
get_target_property(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS
performance_test_fixture::performance_test_fixture INTERFACE_INCLUDE_DIRECTORIES)
set(TEST_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/test_libs")
add_library(rosidl_typesupport_cpp__test_type_support1
test/test_type_support.cpp)
target_link_libraries(rosidl_typesupport_cpp__test_type_support1 ${PROJECT_NAME})
add_custom_command(TARGET rosidl_typesupport_cpp__test_type_support1 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:rosidl_typesupport_cpp__test_type_support1>
${TEST_LIB_DIR})
# This same library is added a second type with a new name for additional tests
add_library(rosidl_typesupport_cpp__test_type_support2
test/test_type_support.cpp)
target_link_libraries(rosidl_typesupport_cpp__test_type_support2 ${PROJECT_NAME})
add_custom_command(TARGET rosidl_typesupport_cpp__test_type_support2 POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:rosidl_typesupport_cpp__test_type_support2>
${TEST_LIB_DIR})
ament_add_gtest(test_message_type_support test/test_message_type_support_dispatch.cpp
APPEND_ENV
"DYLD_LIBRARY_PATH=${TEST_LIB_DIR}"
"LD_LIBRARY_PATH=${TEST_LIB_DIR}"
"PATH=${TEST_LIB_DIR}")
if(TARGET test_message_type_support)
target_link_libraries(test_message_type_support
${PROJECT_NAME}
rcutils::rcutils
rcpputils::rcpputils
)
target_compile_definitions(test_message_type_support PUBLIC RCUTILS_ENABLE_FAULT_INJECTION)
endif()
ament_add_gtest(test_service_type_support test/test_service_type_support_dispatch.cpp
APPEND_ENV
"DYLD_LIBRARY_PATH=${TEST_LIB_DIR}"
"LD_LIBRARY_PATH=${TEST_LIB_DIR}"
"PATH=${TEST_LIB_DIR}")
if(TARGET test_service_type_support)
target_link_libraries(test_service_type_support
${PROJECT_NAME}
rcutils::rcutils
rcpputils::rcpputils
)
target_compile_definitions(test_service_type_support PUBLIC RCUTILS_ENABLE_FAULT_INJECTION)
endif()
# Test type_support_dispatch throws runtime error when trying to load this "library"
file(GENERATE
OUTPUT
"${TEST_LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}rosidl_typesupport_cpp__test_type_support3${CMAKE_SHARED_LIBRARY_SUFFIX}"
CONTENT "I'm not a shared library, why would you treat me like one?")
add_performance_test(benchmark_type_support_dispatch test/benchmark/benchmark_type_support_dispatch.cpp
APPEND_ENV
"DYLD_LIBRARY_PATH=${TEST_LIB_DIR}"
"LD_LIBRARY_PATH=${TEST_LIB_DIR}"
"PATH=${TEST_LIB_DIR}")
if(TARGET benchmark_type_support_dispatch)
target_link_libraries(benchmark_type_support_dispatch
${PROJECT_NAME}
rcpputils::rcpputils)
endif()
find_package(ament_cmake_pytest REQUIRED)
ament_add_pytest_test(test_cli_extension test/test_cli_extension.py)
endif()
if(BUILD_SHARED_LIBS)
set(${PROJECT_NAME}_LIBRARY_TYPE "SHARED")
else()
set(${PROJECT_NAME}_LIBRARY_TYPE "STATIC")
endif()
ament_package(
CONFIG_EXTRAS "rosidl_typesupport_cpp-extras.cmake.in"
)
install(
PROGRAMS bin/rosidl_typesupport_cpp
DESTINATION lib/rosidl_typesupport_cpp
)
install(
DIRECTORY cmake resource
DESTINATION share/${PROJECT_NAME}
)
install(
DIRECTORY include/
DESTINATION include/${PROJECT_NAME}
)
install(
TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)