Skip to content

Commit ea72824

Browse files
docs: add more info to README (#51)
* docs: add more info to README Signed-off-by: Henry Schreiner <[email protected]> * style: pre-commit fixes --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e89b851 commit ea72824

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,73 @@
1515

1616
<!-- SPHINX-START -->
1717

18+
This provides helpers for using Cython. Use:
19+
20+
```cmake
21+
find_package(Cython MODULE REQUIRED VERSION 3.0)
22+
include(UseCython)
23+
```
24+
25+
If you find Python beforehand, the search will take this into account. You can
26+
specify a version range on CMake 3.19+. This will define a `Cython::Cython`
27+
target (along with a matching `CYTHON_EXECUTABLE` variable). It will also
28+
provide the following helper function:
29+
30+
```cmake
31+
cython_transpile(<pyx_file>
32+
[LANGUAGE C | CXX]
33+
[CYTHON_ARGS <args> ...]
34+
[OUTPUT <OutputFile>]
35+
[OUTPUT_VARIABLE <OutputVariable>]
36+
)
37+
```
38+
39+
This function takes a pyx file and makes a matching `.c` / `.cxx` file in the
40+
current binary directory (exact path can be specified with `OUTPUT`). The
41+
location of the produced file is placed in the variable specified by
42+
`OUTPUT_VARIABLE` if given. Extra arguments to the Cython executable can be
43+
given with `CYTHON_ARGS`, and if this is not set, it will take a default from a
44+
`CYTHON_ARGS` variable.
45+
46+
If the `LANGUAGE` is not given, and both `C` and `CXX` are enabled globally,
47+
then the language will try to be deduced from a `# distutils: language=...`
48+
comment in the source file, and C will be used if not found.
49+
50+
This utility relies on the `DEPFILE` feature introduced for Ninja in CMake 3.7,
51+
and added for Make in CMake 3.20, and Visual Studio & Xcode in CMake 3.21.
52+
53+
## Example
54+
55+
```cmake
56+
find_package(
57+
Python
58+
COMPONENTS Interpreter Development.Module
59+
REQUIRED)
60+
find_package(Cython MODULE REQUIRED)
61+
62+
cython_transpile(simple.pyx LANGUAGE C OUTPUT_VARIABLE simple_c)
63+
64+
python_add_library(simple MODULE "${simple_c}" WITH_SOABI)
65+
```
66+
67+
## scikit-build-core
68+
69+
To use this package with scikit-build-core, you need to include it in your build
70+
requirements:
71+
72+
```toml
73+
[build-system]
74+
requires = ["scikit-build-core", "cython", "cython-cmake"]
75+
build-backend = "scikit_build_core.build"
76+
```
77+
78+
It is also recommended to require CMake 3.21:
79+
80+
```toml
81+
[tool.scikit-build]
82+
cmake.version = ">=3.21"
83+
```
84+
1885
## Vendoring
1986

2087
You can vendor FindCython and/or UseCython into your package, as well. This

0 commit comments

Comments
 (0)