1313# ``CYTHON_FOUND``
1414# true if the program was found
1515#
16+ # And the following target:
17+ #
18+ # ``Cython::Cython``
19+ # The Cython executable
20+ #
1621# For more information on the Cython project, see https://cython.org/.
1722#
1823# *Cython is a language that makes writing C extensions for the Python language
3439# limitations under the License.
3540#=============================================================================
3641
42+ if (CMAKE_VERSION VERSION_LESS "3.20" )
43+ message (SEND_ERROR "CMake 3.20 required" )
44+ endif ()
45+
3746# Use the Cython executable that lives next to the Python executable
3847# if it is a local installation.
3948if (Python_EXECUTABLE)
5665endif ()
5766
5867if (CYTHON_EXECUTABLE)
59- set (CYTHON_version_command ${CYTHON_EXECUTABLE} --version )
68+ set (CYTHON_version_command " ${CYTHON_EXECUTABLE} " --version )
6069
6170 execute_process (COMMAND ${CYTHON_version_command}
6271 OUTPUT_VARIABLE CYTHON_version_output
@@ -69,20 +78,31 @@ if(CYTHON_EXECUTABLE)
6978 set (_error_msg "Command \" ${CYTHON_version_command} \" failed with" )
7079 set (_error_msg "${_error_msg} output:\n ${CYTHON_version_error} " )
7180 message (SEND_ERROR "${_error_msg} " )
81+ elseif ("${CYTHON_version_output} " MATCHES "^[Cc]ython version ([^,]+)" )
82+ set (CYTHON_VERSION "${CMAKE_MATCH_1} " )
83+ elseif ("${CYTHON_version_error} " MATCHES "^[Cc]ython version ([^,]+)" )
84+ set (CYTHON_VERSION "${CMAKE_MATCH_1} " )
7285 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 ()
86+ message (SEND_ERROR "Invalid Cython version output" )
8087 endif ()
8188endif ()
8289
8390include (FindPackageHandleStandardArgs)
84- FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cython REQUIRED_VARS CYTHON_EXECUTABLE)
91+ find_package_handle_standard_args(Cython
92+ REQUIRED_VARS CYTHON_EXECUTABLE
93+ VERSION_VAR ${CYTHON_VERSION}
94+ HANDLE_VERSION_RANGE
95+ )
8596
86- mark_as_advanced (CYTHON_EXECUTABLE)
97+ if (CYTHON_FOUND)
98+ if (NOT DEFINED Cython::Cython)
99+ add_executable (Cython::Cython IMPORTED )
100+ set_target_properties (Cython::Cython PROPERTIES
101+ IMPORTED_LOCATION "${CYTHON_EXECUTABLE} "
102+ )
103+ endif ()
104+
105+ include (UseCython)
106+ endif ()
87107
88- include (UseCython )
108+ mark_as_advanced (CYTHON_EXECUTABLE )
0 commit comments