|
4 | 4 |
|
5 | 5 | # the Python version number requirement is in modules/FindPython_test.cpp
|
6 | 6 | find_package(Python ${PYTHON_MIN_VERSION} REQUIRED)
|
7 |
| -find_package(Cython ${CYTHON_MIN_VERSION} REQUIRED) |
| 7 | + |
| 8 | +# Define minimum and fallback versions for Cython |
| 9 | +set(CYTHON_MIN_VERSION 3.0.10) |
| 10 | +set(CYTHON_MIN_VERSION_FALLBACK 0.29.31) |
| 11 | + |
| 12 | +find_package(Cython QUIET) |
| 13 | +if (CYTHON_FOUND AND |
| 14 | + ((CYTHON_VERSION VERSION_GREATER_EQUAL ${CYTHON_MIN_VERSION}) OR |
| 15 | + (CYTHON_VERSION VERSION_GREATER ${CYTHON_MIN_VERSION_FALLBACK} AND CYTHON_VERSION VERSION_LESS 3.0.0))) |
| 16 | + message("Using Cython ${CYTHON_VERSION}") |
| 17 | +else() |
| 18 | + message(FATAL_ERROR "Not found Cython compatible version (>= ${CYTHON_MIN_VERSION} or > ${CYTHON_MIN_VERSION_FALLBACK} in 0.29.x).") |
| 19 | +endif() |
8 | 20 |
|
9 | 21 | py_get_config_var(EXT_SUFFIX PYEXT_SUFFIX)
|
10 | 22 | if(MINGW)
|
11 |
| - string(REGEX REPLACE "dll" "pyd" PYEXT_SUFFIX "${PYEXT_SUFFIX}") |
| 23 | + string(REGEX REPLACE "dll" "pyd" PYEXT_SUFFIX "${PYEXT_SUFFIX}") |
12 | 24 | endif()
|
13 | 25 |
|
14 | 26 | # This is the only useful thing after cleaning up what python suggests
|
15 | 27 | if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
16 |
| - set(PYEXT_CXXFLAGS "-fwrapv") |
| 28 | + set(PYEXT_CXXFLAGS "-fwrapv") |
17 | 29 | endif()
|
18 | 30 |
|
19 | 31 |
|
20 | 32 | # numpy deprecated api
|
21 | 33 | # http://docs.cython.org/en/latest/src/userguide/source_files_and_compilation.html#configuring-the-c-build
|
22 | 34 | if(CYTHON_VERSION VERSION_GREATER_EQUAL 3)
|
23 |
| - set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION") |
| 35 | + set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION") |
24 | 36 | else()
|
25 | 37 |
|
26 |
| - # suppress #warning about deprecated numpy api |
27 |
| - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
28 |
| - set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -Wno-cpp") |
29 |
| - elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
30 |
| - set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -Wno-#warnings") |
31 |
| - endif() |
| 38 | + # suppress #warning about deprecated numpy api |
| 39 | + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 40 | + set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -Wno-cpp") |
| 41 | + elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") |
| 42 | + set(PYEXT_CXXFLAGS "${PYEXT_CXXFLAGS} -Wno-#warnings") |
| 43 | + endif() |
32 | 44 | endif()
|
33 | 45 |
|
34 | 46 | # silence cython+python3.8 tp_print deprecation warning
|
35 | 47 | # https://github.com/cython/cython/pull/3201
|
36 | 48 | # https://github.com/cython/cython/issues/3474
|
37 | 49 | if(PYTHON_VER VERSION_GREATER_EQUAL 3.8 AND PYTHON_VERSION VERSION_LESS 3.9)
|
38 |
| - set(PYEXT_CXXCLAGS "${PYEXT_CXXCLAGS}" "-Wno-deprecated-declarations") |
| 50 | + set(PYEXT_CXXCLAGS "${PYEXT_CXXCLAGS}" "-Wno-deprecated-declarations") |
39 | 51 | endif()
|
40 | 52 |
|
41 | 53 | set(PYEXT_LIBRARY "${PYTHON_LIBRARIES}")
|
42 | 54 | message("PYTHON_LIBRARIES: " "${PYTHON_LIBRARIES}")
|
43 | 55 | #Windows always uses optimized version of Python lib
|
44 | 56 | if(WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
45 |
| - #get index of string "optimized" and increment it by 1 so index points at the path of the optimized lib |
46 |
| - list (FIND PYEXT_LIBRARY "optimized" _index) |
47 |
| - if (${_index} GREATER -1) |
48 |
| - MATH(EXPR _index "${_index}+1") |
49 |
| - list(GET PYEXT_LIBRARY ${_index} PYEXT_LIBRARY) |
50 |
| - endif() |
51 |
| - message("force linking to python release lib, instead of debug lib when cythonising") |
52 |
| - set(force_optimized_lib_flag "--force_optimized_lib") |
| 57 | + #get index of string "optimized" and increment it by 1 so index points at the path of the optimized lib |
| 58 | + list(FIND PYEXT_LIBRARY "optimized" _index) |
| 59 | + if(${_index} GREATER -1) |
| 60 | + MATH(EXPR _index "${_index}+1") |
| 61 | + list(GET PYEXT_LIBRARY ${_index} PYEXT_LIBRARY) |
| 62 | + endif() |
| 63 | + message("force linking to python release lib, instead of debug lib when cythonising") |
| 64 | + set(force_optimized_lib_flag "--force_optimized_lib") |
53 | 65 | endif()
|
54 | 66 |
|
55 | 67 | set(PYEXT_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS};${NUMPY_INCLUDE_DIR}")
|
56 | 68 |
|
57 | 69 | if(NOT CMAKE_PY_INSTALL_PREFIX)
|
58 |
| - if(MSVC) |
59 |
| - set(CMAKE_PY_INSTALL_PREFIX "python") |
60 |
| - else() |
61 |
| - # get site-packages directory, prepended with cmake's install prefix |
62 |
| - py_exec("import sys, sysconfig, os; print(os.path.join('${CMAKE_INSTALL_PREFIX}', os.path.relpath(sysconfig.get_path('purelib'), os.path.normpath(sys.prefix))))" PREFIX) |
63 |
| - set(CMAKE_PY_INSTALL_PREFIX "${PREFIX}") |
64 |
| - endif() |
| 70 | + if(MSVC) |
| 71 | + set(CMAKE_PY_INSTALL_PREFIX "python") |
| 72 | + else() |
| 73 | + # get site-packages directory, prepended with cmake's install prefix |
| 74 | + py_exec("import sys, sysconfig, os; print(os.path.join('${CMAKE_INSTALL_PREFIX}', os.path.relpath(sysconfig.get_path('purelib'), os.path.normpath(sys.prefix))))" PREFIX) |
| 75 | + set(CMAKE_PY_INSTALL_PREFIX "${PREFIX}") |
| 76 | + endif() |
65 | 77 | endif()
|
0 commit comments