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