@@ -21,6 +21,7 @@ find_package(PythonInterp 3.6 REQUIRED)
21
21
22
22
find_package (python_cmake_module REQUIRED)
23
23
find_package (PythonExtra MODULE REQUIRED)
24
+ find_package (Python3 REQUIRED COMPONENTS Development NumPy)
24
25
25
26
# Get a list of typesupport implementations from valid rmw implementations.
26
27
rosidl_generator_py_get_typesupports(_typesupport_impls)
@@ -165,52 +166,23 @@ set(rosidl_generator_py_suffix "__rosidl_generator_py")
165
166
set (_target_name_lib "${rosidl_generate_interfaces_TARGET}${rosidl_generator_py_suffix} " )
166
167
add_library (${_target_name_lib} SHARED ${_generated_c_files} )
167
168
target_link_libraries (${_target_name_lib}
169
+ PRIVATE
168
170
${rosidl_generate_interfaces_TARGET} __rosidl_generator_c)
169
171
add_dependencies (
170
172
${_target_name_lib}
171
173
${rosidl_generate_interfaces_TARGET}${_target_suffix}
172
174
${rosidl_generate_interfaces_TARGET} __rosidl_typesupport_c
173
175
)
174
-
175
- target_link_libraries (
176
- ${_target_name_lib}
177
- ${PythonExtra_LIBRARIES}
178
- )
179
176
target_include_directories (${_target_name_lib}
180
177
PRIVATE
181
178
${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_c
182
179
${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_py
183
- ${PythonExtra_INCLUDE_DIRS}
184
- )
185
-
186
- # Check if numpy is in the include path
187
- find_file (_numpy_h numpy/numpyconfig.h
188
- PATHS ${PythonExtra_INCLUDE_DIRS}
189
180
)
190
181
191
- if (APPLE OR WIN32 OR NOT _numpy_h)
192
- # add include directory for numpy headers
193
- set (_python_code
194
- "import numpy"
195
- "print(numpy.get_include())"
196
- )
197
- execute_process (
198
- COMMAND "${PYTHON_EXECUTABLE} " "-c" "${_python_code} "
199
- OUTPUT_VARIABLE _output
200
- RESULT_VARIABLE _result
201
- OUTPUT_STRIP_TRAILING_WHITESPACE
202
- )
203
- if (NOT _result EQUAL 0)
204
- message (FATAL_ERROR
205
- "execute_process(${PYTHON_EXECUTABLE} -c '${_python_code} ') returned "
206
- "error code ${_result} " )
207
- endif ()
208
- message (STATUS "Using numpy include directory: ${_output} " )
209
- target_include_directories (${_target_name_lib} PUBLIC "${_output} " )
210
- endif ()
182
+ target_link_libraries (${_target_name_lib} PRIVATE Python3::NumPy Python3::Module)
211
183
212
184
rosidl_get_typesupport_target(c_typesupport_target "${rosidl_generate_interfaces_TARGET} " "rosidl_typesupport_c" )
213
- target_link_libraries (${_target_name_lib} ${c_typesupport_target} )
185
+ target_link_libraries (${_target_name_lib} PRIVATE ${c_typesupport_target} )
214
186
215
187
foreach (_typesupport_impl ${_typesupport_impls} )
216
188
find_package (${_typesupport_impl} REQUIRED)
@@ -245,35 +217,36 @@ foreach(_typesupport_impl ${_typesupport_impls})
245
217
endif ()
246
218
target_link_libraries (
247
219
${_target_name}
220
+ PRIVATE
248
221
${_target_name_lib}
249
- ${PythonExtra_LIBRARIES}
250
222
${rosidl_generate_interfaces_TARGET} __${_typesupport_impl}
223
+ Python3::Module
251
224
)
252
225
253
226
target_include_directories (${_target_name}
254
227
PUBLIC
255
228
${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_c
256
229
${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_py
257
- ${PythonExtra_INCLUDE_DIRS}
258
230
)
259
231
260
- target_link_libraries (${_target_name} ${c_typesupport_target} )
232
+ target_link_libraries (${_target_name} PRIVATE ${c_typesupport_target} )
261
233
262
234
ament_target_dependencies(${_target_name}
235
+ PUBLIC
263
236
"rosidl_runtime_c"
264
237
"rosidl_typesupport_c"
265
238
"rosidl_typesupport_interface"
266
239
)
267
240
foreach (_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES} )
268
- ament_target_dependencies(${_target_name}
241
+ ament_target_dependencies(${_target_name} PUBLIC
269
242
${_pkg_name}
270
243
)
271
244
endforeach ()
272
245
273
246
add_dependencies (${_target_name}
274
247
${rosidl_generate_interfaces_TARGET} __${_typesupport_impl}
275
248
)
276
- ament_target_dependencies(${_target_name}
249
+ ament_target_dependencies(${_target_name} PUBLIC
277
250
"rosidl_runtime_c"
278
251
"rosidl_generator_py"
279
252
)
@@ -288,7 +261,7 @@ set(PYTHON_EXECUTABLE ${_PYTHON_EXECUTABLE})
288
261
289
262
# Depend on rosidl_generator_py generated targets from our dependencies
290
263
foreach (_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES} )
291
- target_link_libraries (${_target_name_lib} ${${_pkg_name} _TARGETS${rosidl_generator_py_suffix} })
264
+ target_link_libraries (${_target_name_lib} PRIVATE ${${_pkg_name} _TARGETS${rosidl_generator_py_suffix} })
292
265
endforeach ()
293
266
294
267
set_lib_properties("" )
0 commit comments