Support compiling Cython extensions
I would like to add support for compiling Cython extensions using CMake. Since Cython is a transpiler, it would be sufficient to support the Cython to C/C++ translation, with the resulting target then usable by any other CMake functionality.
If there is interest in adding this functionality, I would propose to do so by adding a Cython
component to FindPython
. Successfully finding this component would require the cython
executable to exist somewhere on the PATH
. If found, this component would, at minimum:
- Create a
Python::Cython
target - Set
Python_Cython_FOUND
- Set
Python_Cython_VERSION
- Set
Python_Cython_EXECUTABLE
to the absolute path to the Cython executable - Define an
add_cython_target
(replacetarget
withlibrary
etc, whatever naming preferred) function that would accept a Cython pyx file and run thecython
executable on it, producing a C/C++ file. Ideally, this command would support all the command line arguments tocython
as well.
If there is interest in this functionality, I'm happy to put up a PR implementing it (may need some guidance of course).
Alternatives considered
Rather than running cython
, CMake could also run cythonize
, which runs cython
as well as running an appropriate C/C++ compiler afterwards. While that may be the easier use case for direct Cython usage, I think it plays less nicely with CMake since CMake can probably do a better job of orchestrating the compilation when you're compiling Cython code as part of a larger project and all other targets are managed by CMake.