Skip to content

Commit a1dcee1

Browse files
committed
jsk_recognition_utils: compile nms: check if NumPy >= 1.26.0 requires newer version of Cython >= 0.29.30
1 parent 74b6670 commit a1dcee1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

jsk_recognition_utils/python/jsk_recognition_utils/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
# Get NumPy and Cython versions
2+
execute_process(
3+
COMMAND python3 -c "import numpy; print(numpy.__version__)"
4+
OUTPUT_VARIABLE NUMPY_VERSION
5+
OUTPUT_STRIP_TRAILING_WHITESPACE
6+
)
7+
8+
execute_process(
9+
COMMAND python3 -c "import Cython; print(Cython.__version__)"
10+
OUTPUT_VARIABLE CYTHON_VERSION
11+
OUTPUT_STRIP_TRAILING_WHITESPACE
12+
)
13+
14+
message(STATUS "NumPy version: ${NUMPY_VERSION}")
15+
message(STATUS "Cython version: ${CYTHON_VERSION}")
16+
17+
# Convert versions to list of numbers
18+
string(REPLACE "." ";" NUMPY_VER_LIST ${NUMPY_VERSION})
19+
list(GET NUMPY_VER_LIST 0 NUMPY_MAJOR)
20+
list(GET NUMPY_VER_LIST 1 NUMPY_MINOR)
21+
list(GET NUMPY_VER_LIST 2 NUMPY_PATCH)
22+
23+
string(REPLACE "." ";" CYTHON_VER_LIST ${CYTHON_VERSION})
24+
list(GET CYTHON_VER_LIST 0 CYTHON_MAJOR)
25+
list(GET CYTHON_VER_LIST 1 CYTHON_MINOR)
26+
list(GET CYTHON_VER_LIST 2 CYTHON_PATCH)
27+
28+
# Compare versions
29+
# This noexcept modifier was added in newer versions of Cython, and support for it is required when compiling with newer versions of NumPy (1.26+).
30+
# Update your Cython to a recent version (>= 0.29.30 or 3.0+ recommended):
31+
32+
math(EXPR NUMPY_VER "${NUMPY_MAJOR} * 10000 + ${NUMPY_MINOR} * 100 + ${NUMPY_PATCH}")
33+
math(EXPR CYTHON_VER "${CYTHON_MAJOR} * 10000 + ${CYTHON_MINOR} * 100 + ${CYTHON_PATCH}")
34+
35+
if (NUMPY_VER GREATER_EQUAL 12600 AND CYTHON_VER LESS 2930)
36+
message(WARNING "NumPy >= 1.26.0 requires newer version of Cython >= 0.29.30, skip compile nms.pyx")
37+
else()
38+
# Your normal logic here
39+
140
if(NOT DEFINED Numpy_INCLUDE_DIRS)
241
# Get Numpy include directories
342
execute_process(
@@ -16,3 +55,5 @@ install(TARGETS nms
1655
ARCHIVE DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}
1756
LIBRARY DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}
1857
)
58+
59+
endif()

0 commit comments

Comments
 (0)