-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathros-noetic-jsk-recognition-utils.patch
705 lines (686 loc) · 27.3 KB
/
ros-noetic-jsk-recognition-utils.patch
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 55c405fd0..a53d0f349 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -39,7 +39,8 @@ configure_file(
# ------------------------------------------------------------------------------------
# download and install font data
-add_custom_target(${PROJECT_NAME}_install_font_data ALL COMMAND python$ENV{ROS_PYTHON_VERSION} ${PROJECT_SOURCE_DIR}/scripts/install_font_data.py)
+find_package (Python COMPONENTS Interpreter Development NumPy)
+add_custom_target(${PROJECT_NAME}_install_font_data ALL COMMAND ${Python_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/install_font_data.py)
catkin_python_setup()
@@ -62,6 +63,7 @@ add_subdirectory(python/${PROJECT_NAME})
find_package(OpenCV REQUIRED core imgproc)
find_package(PCL REQUIRED)
+find_package(GLEW REQUIRED)
find_package(PkgConfig)
pkg_check_modules(yaml_cpp yaml-cpp REQUIRED)
IF(${yaml_cpp_VERSION} VERSION_LESS "0.5.0")
@@ -72,11 +74,10 @@ if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z defs")
endif()
include_directories(
- include ${catkin_INCLUDE_DIRS}
+ include ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS}
)
-link_libraries(${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${PCL_LIBRARIES} yaml-cpp)
-add_library(jsk_recognition_utils SHARED
+add_library(jsk_recognition_utils
src/grid_index.cpp
src/grid_map.cpp
src/grid_line.cpp
@@ -102,6 +103,8 @@ add_library(jsk_recognition_utils SHARED
src/time_util.cpp
)
+target_link_libraries(jsk_recognition_utils ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} ${PCL_LIBRARIES} ${yaml_cpp_LIBRARIES} ${GLEW_LIBRARIES})
+
if (CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
if("$ENV{ROS_DISTRO}" STRGREATER "indigo") # kinetic and later uses qt5
diff --git a/cmake/FindCython.cmake b/cmake/FindCython.cmake
index f44f1f707..d7fb4205f 100644
--- a/cmake/FindCython.cmake
+++ b/cmake/FindCython.cmake
@@ -24,9 +24,9 @@
# Use the Cython executable that lives next to the Python executable
# if it is a local installation.
-find_package( PythonInterp )
-if( PYTHONINTERP_FOUND )
- get_filename_component( _python_path ${PYTHON_EXECUTABLE} PATH )
+find_package (Python COMPONENTS Interpreter Development NumPy)
+if( Python_Interpreter_FOUND )
+ get_filename_component( _python_path ${Python_EXECUTABLE} PATH )
find_program( CYTHON_EXECUTABLE
NAMES cython cython.bat cython3
HINTS ${_python_path}
diff --git a/cmake/UseCython.cmake b/cmake/UseCython.cmake
index f432c890c..0a11631e5 100644
--- a/cmake/UseCython.cmake
+++ b/cmake/UseCython.cmake
@@ -1,51 +1,83 @@
-# Define a function to create Cython modules.
+#.rst:
#
-# For more information on the Cython project, see http://cython.org/.
-# "Cython is a language that makes writing C extensions for the Python language
-# as easy as Python itself."
+# The following functions are defined:
#
-# This file defines a CMake function to build a Cython Python module.
-# To use it, first include this file.
+# .. cmake:command:: add_cython_target
#
-# include( UseCython )
+# Create a custom rule to generate the source code for a Python extension module
+# using cython.
#
-# Then call cython_add_module to create a module.
+# add_cython_target(<Name> [<CythonInput>]
+# [EMBED_MAIN]
+# [C | CXX]
+# [PY2 | PY3]
+# [OUTPUT_VAR <OutputVar>])
#
-# cython_add_module( <module_name> <src1> <src2> ... <srcN> )
+# ``<Name>`` is the name of the new target, and ``<CythonInput>``
+# is the path to a cython source file. Note that, despite the name, no new
+# targets are created by this function. Instead, see ``OUTPUT_VAR`` for
+# retrieving the path to the generated source for subsequent targets.
#
-# To create a standalone executable, the function
+# If only ``<Name>`` is provided, and it ends in the ".pyx" extension, then it
+# is assumed to be the ``<CythonInput>``. The name of the input without the
+# extension is used as the target name. If only ``<Name>`` is provided, and it
+# does not end in the ".pyx" extension, then the ``<CythonInput>`` is assumed to
+# be ``<Name>.pyx``.
#
-# cython_add_standalone_executable( <executable_name> [MAIN_MODULE src1] <src1> <src2> ... <srcN> )
+# The Cython include search path is amended with any entries found in the
+# ``INCLUDE_DIRECTORIES`` property of the directory containing the
+# ``<CythonInput>`` file. Use ``include_directories`` to add to the Cython
+# include search path.
#
-# To avoid dependence on Python, set the PYTHON_LIBRARY cache variable to point
-# to a static library. If a MAIN_MODULE source is specified,
-# the "if __name__ == '__main__':" from that module is used as the C main() method
-# for the executable. If MAIN_MODULE, the source with the same basename as
-# <executable_name> is assumed to be the MAIN_MODULE.
+# Options:
#
-# Where <module_name> is the name of the resulting Python module and
-# <src1> <src2> ... are source files to be compiled into the module, e.g. *.pyx,
-# *.py, *.c, *.cxx, etc. A CMake target is created with name <module_name>. This can
-# be used for target_link_libraries(), etc.
+# ``EMBED_MAIN``
+# Embed a main() function in the generated output (for stand-alone
+# applications that initialize their own Python runtime).
#
-# The sample paths set with the CMake include_directories() command will be used
-# for include directories to search for *.pxd when running the Cython complire.
+# ``C | CXX``
+# Force the generation of either a C or C++ file. By default, a C file is
+# generated, unless the C language is not enabled for the project; in this
+# case, a C++ file is generated by default.
#
-# Cache variables that effect the behavior include:
+# ``PY2 | PY3``
+# Force compilation using either Python-2 or Python-3 syntax and code
+# semantics. By default, Python-2 syntax and semantics are used if the major
+# version of Python found is 2. Otherwise, Python-3 syntax and semantics are
+# used.
#
-# CYTHON_ANNOTATE
-# CYTHON_NO_DOCSTRINGS
-# CYTHON_FLAGS
+# ``OUTPUT_VAR <OutputVar>``
+# Set the variable ``<OutputVar>`` in the parent scope to the path to the
+# generated source file. By default, ``<Name>`` is used as the output
+# variable name.
#
-# Source file properties that effect the build process are
+# Defined variables:
#
-# CYTHON_IS_CXX
+# ``<OutputVar>``
+# The path of the generated source file.
#
-# If this is set of a *.pyx file with CMake set_source_files_properties()
-# command, the file will be compiled as a C++ file.
+# Cache variables that affect the behavior include:
+#
+# ``CYTHON_ANNOTATE``
+# Whether to create an annotated .html file when compiling.
+#
+# ``CYTHON_FLAGS``
+# Additional flags to pass to the Cython compiler.
+#
+# Example usage
+# ^^^^^^^^^^^^^
+#
+# .. code-block:: cmake
+#
+# find_package(Cython)
+#
+# # Note: In this case, either one of these arguments may be omitted; their
+# # value would have been inferred from that of the other.
+# add_cython_target(cy_code cy_code.pyx)
+#
+# add_library(cy_code MODULE ${cy_code})
+# target_link_libraries(cy_code ...)
#
-# See also FindCython.cmake
-
#=============================================================================
# Copyright 2011 Kitware, Inc.
#
@@ -63,225 +95,290 @@
#=============================================================================
# Configuration options.
-set( CYTHON_ANNOTATE OFF
- CACHE BOOL "Create an annotated .html file when compiling *.pyx." )
-set( CYTHON_NO_DOCSTRINGS OFF
- CACHE BOOL "Strip docstrings from the compiled module." )
-set( CYTHON_FLAGS "" CACHE STRING
- "Extra flags to the cython compiler." )
-mark_as_advanced( CYTHON_ANNOTATE CYTHON_NO_DOCSTRINGS CYTHON_FLAGS )
-
-find_package( Cython REQUIRED )
-find_package( PythonLibs REQUIRED )
-
-set( CYTHON_CXX_EXTENSION "cxx" )
-set( CYTHON_C_EXTENSION "c" )
-
-# Create a *.c or *.cxx file from a *.pyx file.
-# Input the generated file basename. The generate file will put into the variable
-# placed in the "generated_file" argument. Finally all the *.py and *.pyx files.
-function( compile_pyx _name generated_file )
- # Default to assuming all files are C.
- set( cxx_arg "" )
- set( extension ${CYTHON_C_EXTENSION} )
- set( pyx_lang "C" )
- set( comment "Compiling Cython C source for ${_name}..." )
-
- set( cython_include_directories "" )
- set( pxd_dependencies "" )
- set( c_header_dependencies "" )
- set( pyx_locations "" )
-
- foreach( pyx_file ${ARGN} )
- get_filename_component( pyx_file_basename "${pyx_file}" NAME_WE )
-
- # Determine if it is a C or C++ file.
- get_source_file_property( property_is_cxx ${pyx_file} CYTHON_IS_CXX )
- if( ${property_is_cxx} )
- set( cxx_arg "--cplus" )
- set( extension ${CYTHON_CXX_EXTENSION} )
- set( pyx_lang "CXX" )
- set( comment "Compiling Cython CXX source for ${_name}..." )
- endif()
+set(CYTHON_ANNOTATE OFF
+ CACHE BOOL "Create an annotated .html file when compiling *.pyx.")
+
+set(CYTHON_FLAGS "" CACHE STRING
+ "Extra flags to the cython compiler.")
+mark_as_advanced(CYTHON_ANNOTATE CYTHON_FLAGS)
+
+set(CYTHON_CXX_EXTENSION "cxx")
+set(CYTHON_C_EXTENSION "c")
+cmake_policy(SET CMP0057 NEW)
+
+get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
+
+function(add_cython_target _name)
+ set(options EMBED_MAIN C CXX PY2 PY3)
+ set(options1 OUTPUT_VAR)
+ cmake_parse_arguments(_args "${options}" "${options1}" "" ${ARGN})
+
+ list(GET _args_UNPARSED_ARGUMENTS 0 _arg0)
+
+ # if provided, use _arg0 as the input file path
+ if(_arg0)
+ set(_source_file ${_arg0})
+
+ # otherwise, must determine source file from name, or vice versa
+ else()
+ get_filename_component(_name_ext "${_name}" EXT)
+
+ # if extension provided, _name is the source file
+ if(_name_ext)
+ set(_source_file ${_name})
+ get_filename_component(_name "${_source_file}" NAME_WE)
- # Get the include directories.
- get_source_file_property( pyx_location ${pyx_file} LOCATION )
- get_filename_component( pyx_path ${pyx_location} PATH )
- get_directory_property( cmake_include_directories DIRECTORY ${pyx_path} INCLUDE_DIRECTORIES )
- list( APPEND cython_include_directories ${cmake_include_directories} )
- list( APPEND pyx_locations "${pyx_location}" )
-
- # Determine dependencies.
- # Add the pxd file will the same name as the given pyx file.
- unset( corresponding_pxd_file CACHE )
- find_file( corresponding_pxd_file ${pyx_file_basename}.pxd
- PATHS "${pyx_path}" ${cmake_include_directories}
- NO_DEFAULT_PATH )
- if( corresponding_pxd_file )
- list( APPEND pxd_dependencies "${corresponding_pxd_file}" )
+ # otherwise, assume the source file is ${_name}.pyx
+ else()
+ set(_source_file ${_name}.pyx)
endif()
+ endif()
- # pxd files to check for additional dependencies.
- set( pxds_to_check "${pyx_file}" "${pxd_dependencies}" )
- set( pxds_checked "" )
- set( number_pxds_to_check 1 )
- while( ${number_pxds_to_check} GREATER 0 )
- foreach( pxd ${pxds_to_check} )
- list( APPEND pxds_checked "${pxd}" )
- list( REMOVE_ITEM pxds_to_check "${pxd}" )
-
- # check for C header dependencies
- file( STRINGS "${pxd}" extern_from_statements
- REGEX "cdef[ ]+extern[ ]+from.*$" )
- foreach( statement ${extern_from_statements} )
- # Had trouble getting the quote in the regex
- string( REGEX REPLACE "cdef[ ]+extern[ ]+from[ ]+[\"]([^\"]+)[\"].*" "\\1" header "${statement}" )
- unset( header_location CACHE )
- find_file( header_location ${header} PATHS ${cmake_include_directories} )
- if( header_location )
- list( FIND c_header_dependencies "${header_location}" header_idx )
- if( ${header_idx} LESS 0 )
- list( APPEND c_header_dependencies "${header_location}" )
- endif()
- endif()
- endforeach()
-
- # check for pxd dependencies
-
- # Look for cimport statements.
- set( module_dependencies "" )
- file( STRINGS "${pxd}" cimport_statements REGEX cimport )
- foreach( statement ${cimport_statements} )
- if( ${statement} MATCHES from )
- string( REGEX REPLACE "from[ ]+([^ ]+).*" "\\1" module "${statement}" )
- else()
- string( REGEX REPLACE "cimport[ ]+([^ ]+).*" "\\1" module "${statement}" )
- endif()
- list( APPEND module_dependencies ${module} )
- endforeach()
- list( REMOVE_DUPLICATES module_dependencies )
- # Add the module to the files to check, if appropriate.
- foreach( module ${module_dependencies} )
- unset( pxd_location CACHE )
- find_file( pxd_location ${module}.pxd
- PATHS "${pyx_path}" ${cmake_include_directories} NO_DEFAULT_PATH )
- if( pxd_location )
- list( FIND pxds_checked ${pxd_location} pxd_idx )
- if( ${pxd_idx} LESS 0 )
- list( FIND pxds_to_check ${pxd_location} pxd_idx )
- if( ${pxd_idx} LESS 0 )
- list( APPEND pxds_to_check ${pxd_location} )
- list( APPEND pxd_dependencies ${pxd_location} )
- endif() # if it is not already going to be checked
- endif() # if it has not already been checked
- endif() # if pxd file can be found
- endforeach() # for each module dependency discovered
- endforeach() # for each pxd file to check
- list( LENGTH pxds_to_check number_pxds_to_check )
- endwhile()
- endforeach() # pyx_file
+ set(_embed_main FALSE)
- # Set additional flags.
- if( CYTHON_ANNOTATE )
- set( annotate_arg "--annotate" )
+ if("C" IN_LIST languages)
+ set(_output_syntax "C")
+ elseif("CXX" IN_LIST languages)
+ set(_output_syntax "CXX")
+ else()
+ message(FATAL_ERROR "Either C or CXX must be enabled to use Cython")
endif()
- if( CYTHON_NO_DOCSTRINGS )
- set( no_docstrings_arg "--no-docstrings" )
+ if(_args_EMBED_MAIN)
+ set(_embed_main TRUE)
endif()
- if( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR
- "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" )
- set( cython_debug_arg "--gdb" )
+ if(_args_C)
+ set(_output_syntax "C")
endif()
- # Include directory arguments.
- list( REMOVE_DUPLICATES cython_include_directories )
- set( include_directory_arg "" )
- foreach( _include_dir ${cython_include_directories} )
- set( include_directory_arg ${include_directory_arg} "-I" "${_include_dir}" )
- endforeach()
+ if(_args_CXX)
+ set(_output_syntax "CXX")
+ endif()
- # Determining generated file name.
- set( _generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${extension}" )
- set_source_files_properties( ${_generated_file} PROPERTIES GENERATED TRUE )
- set( ${generated_file} ${_generated_file} PARENT_SCOPE )
+ # Doesn't select an input syntax - Cython
+ # defaults to 2 for Cython 2 and 3 for Cython 3
+ set(_input_syntax "default")
- list( REMOVE_DUPLICATES pxd_dependencies )
- list( REMOVE_DUPLICATES c_header_dependencies )
+ if(_args_PY2)
+ set(_input_syntax "PY2")
+ endif()
- # Add the command to run the compiler.
- add_custom_command( OUTPUT ${_generated_file}
- COMMAND ${CYTHON_EXECUTABLE}
- ARGS ${cxx_arg} ${include_directory_arg}
- ${annotate_arg} ${no_docstrings_arg} ${cython_debug_arg} ${CYTHON_FLAGS}
- --output-file ${_generated_file} ${pyx_locations}
- DEPENDS ${pyx_locations} ${pxd_dependencies}
- IMPLICIT_DEPENDS ${pyx_lang} ${c_header_dependencies}
- COMMENT ${comment}
- )
+ if(_args_PY3)
+ set(_input_syntax "PY3")
+ endif()
- # Remove their visibility to the user.
- set( corresponding_pxd_file "" CACHE INTERNAL "" )
- set( header_location "" CACHE INTERNAL "" )
- set( pxd_location "" CACHE INTERNAL "" )
-endfunction()
-
-# cython_add_module( <name> src1 src2 ... srcN )
-# Build the Cython Python module.
-function( cython_add_module _name )
- set( pyx_module_sources "" )
- set( other_module_sources "" )
- foreach( _file ${ARGN} )
- if( ${_file} MATCHES ".*\\.py[x]?$" )
- list( APPEND pyx_module_sources ${_file} )
- else()
- list( APPEND other_module_sources ${_file} )
- endif()
- endforeach()
- compile_pyx( ${_name} generated_file ${pyx_module_sources} )
- include_directories( ${PYTHON_INCLUDE_DIRS} )
- python_add_module( ${_name} ${generated_file} ${other_module_sources} )
- if( APPLE )
- set_target_properties( ${_name} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup" )
- else()
- target_link_libraries( ${_name} ${PYTHON_LIBRARIES} )
+ set(embed_arg "")
+ if(_embed_main)
+ set(embed_arg "--embed")
endif()
-endfunction()
-
-include( CMakeParseArguments )
-# cython_add_standalone_executable( _name [MAIN_MODULE src3.py] src1 src2 ... srcN )
-# Creates a standalone executable the given sources.
-function( cython_add_standalone_executable _name )
- set( pyx_module_sources "" )
- set( other_module_sources "" )
- set( main_module "" )
- cmake_parse_arguments( cython_arguments "" "MAIN_MODULE" "" ${ARGN} )
- include_directories( ${PYTHON_INCLUDE_DIRS} )
- foreach( _file ${cython_arguments_UNPARSED_ARGUMENTS} )
- if( ${_file} MATCHES ".*\\.py[x]?$" )
- get_filename_component( _file_we ${_file} NAME_WE )
- if( "${_file_we}" STREQUAL "${_name}" )
- set( main_module "${_file}" )
- elseif( NOT "${_file}" STREQUAL "${cython_arguments_MAIN_MODULE}" )
- set( PYTHON_MODULE_${_file_we}_static_BUILD_SHARED OFF )
- compile_pyx( "${_file_we}_static" generated_file "${_file}" )
- list( APPEND pyx_module_sources "${generated_file}" )
- endif()
- else()
- list( APPEND other_module_sources ${_file} )
- endif()
- endforeach()
- if( cython_arguments_MAIN_MODULE )
- set( main_module ${cython_arguments_MAIN_MODULE} )
+ set(cxx_arg "")
+ set(extension "c")
+ if(_output_syntax STREQUAL "CXX")
+ set(cxx_arg "--cplus")
+ set(extension "cxx")
+ endif()
+
+ set(py_version_arg "")
+ if(_input_syntax STREQUAL "PY2")
+ set(py_version_arg "-2")
+ elseif(_input_syntax STREQUAL "PY3")
+ set(py_version_arg "-3")
+ endif()
+
+ set(generated_file "${CMAKE_CURRENT_BINARY_DIR}/${_name}.${extension}")
+ set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE)
+
+ set(_output_var ${_name})
+ if(_args_OUTPUT_VAR)
+ set(_output_var ${_args_OUTPUT_VAR})
+ endif()
+ set(${_output_var} ${generated_file} PARENT_SCOPE)
+
+ file(RELATIVE_PATH generated_file_relative
+ ${CMAKE_BINARY_DIR} ${generated_file})
+
+ set(comment "Generating ${_output_syntax} source ${generated_file_relative}")
+ set(cython_include_directories "")
+ set(pxd_dependencies "")
+ set(c_header_dependencies "")
+
+ # Get the include directories.
+ get_directory_property(cmake_include_directories
+ DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
+ INCLUDE_DIRECTORIES)
+ list(APPEND cython_include_directories ${cmake_include_directories})
+
+ # Determine dependencies.
+ # Add the pxd file with the same basename as the given pyx file.
+ get_source_file_property(pyx_location ${_source_file} LOCATION)
+ get_filename_component(pyx_path ${pyx_location} PATH)
+ get_filename_component(pyx_file_basename ${_source_file} NAME_WE)
+ unset(corresponding_pxd_file CACHE)
+ find_file(corresponding_pxd_file ${pyx_file_basename}.pxd
+ PATHS "${pyx_path}" ${cmake_include_directories}
+ NO_DEFAULT_PATH)
+ if(corresponding_pxd_file)
+ list(APPEND pxd_dependencies "${corresponding_pxd_file}")
+ endif()
+
+ # pxd files to check for additional dependencies
+ set(pxds_to_check "${_source_file}" "${pxd_dependencies}")
+ set(pxds_checked "")
+ set(number_pxds_to_check 1)
+ while(number_pxds_to_check GREATER 0)
+ foreach(pxd ${pxds_to_check})
+ list(APPEND pxds_checked "${pxd}")
+ list(REMOVE_ITEM pxds_to_check "${pxd}")
+
+ # look for C headers
+ file(STRINGS "${pxd}" extern_from_statements
+ REGEX "cdef[ ]+extern[ ]+from.*$")
+ foreach(statement ${extern_from_statements})
+ # Had trouble getting the quote in the regex
+ string(REGEX REPLACE
+ "cdef[ ]+extern[ ]+from[ ]+[\"]([^\"]+)[\"].*" "\\1"
+ header "${statement}")
+ unset(header_location CACHE)
+ find_file(header_location ${header} PATHS ${cmake_include_directories})
+ if(header_location)
+ list(FIND c_header_dependencies "${header_location}" header_idx)
+ if(${header_idx} LESS 0)
+ list(APPEND c_header_dependencies "${header_location}")
+ endif()
+ endif()
+ endforeach()
+
+ # check for pxd dependencies
+ # Look for cimport statements.
+ set(module_dependencies "")
+ file(STRINGS "${pxd}" cimport_statements REGEX cimport)
+ foreach(statement ${cimport_statements})
+ if(${statement} MATCHES from)
+ string(REGEX REPLACE
+ "from[ ]+([^ ]+).*" "\\1"
+ module "${statement}")
+ else()
+ string(REGEX REPLACE
+ "cimport[ ]+([^ ]+).*" "\\1"
+ module "${statement}")
+ endif()
+ list(APPEND module_dependencies ${module})
+ endforeach()
+
+ # check for pxi dependencies
+ # Look for include statements.
+ set(include_dependencies "")
+ file(STRINGS "${pxd}" include_statements REGEX include)
+ foreach(statement ${include_statements})
+ string(REGEX REPLACE
+ "include[ ]+[\"]([^\"]+)[\"].*" "\\1"
+ module "${statement}")
+ list(APPEND include_dependencies ${module})
+ endforeach()
+
+ list(REMOVE_DUPLICATES module_dependencies)
+ list(REMOVE_DUPLICATES include_dependencies)
+
+ # Add modules to the files to check, if appropriate.
+ foreach(module ${module_dependencies})
+ unset(pxd_location CACHE)
+ find_file(pxd_location ${module}.pxd
+ PATHS "${pyx_path}" ${cmake_include_directories}
+ NO_DEFAULT_PATH)
+ if(pxd_location)
+ list(FIND pxds_checked ${pxd_location} pxd_idx)
+ if(${pxd_idx} LESS 0)
+ list(FIND pxds_to_check ${pxd_location} pxd_idx)
+ if(${pxd_idx} LESS 0)
+ list(APPEND pxds_to_check ${pxd_location})
+ list(APPEND pxd_dependencies ${pxd_location})
+ endif() # if it is not already going to be checked
+ endif() # if it has not already been checked
+ endif() # if pxd file can be found
+ endforeach() # for each module dependency discovered
+
+ # Add includes to the files to check, if appropriate.
+ foreach(_include ${include_dependencies})
+ unset(pxi_location CACHE)
+ find_file(pxi_location ${_include}
+ PATHS "${pyx_path}" ${cmake_include_directories}
+ NO_DEFAULT_PATH)
+ if(pxi_location)
+ list(FIND pxds_checked ${pxi_location} pxd_idx)
+ if(${pxd_idx} LESS 0)
+ list(FIND pxds_to_check ${pxi_location} pxd_idx)
+ if(${pxd_idx} LESS 0)
+ list(APPEND pxds_to_check ${pxi_location})
+ list(APPEND pxd_dependencies ${pxi_location})
+ endif() # if it is not already going to be checked
+ endif() # if it has not already been checked
+ endif() # if include file can be found
+ endforeach() # for each include dependency discovered
+ endforeach() # for each include file to check
+
+ list(LENGTH pxds_to_check number_pxds_to_check)
+ endwhile()
+
+ # Set additional flags.
+ set(annotate_arg "")
+ if(CYTHON_ANNOTATE)
+ set(annotate_arg "--annotate")
endif()
- if( NOT main_module )
- message( FATAL_ERROR "main module not found." )
+
+ set(cython_debug_arg "")
+ set(line_directives_arg "")
+ if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR
+ CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
+ set(cython_debug_arg "--gdb")
+ set(line_directives_arg "--line-directives")
endif()
- get_filename_component( main_module_we "${main_module}" NAME_WE )
- set( CYTHON_FLAGS ${CYTHON_FLAGS} --embed )
- compile_pyx( "${main_module_we}_static" generated_file ${main_module} )
- add_executable( ${_name} ${generated_file} ${pyx_module_sources} ${other_module_sources} )
- target_link_libraries( ${_name} ${PYTHON_LIBRARIES} ${pyx_module_libs} )
-endfunction()
+
+ # Include directory arguments.
+ list(REMOVE_DUPLICATES cython_include_directories)
+ set(include_directory_arg "")
+ foreach(_include_dir ${cython_include_directories})
+ set(include_directory_arg
+ ${include_directory_arg} "--include-dir" "${_include_dir}")
+ endforeach()
+
+ list(REMOVE_DUPLICATES pxd_dependencies)
+ list(REMOVE_DUPLICATES c_header_dependencies)
+
+ string(REGEX REPLACE " " ";" CYTHON_FLAGS_LIST "${CYTHON_FLAGS}")
+
+ # Add the command to run the compiler.
+ add_custom_command(OUTPUT ${generated_file}
+ COMMAND ${CYTHON_EXECUTABLE}
+ ARGS ${cxx_arg} ${include_directory_arg} ${py_version_arg}
+ ${embed_arg} ${annotate_arg} ${cython_debug_arg}
+ ${line_directives_arg} ${CYTHON_FLAGS_LIST} ${pyx_location}
+ --output-file ${generated_file}
+ DEPENDS ${_source_file}
+ ${pxd_dependencies}
+ IMPLICIT_DEPENDS ${_output_syntax}
+ ${c_header_dependencies}
+ COMMENT ${comment})
+
+ # NOTE(opadron): I thought about making a proper target, but after trying it
+ # out, I decided that it would be far too convenient to use the same name as
+ # the target for the extension module (e.g.: for single-file modules):
+ #
+ # ...
+ # add_cython_target(_module.pyx)
+ # add_library(_module ${_module})
+ # ...
+ #
+ # The above example would not be possible since the "_module" target name
+ # would already be taken by the cython target. Since I can't think of a
+ # reason why someone would need the custom target instead of just using the
+ # generated file directly, I decided to leave this commented out.
+ #
+ # add_custom_target(${_name} DEPENDS ${generated_file})
+
+ # Remove their visibility to the user.
+ set(corresponding_pxd_file "" CACHE INTERNAL "")
+ set(header_location "" CACHE INTERNAL "")
+ set(pxd_location "" CACHE INTERNAL "")
+endfunction()
\ No newline at end of file
diff --git a/python/jsk_recognition_utils/CMakeLists.txt b/python/jsk_recognition_utils/CMakeLists.txt
index d3feba4f5..496ca09dc 100644
--- a/python/jsk_recognition_utils/CMakeLists.txt
+++ b/python/jsk_recognition_utils/CMakeLists.txt
@@ -1,16 +1,10 @@
-if(NOT DEFINED Numpy_INCLUDE_DIRS)
- # Get Numpy include directories
- execute_process(
- COMMAND python$ENV{ROS_PYTHON_VERSION} -c "import sys, numpy; sys.stdout.write(numpy.get_include())"
- OUTPUT_VARIABLE Numpy_INCLUDE_DIRS
- RESULT_VARIABLE retcode)
- if(NOT ${retcode} EQUAL 0)
- message(FATAL_ERROR "Failed to get Numpy include dirs by numpy.get_include(). Exit code: ${retcode}")
- endif()
-endif()
+find_package (Python COMPONENTS Interpreter Development NumPy)
+find_package(Cython)
+
# Compile nms.pyx
-include_directories(${Numpy_INCLUDE_DIRS})
-cython_add_module(nms nms.pyx)
+include_directories(${Python_NumPy_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ${Python_SITELIB})
+add_cython_target(nms nms.pyx)
+add_library(nms MODULE ${nms})
set_target_properties(nms PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION})
install(TARGETS nms
ARCHIVE DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}