Skip to content

Commit a6bccfa

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

File tree

3 files changed

+205
-9
lines changed

3 files changed

+205
-9
lines changed

docs/cmakelists.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,13 @@ succeed.
7676

7777
## Finding other packages
7878

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

8987
## Install directories
9088

docs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ getting_started
3232
configuration
3333
overrides
3434
cmakelists
35+
search_paths
3536
crosscompile
3637
migration_guide
3738
build

docs/search_paths.md

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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.
5+
6+
## `<PackageName>_ROOT`
7+
8+
This is the most recommended interface to be used for importing dependent
9+
packages using `find_package`. This variable is populated by the dependent
10+
project's entry-point `cmake.root` or by the current project's `search.roots`
11+
option, the latter having a higher priority.
12+
13+
To configure the `cmake.root` entry-point to export to other projects, you
14+
can 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+
```{code-block} toml
40+
:caption: pyproject.toml
41+
:emphasize-lines: 2,5
42+
43+
[tool.scikit-build]
44+
wheel.install-dir = "myproject"
45+
46+
[project.entry-points."cmake.root"]
47+
MyProject = "myproject"
48+
```
49+
50+
:::{note}
51+
52+
Scikit-build-core does not currently support dynamic entry-points population.
53+
54+
:::
55+
56+
With this any consuming project that depends on this would automatically work
57+
with `find_package(MyProject)` as long as it is in the `build-system.requires`
58+
list. When consuming a project, you can ignore these entry-points by setting
59+
`search.ignore_entry_point` or expand them with `search.roots`, e.g.
60+
61+
````{tab} pyproject.toml
62+
63+
```toml
64+
[tool.scikit-build.search]
65+
ignore_entry_point = ["MyProject"]
66+
[tool.scikit-build.search.roots]
67+
OtherProject = "/path/to/other_project"
68+
```
69+
70+
````
71+
72+
`````{tab} config-settings
73+
74+
75+
````{tab} pip
76+
77+
```console
78+
$ pip install . -v --config-settings=search.ignore_entry_point="MyProject" --config-settings=search.roots.OtherProject="/path/to/other_project"
79+
```
80+
81+
````
82+
83+
````{tab} build
84+
85+
```console
86+
$ pipx run build --wheel -Csearch.ignore_entry_point="MyProject" -Csearch.roots.OtherProject="/path/to/other_project"
87+
```
88+
89+
````
90+
91+
````{tab} cibuildwheel
92+
93+
```toml
94+
[tool.cibuildwheel.config-settings]
95+
"search.ignore_entry_point" = ["MyProject"]
96+
"search.roots.OtherProject" = "/path/to/other_project"
97+
```
98+
99+
````
100+
101+
`````
102+
103+
````{tab} Environment
104+
105+
106+
```yaml
107+
SKBUILD_SEARCH_IGNORE_ENTRY_POINT: "MyProject"
108+
SKBUILD_SEARCH_ROOTS_OtherProject: "/path/to/other_project"
109+
```
110+
111+
````
112+
113+
## `CMAKE_PREFIX_PATH`
114+
115+
Another common search path that scikit-build-core populates is the
116+
`CMAKE_PREFIX_PATH` which is a common catch-all for all CMake search paths,
117+
e.g. `find_package`, `find_program`, `find_path`. This is populated by default
118+
with the `site-packages` folder where the project will be installed or the build
119+
isolation's `site-packages` folder. This default can be disabled by setting
120+
121+
```toml
122+
[tool.scikit-build.search]
123+
search.use-site-packages = false
124+
```
125+
126+
Additionally, scikit-build-core reads the entry-point `cmake.prefix`, which you
127+
can similarly export this as
128+
129+
``` toml
130+
[project.entry-points."cmake.prefix"]
131+
MyProject = "myproject"
132+
```
133+
134+
and you can similarly alter them with `search.ignore_entry_point` and
135+
`search.prefixes`
136+
137+
````{tab} pyproject.toml
138+
139+
```toml
140+
[tool.scikit-build.search]
141+
ignore_entry_point = ["MyProject"]
142+
prefixes = ["/path/to/prefixA", "/path/to/prefixB"]
143+
```
144+
145+
````
146+
147+
`````{tab} config-settings
148+
149+
150+
````{tab} pip
151+
152+
```console
153+
$ pip install . -v --config-settings=search.ignore_entry_point="MyProject" --config-settings=search.prefixes="/path/to/prefixA;/path/to/prefixB"
154+
```
155+
156+
````
157+
158+
````{tab} build
159+
160+
```console
161+
$ pipx run build --wheel -Csearch.ignore_entry_point="MyProject" -Csearch.prefixes="/path/to/prefixA;/path/to/prefixB"
162+
```
163+
164+
````
165+
166+
````{tab} cibuildwheel
167+
168+
```toml
169+
[tool.cibuildwheel.config-settings]
170+
"search.ignore_entry_point" = ["MyProject"]
171+
"search.prefixes" = ["/path/to/prefixA", "/path/to/prefixB"]
172+
```
173+
174+
````
175+
176+
`````
177+
178+
````{tab} Environment
179+
180+
181+
```yaml
182+
SKBUILD_SEARCH_IGNORE_ENTRY_POINT: "MyProject"
183+
SKBUILD_SEARCH_PREFIXES: "/path/to/prefixA;/path/to/prefixB"
184+
```
185+
186+
````
187+
188+
## `CMAKE_MODULE_PATH`
189+
190+
Scikit-build-core also populates `CMAKE_MODULE_PATH` variable used to search
191+
for CMake modules using the `include()` command (if the `.cmake` suffix is
192+
omitted).
193+
194+
This variable is populated from the entry-point `cmake.module` and the option
195+
`search.modules` similar to [`CMAKE_PREFIX_PATH`] section.
196+
197+
[`CMAKE_PREFIX_PATH`]: #cmake-prefix-path

0 commit comments

Comments
 (0)