Skip to content

Commit 88de068

Browse files
committed
wip: Add scikit-build-classic FindCython/UseCython
Based of scikit-build/scikit-build@c723e579a (fix: stop assuming that pyx files are in the same directory as CMakeLists.txt)
1 parent eeefc9d commit 88de068

File tree

2 files changed

+471
-0
lines changed

2 files changed

+471
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#.rst:
2+
#
3+
# Find ``cython`` executable.
4+
#
5+
# This module will set the following variables in your project:
6+
#
7+
# ``CYTHON_EXECUTABLE``
8+
# path to the ``cython`` program
9+
#
10+
# ``CYTHON_VERSION``
11+
# version of ``cython``
12+
#
13+
# ``CYTHON_FOUND``
14+
# true if the program was found
15+
#
16+
# For more information on the Cython project, see https://cython.org/.
17+
#
18+
# *Cython is a language that makes writing C extensions for the Python language
19+
# as easy as Python itself.*
20+
#
21+
#=============================================================================
22+
# Copyright 2011 Kitware, Inc.
23+
#
24+
# Licensed under the Apache License, Version 2.0 (the "License");
25+
# you may not use this file except in compliance with the License.
26+
# You may obtain a copy of the License at
27+
#
28+
# http://www.apache.org/licenses/LICENSE-2.0
29+
#
30+
# Unless required by applicable law or agreed to in writing, software
31+
# distributed under the License is distributed on an "AS IS" BASIS,
32+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33+
# See the License for the specific language governing permissions and
34+
# limitations under the License.
35+
#=============================================================================
36+
37+
# Use the Cython executable that lives next to the Python executable
38+
# if it is a local installation.
39+
if(Python_EXECUTABLE)
40+
get_filename_component(_python_path ${Python_EXECUTABLE} PATH)
41+
elseif(Python3_EXECUTABLE)
42+
get_filename_component(_python_path ${Python3_EXECUTABLE} PATH)
43+
elseif(DEFINED PYTHON_EXECUTABLE)
44+
get_filename_component(_python_path ${PYTHON_EXECUTABLE} PATH)
45+
endif()
46+
47+
if(DEFINED _python_path)
48+
find_program(CYTHON_EXECUTABLE
49+
NAMES cython cython.bat cython3
50+
HINTS ${_python_path}
51+
DOC "path to the cython executable")
52+
else()
53+
find_program(CYTHON_EXECUTABLE
54+
NAMES cython cython.bat cython3
55+
DOC "path to the cython executable")
56+
endif()
57+
58+
if(CYTHON_EXECUTABLE)
59+
set(CYTHON_version_command ${CYTHON_EXECUTABLE} --version)
60+
61+
execute_process(COMMAND ${CYTHON_version_command}
62+
OUTPUT_VARIABLE CYTHON_version_output
63+
ERROR_VARIABLE CYTHON_version_error
64+
RESULT_VARIABLE CYTHON_version_result
65+
OUTPUT_STRIP_TRAILING_WHITESPACE
66+
ERROR_STRIP_TRAILING_WHITESPACE)
67+
68+
if(NOT ${CYTHON_version_result} EQUAL 0)
69+
set(_error_msg "Command \"${CYTHON_version_command}\" failed with")
70+
set(_error_msg "${_error_msg} output:\n${CYTHON_version_error}")
71+
message(SEND_ERROR "${_error_msg}")
72+
else()
73+
if("${CYTHON_version_output}" MATCHES "^[Cc]ython version ([^,]+)")
74+
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
75+
else()
76+
if("${CYTHON_version_error}" MATCHES "^[Cc]ython version ([^,]+)")
77+
set(CYTHON_VERSION "${CMAKE_MATCH_1}")
78+
endif()
79+
endif()
80+
endif()
81+
endif()
82+
83+
include(FindPackageHandleStandardArgs)
84+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cython REQUIRED_VARS CYTHON_EXECUTABLE)
85+
86+
mark_as_advanced(CYTHON_EXECUTABLE)
87+
88+
include(UseCython)

0 commit comments

Comments
 (0)