@@ -21,7 +21,6 @@ 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 )
25
24
26
25
# Get a list of typesupport implementations from valid rmw implementations.
27
26
rosidl_generator_py_get_typesupports (_typesupport_impls )
@@ -166,23 +165,52 @@ set(rosidl_generator_py_suffix "__rosidl_generator_py")
166
165
set (_target_name_lib "${rosidl_generate_interfaces_TARGET}${rosidl_generator_py_suffix} " )
167
166
add_library (${_target_name_lib} SHARED ${_generated_c_files} )
168
167
target_link_libraries (${_target_name_lib}
169
- PRIVATE
170
168
${rosidl_generate_interfaces_TARGET} __rosidl_generator_c )
171
169
add_dependencies (
172
170
${_target_name_lib}
173
171
${rosidl_generate_interfaces_TARGET}${_target_suffix}
174
172
${rosidl_generate_interfaces_TARGET} __rosidl_typesupport_c
175
173
)
174
+
175
+ target_link_libraries (
176
+ ${_target_name_lib}
177
+ ${PythonExtra_LIBRARIES}
178
+ )
176
179
target_include_directories (${_target_name_lib}
177
180
PRIVATE
178
181
${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_c
179
182
${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}
180
189
)
181
190
182
- target_link_libraries (${_target_name_lib} PRIVATE Python3::NumPy Python3::Module )
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 ()
183
211
184
212
rosidl_get_typesupport_target (c_typesupport_target "${rosidl_generate_interfaces_TARGET} " "rosidl_typesupport_c" )
185
- target_link_libraries (${_target_name_lib} PRIVATE ${c_typesupport_target} )
213
+ target_link_libraries (${_target_name_lib} ${c_typesupport_target} )
186
214
187
215
foreach (_typesupport_impl ${_typesupport_impls} )
188
216
find_package (${_typesupport_impl} REQUIRED )
@@ -217,36 +245,35 @@ foreach(_typesupport_impl ${_typesupport_impls})
217
245
endif ()
218
246
target_link_libraries (
219
247
${_target_name}
220
- PRIVATE
221
248
${_target_name_lib}
249
+ ${PythonExtra_LIBRARIES}
222
250
${rosidl_generate_interfaces_TARGET} __${_typesupport_impl}
223
- Python3::Module
224
251
)
225
252
226
253
target_include_directories (${_target_name}
227
254
PUBLIC
228
255
${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_c
229
256
${CMAKE_CURRENT_BINARY_DIR} /rosidl_generator_py
257
+ ${PythonExtra_INCLUDE_DIRS}
230
258
)
231
259
232
- target_link_libraries (${_target_name} PRIVATE ${c_typesupport_target} )
260
+ target_link_libraries (${_target_name} ${c_typesupport_target} )
233
261
234
262
ament_target_dependencies (${_target_name}
235
- PUBLIC
236
263
"rosidl_runtime_c"
237
264
"rosidl_typesupport_c"
238
265
"rosidl_typesupport_interface"
239
266
)
240
267
foreach (_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES} )
241
- ament_target_dependencies (${_target_name} PUBLIC
268
+ ament_target_dependencies (${_target_name}
242
269
${_pkg_name}
243
270
)
244
271
endforeach ()
245
272
246
273
add_dependencies (${_target_name}
247
274
${rosidl_generate_interfaces_TARGET} __${_typesupport_impl}
248
275
)
249
- ament_target_dependencies (${_target_name} PUBLIC
276
+ ament_target_dependencies (${_target_name}
250
277
"rosidl_runtime_c"
251
278
"rosidl_generator_py"
252
279
)
@@ -261,7 +288,7 @@ set(PYTHON_EXECUTABLE ${_PYTHON_EXECUTABLE})
261
288
262
289
# Depend on rosidl_generator_py generated targets from our dependencies
263
290
foreach (_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES} )
264
- target_link_libraries (${_target_name_lib} PRIVATE ${${_pkg_name}_TARGETS${rosidl_generator_py_suffix}} )
291
+ target_link_libraries (${_target_name_lib} ${${_pkg_name}_TARGETS${rosidl_generator_py_suffix}} )
265
292
endforeach ()
266
293
267
294
set_lib_properties ("" )
0 commit comments