Find cython executable.

This module will set the following variables in your project:

path to the cython program
version of cython
true if the program was found

For more information on the Cython project, see

Cython is a language that makes writing C extensions for the Python language as easy as Python itself.

The following functions are defined:


Create a custom rule to generate the source code for a Python extension module using cython.

add_cython_target(<Name> [<CythonInput>]
[EMBED_MAIN] [C | CXX] [PY2 | PY3] [OUTPUT_VAR <OutputVar>])

<Name> is the name of the new target, and <CythonInput> is the path to a cython source file. Note that, despite the name, no new targets are created by this function. Instead, see OUTPUT_VAR for retrieving the path to the generated source for subsequent targets.

If only <Name> is provided, and it ends in the ”.pyx” extension, then it is assumed to be the <CythonInput>. The name of the input without the extension is used as the target name. If only <Name> is provided, and it does not end in the ”.pyx” extension, then the <CythonInput> is assumed to be <Name>.pyx.

The Cython include search path is amended with any entries found in the INCLUDE_DIRECTORIES property of the directory containing the <CythonInput> file. Use iunclude_directories to add to the Cython include search path.


Embed a main() function in the generated output (for stand-alone applications that initialize their own Python runtime).
Force the generation of either a C or C++ file. By default, a C file is generated, unless the C language is not enabled for the project; in this case, a C++ file is generated by default.
PY2 | PY3
Force compilation using either Python-2 or Python-3 syntax and code semantics. By default, Python-2 syntax and semantics are used if the major version of Python found is 2. Otherwise, Python-3 syntax and sematics are used.
OUTPUT_VAR <OutputVar>
Set the variable <OutputVar> in the parent scope to the path to the generated source file. By default, <Name> is used as the output variable name.

Defined variables:

The path of the generated source file.

Cache variables that effect the behavior include:

whether to create an annotated .html file when compiling
additional flags to pass to the Cython compiler

Example usage


# Note: In this case, either one of these arguments may be omitted; their
# value would have been inferred from that of the other.
add_cython_target(cy_code cy_code.pyx)

add_library(cy_code MODULE ${cy_code})
target_link_libraries(cy_code ...)