Skip to content

Commit ba6d0e1

Browse files
committed
docs: add info
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 4c12c10 commit ba6d0e1

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,72 @@
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+
```
23+
24+
If you find Python beforehand, the search will take this into account. You can
25+
specify a version range on CMake 3.19+. This will define a `Cython::Cython`
26+
target (along with a matching `CYTHON_EXECUTABLE` variable). It will also
27+
provide the following helper function:
28+
29+
```cmake
30+
Cython_compile_pyx(<pyx_file>
31+
[LANGUAGE C | CXX]
32+
[CYTHON_ARGS <args> ...]
33+
[OUTPUT <OutputFile>]
34+
[OUTPUT_VARIABLE <OutputVariable>]
35+
)
36+
```
37+
38+
This function takes a pyx file and makes a matching `.c` / `.cxx` file in the
39+
current binary directory (exact path can be specified with `OUTPUT`). The
40+
location of the produced file is placed in the variable specified by
41+
`OUTPUT_VARIABLE` if given. Extra arguments to the Cython executable can be
42+
given with `CYTHON_ARGS`, and if this is not set, it will take a default from a
43+
`CYTHON_ARGS` variable.
44+
45+
If the `LANGUAGE` is not given, and both `C` and `CXX` are enabled globally,
46+
then the language will try to be deduced from a `# distutils: language=...`
47+
comment in the source file. It is an error if it cannot be deduced.
48+
49+
This utility relies on the `DEPFILE` feature introduced for Ninja in CMake 3.7,
50+
and added for Make in CMake 3.20, and Visual Studio & Xcode in CMake 3.21.
51+
52+
## Example
53+
54+
```cmake
55+
find_package(
56+
Python
57+
COMPONENTS Interpreter Development.Module
58+
REQUIRED)
59+
find_package(Cython MODULE REQUIRED)
60+
61+
cython_compile_pyx(simple.pyx LANGUAGE C OUTPUT_VARIABLE simple_c)
62+
63+
python_add_library(simple MODULE "${simple_c}" WITH_SOABI)
64+
```
65+
66+
## scikit-build-core
67+
68+
To use this package with scikit-build-core, you need to include it in your build
69+
requirements:
70+
71+
```toml
72+
[build-system]
73+
requires = ["scikit-build-core", "cython", "cython-cmake"]
74+
build-backend = "scikit_build_core.build"
75+
```
76+
77+
It is also recommended to require CMake 3.21:
78+
79+
```toml
80+
[tool.scikit-build]
81+
cmake.version = ">=3.21"
82+
```
83+
1884
<!-- prettier-ignore-start -->
1985
[actions-badge]: https://github.com/scikit-build/cython-cmake/workflows/CI/badge.svg
2086
[actions-link]: https://github.com/scikit-build/cython-cmake/actions

src/cython_cmake/cmake/UseCython.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
#=============================================================================
7474

7575
if(CMAKE_VERSION VERSION_LESS "3.7")
76-
message(SEND_ERROR "CMake 3.7 required for DEPFILE")
76+
message(FATAL_ERROR "CMake 3.7 required for DEPFILE")
7777
endif()
7878

7979

@@ -179,7 +179,6 @@ function(Cython_compile_pyx)
179179
COMMENT
180180
"Cythonizing source ${input_file_relative} to output ${generated_file_relative}"
181181
)
182-
183182
endfunction()
184183

185184
function(_cython_compute_language OUTPUT_VARIABLE FILENAME)

0 commit comments

Comments
 (0)