Skip to content

Commit d5a437e

Browse files
committed
Document search path behavior
Signed-off-by: Cristian Le <[email protected]> Signed-off-by: Cristian Le <[email protected]>
1 parent a6a145f commit d5a437e

File tree

3 files changed

+192
-9
lines changed

3 files changed

+192
-9
lines changed

docs/configuration/search_paths.md

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# Search paths
2+
3+
Scikit-build-core populates CMake search paths to take into account any other
4+
CMake project installed in the same environment. In order to take advantage of
5+
this the dependent project must populate a `cmake.*` entry-point.
6+
7+
## `<PackageName>_ROOT`
8+
9+
This is the most recommended interface to be used for importing dependent
10+
packages using `find_package`. This variable is populated by the dependent
11+
project's entry-point `cmake.root`.
12+
13+
To configure the `cmake.root` entry-point to export to other projects, you can
14+
use the CMake standard install paths in you `CMakeLists.txt` if you use
15+
`wheel.install-dir` option, e.g.
16+
17+
```{code-block} cmake
18+
:caption: CMakeLists.txt
19+
:emphasize-lines: 14-16
20+
21+
include(CMakePackageConfigHelpers)
22+
include(GNUInstallDirs)
23+
write_basic_package_version_file(
24+
MyProjectConfigVersion.cmake
25+
VERSION ${PROJECT_VERSION}
26+
COMPATIBILITY SameMajorVersion
27+
)
28+
configure_package_config_file(
29+
cmake/MyProjectConfig.cmake.in
30+
MyProjectConfig.cmake
31+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MyProject
32+
)
33+
install(FILES
34+
${CMAKE_CURRENT_BINARY_DIR}/MyProjectConfigVersion.cmake
35+
${CMAKE_CURRENT_BINARY_DIR}/MyProjectConfig.cmake
36+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/MyProject
37+
)
38+
```
39+
40+
```{code-block} toml
41+
:caption: pyproject.toml
42+
:emphasize-lines: 2,5
43+
44+
[tool.scikit-build]
45+
wheel.install-dir = "myproject"
46+
47+
[project.entry-points."cmake.root"]
48+
MyProject = "myproject"
49+
```
50+
51+
With this any consuming project that depends on this would automatically work
52+
with `find_package(MyProject)` as long as it is in the `build-system.requires`
53+
list.
54+
55+
````{tab} pyproject.toml
56+
57+
```toml
58+
[tool.scikit-build.search]
59+
ignore_entry_point = ["MyProject"]
60+
[tool.scikit-build.search.roots]
61+
OtherProject = "/path/to/other_project"
62+
```
63+
64+
````
65+
66+
`````{tab} config-settings
67+
68+
69+
````{tab} pip
70+
71+
```console
72+
$ pip install . -v --config-settings=search.ignore_entry_point="MyProject" --config-settings=search.roots.OtherProject="/path/to/other_project"
73+
```
74+
75+
````
76+
77+
````{tab} build
78+
79+
```console
80+
$ pipx run build --wheel -Csearch.ignore_entry_point="MyProject" -Csearch.roots.OtherProject="/path/to/other_project"
81+
```
82+
83+
````
84+
85+
````{tab} cibuildwheel
86+
87+
```toml
88+
[tool.cibuildwheel.config-settings]
89+
"search.ignore_entry_point" = ["MyProject"]
90+
"search.roots.OtherProject" = "/path/to/other_project"
91+
```
92+
93+
````
94+
95+
`````
96+
97+
````{tab} Environment
98+
99+
100+
```yaml
101+
SKBUILD_SEARCH_IGNORE_ENTRY_POINT: "MyProject"
102+
SKBUILD_SEARCH_ROOTS_OtherProject: "/path/to/other_project"
103+
```
104+
105+
````
106+
107+
## `CMAKE_PREFIX_PATH`
108+
109+
Another common search path that scikit-build-core populates is the
110+
`CMAKE_PREFIX_PATH` which is a common catch-all for all CMake search paths, e.g.
111+
`find_package`, `find_program`, `find_path`. This is populated by default with
112+
the `site-packages` folder where the project will be installed or the build
113+
isolation's `site-packages` folder. This default can be disabled by setting
114+
115+
```toml
116+
[tool.scikit-build.search]
117+
search.use-site-packages = false
118+
```
119+
120+
Additionally, scikit-build-core reads the entry-point `cmake.prefix` of the
121+
dependent projects, which is similarly export as
122+
123+
```toml
124+
[project.entry-points."cmake.prefix"]
125+
MyProject = "myproject"
126+
```
127+
128+
````{tab} pyproject.toml
129+
130+
```toml
131+
[tool.scikit-build.search]
132+
ignore_entry_point = ["MyProject"]
133+
prefixes = ["/path/to/prefixA", "/path/to/prefixB"]
134+
```
135+
136+
````
137+
138+
`````{tab} config-settings
139+
140+
141+
````{tab} pip
142+
143+
```console
144+
$ pip install . -v --config-settings=search.ignore_entry_point="MyProject" --config-settings=search.prefixes="/path/to/prefixA;/path/to/prefixB"
145+
```
146+
147+
````
148+
149+
````{tab} build
150+
151+
```console
152+
$ pipx run build --wheel -Csearch.ignore_entry_point="MyProject" -Csearch.prefixes="/path/to/prefixA;/path/to/prefixB"
153+
```
154+
155+
````
156+
157+
````{tab} cibuildwheel
158+
159+
```toml
160+
[tool.cibuildwheel.config-settings]
161+
"search.ignore_entry_point" = ["MyProject"]
162+
"search.prefixes" = ["/path/to/prefixA", "/path/to/prefixB"]
163+
```
164+
165+
````
166+
167+
`````
168+
169+
````{tab} Environment
170+
171+
172+
```yaml
173+
SKBUILD_SEARCH_IGNORE_ENTRY_POINT: "MyProject"
174+
SKBUILD_SEARCH_PREFIXES: "/path/to/prefixA;/path/to/prefixB"
175+
```
176+
177+
````
178+
179+
## `CMAKE_MODULE_PATH`
180+
181+
Scikit-build-core also populates `CMAKE_MODULE_PATH` variable used to search for
182+
CMake modules using the `include()` command (if the `.cmake` suffix is omitted).
183+
184+
[`CMAKE_PREFIX_PATH`]: #cmake-prefix-path

docs/guide/cmakelists.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ succeed.
7777

7878
## Finding other packages
7979

80-
Scikit-build-core includes the site-packages directory in CMake's search path,
81-
so packages can provide a find package config with a name matching the package
82-
name - such as the `pybind11` package.
83-
84-
Third party packages can declare entry-points `cmake.module` and `cmake.prefix`,
85-
and the specified module will be added to `CMAKE_MODULE_PATH` and
86-
`CMAKE_PREFIX_PATH`, respectively. Currently, the key is not used, but
87-
eventually there might be a way to request or exclude certain entry-points by
88-
key.
80+
Scikit-build-core includes various pythonic paths to the CMake search paths by
81+
default so that usually you only need to include the dependent project inside
82+
the `build-system.requires` section. Note that `cmake` and `ninja` should not be
83+
included in that section.
84+
85+
See [search paths section](../configuration/search_paths.md) for more details on
86+
how the search paths are constructed.
8987

9088
## Install directories
9189

docs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ guide/faqs
4343
configuration/index
4444
configuration/overrides
4545
configuration/dynamic
46+
configuration/search_paths
4647
```
4748

4849
```{toctree}

0 commit comments

Comments
 (0)