diff --git a/src/scikit_build_core/builder/builder.py b/src/scikit_build_core/builder/builder.py index 1db847a1..8492c469 100644 --- a/src/scikit_build_core/builder/builder.py +++ b/src/scikit_build_core/builder/builder.py @@ -123,19 +123,47 @@ def configure( } # Add any extra CMake modules - eps = metadata.entry_points(group="cmake.module") - self.config.module_dirs.extend(resources.files(ep.load()) for ep in eps) + module_dirs_dict = { + ep.name: resources.files(ep.load()) + for ep in metadata.entry_points(group="cmake.module") + } + if isinstance(self.settings.search.modules, dict): + # Allow to override any entry-point definition + module_dirs_dict.update(self.settings.search.modules) + module_dirs = list(module_dirs_dict.values()) + if isinstance(self.settings.search.modules, list): + # If it was a list, append to the entry-point definitions + module_dirs += self.settings.search.modules + # Remove any empty paths + module_dirs = [path for path in module_dirs if path] + self.config.module_dirs.extend(module_dirs) # Add any extra CMake prefixes - eps = metadata.entry_points(group="cmake.prefix") - self.config.prefix_dirs.extend(resources.files(ep.load()) for ep in eps) + prefix_dirs_dict = { + ep.name: resources.files(ep.load()) + for ep in metadata.entry_points(group="cmake.prefix") + } + if isinstance(self.settings.search.prefixes, dict): + # Allow to override any entry-point definition + prefix_dirs_dict.update(self.settings.search.prefixes) + prefix_dirs = list(prefix_dirs_dict.values()) + if isinstance(self.settings.search.prefixes, list): + # If it was a list, append to the entry-point definitions + prefix_dirs += self.settings.search.prefixes + # Remove any empty paths + prefix_dirs = [path for path in prefix_dirs if path] + self.config.prefix_dirs.extend(prefix_dirs) # Add all CMake roots - eps = metadata.entry_points(group="cmake.root") + prefix_roots = { + ep.name: resources.files(ep.load()) + for ep in metadata.entry_points(group="cmake.root") + } # TODO: Check for unique uppercase names - self.config.prefix_roots.update( - {ep.name: resources.files(ep.load()) for ep in eps} - ) + prefix_roots.update(self.settings.search.roots) + # Remove any empty paths + prefix_roots = {pkg: path for pkg, path in prefix_roots.items() if path} + self.config.prefix_roots.update(prefix_roots) # Add site-packages to the prefix path for CMake site_packages = Path(sysconfig.get_path("purelib")) diff --git a/src/scikit_build_core/settings/skbuild_model.py b/src/scikit_build_core/settings/skbuild_model.py index 200915c1..6b3bbba8 100644 --- a/src/scikit_build_core/settings/skbuild_model.py +++ b/src/scikit_build_core/settings/skbuild_model.py @@ -93,6 +93,23 @@ class SearchSettings: Add the wheel build path to the CMake prefix paths. """ + modules: Optional[Union[List[Path], Dict[str, Path]]] = None + """ + List or dict of CMake module search paths. Dict from is used to override + another package's entry-point definition. Populates `CMAKE_MODULE_PATH`. + """ + + prefixes: Optional[Union[List[Path], Dict[str, Path]]] = None + """ + List or dict of CMake prefix search paths. Dict from is used to override + another package's entry-point definition. Populates `CMAKE_PREFIX_PATH`. + """ + + roots: Dict[str, Path] = dataclasses.field(default_factory=dict) + """ + Dict of package names and prefix paths. Populates `_ROOT`. + """ + @dataclasses.dataclass class NinjaSettings: