|
| 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. |
| 59 | + |
| 60 | +You can use `search.roots` to override or extend these variables, e.g. you can |
| 61 | +delete the `MyProject_ROOT` variable by setting |
| 62 | + |
| 63 | +````{tab} pyproject.toml |
| 64 | + |
| 65 | +```toml |
| 66 | +[tool.scikit-build.search.roots] |
| 67 | +MyProject = "" |
| 68 | +``` |
| 69 | + |
| 70 | +```` |
| 71 | + |
| 72 | +`````{tab} config-settings |
| 73 | +
|
| 74 | +
|
| 75 | +````{tab} pip |
| 76 | +
|
| 77 | +```console |
| 78 | +$ pip install . -v --config-settings=search.roots.MyProject="" |
| 79 | +``` |
| 80 | +
|
| 81 | +```` |
| 82 | +
|
| 83 | +````{tab} build |
| 84 | +
|
| 85 | +```console |
| 86 | +$ pipx run build --wheel -Csearch.roots.MyProject="" |
| 87 | +``` |
| 88 | +
|
| 89 | +```` |
| 90 | +
|
| 91 | +````{tab} cibuildwheel |
| 92 | +
|
| 93 | +```toml |
| 94 | +[tool.cibuildwheel.config-settings] |
| 95 | +"search.roots.MyProject" = "" |
| 96 | +``` |
| 97 | +
|
| 98 | +```` |
| 99 | +
|
| 100 | +````` |
| 101 | + |
| 102 | +````{tab} Environment |
| 103 | +
|
| 104 | +
|
| 105 | +```yaml |
| 106 | +SKBUILD_SEARCH_ROOTS_MyProject: "" |
| 107 | +``` |
| 108 | +
|
| 109 | +```` |
| 110 | + |
| 111 | +Or you could point to another preferred path: |
| 112 | + |
| 113 | + |
| 114 | +````{tab} pyproject.toml |
| 115 | + |
| 116 | +```toml |
| 117 | +[tool.scikit-build.search.roots] |
| 118 | +MyProject = "other_project" |
| 119 | +``` |
| 120 | + |
| 121 | +```` |
| 122 | + |
| 123 | +`````{tab} config-settings |
| 124 | +
|
| 125 | +
|
| 126 | +````{tab} pip |
| 127 | +
|
| 128 | +```console |
| 129 | +$ pip install . -v --config-settings=search.roots.MyProject="other_project" |
| 130 | +``` |
| 131 | +
|
| 132 | +```` |
| 133 | +
|
| 134 | +````{tab} build |
| 135 | +
|
| 136 | +```console |
| 137 | +$ pipx run build --wheel -Csearch.roots.MyProject="other_project" |
| 138 | +``` |
| 139 | +
|
| 140 | +```` |
| 141 | +
|
| 142 | +````{tab} cibuildwheel |
| 143 | +
|
| 144 | +```toml |
| 145 | +[tool.cibuildwheel.config-settings] |
| 146 | +"search.roots.MyProject" = "other_project" |
| 147 | +``` |
| 148 | +
|
| 149 | +```` |
| 150 | +
|
| 151 | +````` |
| 152 | + |
| 153 | +````{tab} Environment |
| 154 | +
|
| 155 | +
|
| 156 | +```yaml |
| 157 | +SKBUILD_SEARCH_ROOTS_MyProject: "other_project" |
| 158 | +``` |
| 159 | +
|
| 160 | +```` |
| 161 | + |
| 162 | +## `CMAKE_PREFIX_PATH` |
| 163 | + |
| 164 | +Another common search path that scikit-build-core populates is the |
| 165 | +`CMAKE_PREFIX_PATH` which is a common catch-all for all CMake search paths, |
| 166 | +e.g. `find_package`, `find_program`, `find_path`. This is populated by default |
| 167 | +with the install and build path's `site-packages` folder, but this can be |
| 168 | +disabled by setting |
| 169 | + |
| 170 | +```toml |
| 171 | +[tool.scikit-build.search] |
| 172 | +search.use-install-prefix = false |
| 173 | +search.use-build-prefix = false |
| 174 | +``` |
| 175 | + |
| 176 | +Additionally, scikit-build-core reads the entry-point `cmake.prefix` and the |
| 177 | +option `search.prefixes` to prepend to this path list. You can similarly export |
| 178 | +this as |
| 179 | + |
| 180 | +``` toml |
| 181 | +[project.entry-points."cmake.prefix"] |
| 182 | +MyProject = "myproject" |
| 183 | +``` |
| 184 | + |
| 185 | +and you can similarly delete this entry-point variable |
| 186 | + |
| 187 | +````{tab} pyproject.toml |
| 188 | + |
| 189 | +```toml |
| 190 | +[tool.scikit-build.search.prefixes] |
| 191 | +MyProject = "" |
| 192 | +``` |
| 193 | + |
| 194 | +```` |
| 195 | + |
| 196 | +`````{tab} config-settings |
| 197 | +
|
| 198 | +
|
| 199 | +````{tab} pip |
| 200 | +
|
| 201 | +```console |
| 202 | +$ pip install . -v --config-settings=search.prefixes.MyProject="" |
| 203 | +``` |
| 204 | +
|
| 205 | +```` |
| 206 | +
|
| 207 | +````{tab} build |
| 208 | +
|
| 209 | +```console |
| 210 | +$ pipx run build --wheel -Csearch.prefixes.MyProject="" |
| 211 | +``` |
| 212 | +
|
| 213 | +```` |
| 214 | +
|
| 215 | +````{tab} cibuildwheel |
| 216 | +
|
| 217 | +```toml |
| 218 | +[tool.cibuildwheel.config-settings] |
| 219 | +"search.prefixes.MyProject" = "" |
| 220 | +``` |
| 221 | +
|
| 222 | +```` |
| 223 | +
|
| 224 | +````` |
| 225 | + |
| 226 | +````{tab} Environment |
| 227 | +
|
| 228 | +
|
| 229 | +```yaml |
| 230 | +SKBUILD_SEARCH_PREFIXES_MyProject: "" |
| 231 | +``` |
| 232 | +
|
| 233 | +```` |
| 234 | + |
| 235 | +If you only wish to expand the prefix path, you can also define |
| 236 | +`search.prefixes` as a list |
| 237 | + |
| 238 | +```toml |
| 239 | +[tool.scikit-build.search] |
| 240 | +prefixes = ["/path/to/prefixA", "/path/to/prefixB"] |
| 241 | +``` |
| 242 | + |
| 243 | +## `CMAKE_MODULE_PATH` |
| 244 | + |
| 245 | +Scikit-build-core also populates `CMAKE_MODULE_PATH` variable used to search |
| 246 | +for CMake modules using the `include()` command (if the `.cmake` suffix is |
| 247 | +omitted). |
| 248 | + |
| 249 | +This variable is populated from the entry-point `cmake.module` and the option |
| 250 | +`search.modules` similar to [`CMAKE_PREFIX_PATH`] section. |
| 251 | + |
| 252 | +[`CMAKE_PREFIX_PATH`]: #cmake-prefix-path |
0 commit comments