Skip to content

Commit 09a1f09

Browse files
committed
build(python): properly support both new and old cython
Signed-off-by: Benn Snyder <[email protected]>
1 parent 196f95d commit 09a1f09

File tree

4 files changed

+574
-8
lines changed

4 files changed

+574
-8
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ include (SetupDirectories)
4747

4848
set (PROJECT_VER_MAJOR 0)
4949
set (PROJECT_VER_MINOR 7)
50-
set (PROJECT_VER_PATCH 4)
50+
set (PROJECT_VER_PATCH 5)
5151
set (PROJECT_VER
5252
"${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}.${PROJECT_VER_PATCH}")
5353
set (PROJECT_APIVER

wrappers/python/CMakeLists.txt

+18-5
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,30 @@ execute_process(COMMAND
3131
-c "import numpy; print(numpy.get_include())"
3232
OUTPUT_VARIABLE Python${Python_BUILD_VERSION}_NumPy_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
3333

34+
# cython 3.0 has breaking changes, like certain functions must be marked noexcept
35+
# but noexcept is not defined in old cython < 0.29.31 shipped in ubuntu 20.04
36+
# todo: eventually drop support for cython 0.x.x
37+
execute_process(COMMAND
38+
${CYTHON_EXECUTABLE} --version
39+
ERROR_VARIABLE CYTHON_VERSION_OUTPUT ERROR_STRIP_TRAILING_WHITESPACE)
40+
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CYTHON_VERSION "${CYTHON_VERSION_OUTPUT}")
41+
string(REGEX MATCHALL "[0-9]+" CYTHON_VERSION_COMPONENTS "${CYTHON_VERSION}")
42+
list(GET CYTHON_VERSION_COMPONENTS 0 CYTHON_VERSION_MAJOR)
43+
list(GET CYTHON_VERSION_COMPONENTS 1 CYTHON_VERSION_MINOR)
44+
list(GET CYTHON_VERSION_COMPONENTS 2 CYTHON_VERSION_PATCH)
45+
if (${CYTHON_VERSION_MAJOR} LESS_EQUAL 0)
46+
set(FREENECT_PYX "freenect.cython0.pyx")
47+
else()
48+
set(FREENECT_PYX "freenect.pyx")
49+
endif()
50+
3451
# How to Cython the .pyx file
3552
add_custom_command(OUTPUT freenect${Python_BUILD_VERSION}.c
3653
COMMAND
3754
${CYTHON_EXECUTABLE}
3855
-${Python_BUILD_VERSION}
3956
-o freenect${Python_BUILD_VERSION}.c
40-
# cython 3.0 needs certain functions to be marked noexcept
41-
# but noexcept is not defined in old cython shipped in ubuntu 20.04
42-
# todo: eventually require cython >= 0.29.31 and add proper noexcept without this workaround
43-
-X legacy_implicit_noexcept=True
44-
"${CMAKE_CURRENT_SOURCE_DIR}/freenect.pyx")
57+
"${CMAKE_CURRENT_SOURCE_DIR}/${FREENECT_PYX}")
4558
list(APPEND ADDITIONAL_MAKE_CLEAN_FILES freenect${Python_BUILD_VERSION}.c)
4659

4760
# Compile the extension

0 commit comments

Comments
 (0)