Skip to content

Commit 00b7dff

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 00b7dff

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

jsk_recognition_utils/python/jsk_recognition_utils/CMakeLists.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,59 @@
1+
# Get NumPy and Cython versions
2+
execute_process(
3+
COMMAND python$ENV{ROS_PYTHON_VERSION} -c "import numpy; print(numpy.__version__)"
4+
OUTPUT_VARIABLE NUMPY_VERSION
5+
OUTPUT_STRIP_TRAILING_WHITESPACE
6+
)
7+
8+
execute_process(
9+
COMMAND python$ENV{ROS_PYTHON_VERSION} -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+
# --- Parse version strings safely ---
18+
# --- Compatibility logic (CMake 3.5+) ---
19+
function(version_to_number ver_str out_var)
20+
string(REPLACE "." ";" _parts ${ver_str})
21+
list(LENGTH _parts _len)
22+
list(GET _parts 0 _major)
23+
if(_len GREATER 1)
24+
list(GET _parts 1 _minor)
25+
else()
26+
set(_minor 0)
27+
endif()
28+
if(_len GREATER 2)
29+
list(GET _parts 2 _patch)
30+
else()
31+
set(_patch 0)
32+
endif()
33+
math(EXPR _version_num "${_major} * 10000 + ${_minor} * 100 + ${_patch}")
34+
set(${out_var} ${_version_num} PARENT_SCOPE)
35+
endfunction()
36+
37+
# Compare versions
38+
# 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+).
39+
# Update your Cython to a recent version (>= 0.29.30 or 3.0+ recommended):
40+
41+
42+
# Simulate GREATER_EQUAL using GREATER or EQUAL
43+
set(SKIP_NMS FALSE)
44+
version_to_number("${NUMPY_VERSION}" NUMPY_VER)
45+
if(NUMPY_VER GREATER 12600 OR NUMPY_VER EQUAL 12600)
46+
version_to_number("${CYTHON_VERSION}" CYTHON_VER)
47+
if(CYTHON_VER LESS 2930)
48+
set(SKIP_NMS TRUE)
49+
endif()
50+
endif()
51+
52+
if(SKIP_NMS)
53+
message(WARNING "NumPy >= 1.26.0 requires newer version of Cython >= 0.29.30, skip compile nms.pyx")
54+
else()
55+
# Your normal logic here
56+
157
if(NOT DEFINED Numpy_INCLUDE_DIRS)
258
# Get Numpy include directories
359
execute_process(
@@ -16,3 +72,5 @@ install(TARGETS nms
1672
ARCHIVE DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}
1773
LIBRARY DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}
1874
)
75+
76+
endif()

0 commit comments

Comments
 (0)