diff options
author | Alberto Invernizzi <9337627+albestro@users.noreply.github.com> | 2024-01-25 19:04:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-25 19:04:03 +0100 |
commit | 02a6ec7b3c2d487010a192eb6ecb201c4d1a6d2e (patch) | |
tree | 9d16b092445678e56bcd1b129e16081b2d86fa42 /lib | |
parent | d3c1f7a872a4097b74085b7275c338a1b52d96ae (diff) | |
download | spack-02a6ec7b3c2d487010a192eb6ecb201c4d1a6d2e.tar.gz spack-02a6ec7b3c2d487010a192eb6ecb201c4d1a6d2e.tar.bz2 spack-02a6ec7b3c2d487010a192eb6ecb201c4d1a6d2e.tar.xz spack-02a6ec7b3c2d487010a192eb6ecb201c4d1a6d2e.zip |
CMake: disable Package Registry (#42149)
CMake may write and read from `~/.cmake` through `export(...)` and read `find_package(...)` respectively. We don't want this as it may influence the build in a non-deterministic way, so disable it for all versions of `cmake`.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/build_systems/cmake.py | 48 | ||||
-rw-r--r-- | lib/spack/spack/spec.py | 8 |
2 files changed, 45 insertions, 11 deletions
diff --git a/lib/spack/spack/build_systems/cmake.py b/lib/spack/spack/build_systems/cmake.py index a92cb1b6b5..d66d531694 100644 --- a/lib/spack/spack/build_systems/cmake.py +++ b/lib/spack/spack/build_systems/cmake.py @@ -58,6 +58,44 @@ def _maybe_set_python_hints(pkg: spack.package_base.PackageBase, args: List[str] ) +def _conditional_cmake_defaults(pkg: spack.package_base.PackageBase, args: List[str]) -> None: + """Set a few default defines for CMake, depending on its version.""" + cmakes = pkg.spec.dependencies("cmake", dt.BUILD) + + if len(cmakes) != 1: + return + + cmake = cmakes[0] + + # CMAKE_INTERPROCEDURAL_OPTIMIZATION only exists for CMake >= 3.9 + try: + ipo = pkg.spec.variants["ipo"].value + except KeyError: + ipo = False + + if cmake.satisfies("@3.9:"): + args.append(CMakeBuilder.define("CMAKE_INTERPROCEDURAL_OPTIMIZATION", ipo)) + + # Disable Package Registry: export(PACKAGE) may put files in the user's home directory, and + # find_package may search there. This is not what we want. + + # Do not populate CMake User Package Registry + if cmake.satisfies("@3.15:"): + # see https://cmake.org/cmake/help/latest/policy/CMP0090.html + args.append(CMakeBuilder.define("CMAKE_POLICY_DEFAULT_CMP0090", "NEW")) + elif cmake.satisfies("@3.1:"): + # see https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY.html + args.append(CMakeBuilder.define("CMAKE_EXPORT_NO_PACKAGE_REGISTRY", True)) + + # Do not use CMake User/System Package Registry + # https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#disabling-the-package-registry + if cmake.satisfies("@3.16:"): + args.append(CMakeBuilder.define("CMAKE_FIND_USE_PACKAGE_REGISTRY", False)) + elif cmake.satisfies("@3.1:3.15"): + args.append(CMakeBuilder.define("CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY", False)) + args.append(CMakeBuilder.define("CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY", False)) + + def generator(*names: str, default: Optional[str] = None): """The build system generator to use. @@ -293,11 +331,6 @@ class CMakeBuilder(BaseBuilder): except KeyError: build_type = "RelWithDebInfo" - try: - ipo = pkg.spec.variants["ipo"].value - except KeyError: - ipo = False - define = CMakeBuilder.define args = [ "-G", @@ -306,10 +339,6 @@ class CMakeBuilder(BaseBuilder): define("CMAKE_BUILD_TYPE", build_type), ] - # CMAKE_INTERPROCEDURAL_OPTIMIZATION only exists for CMake >= 3.9 - if pkg.spec.satisfies("^cmake@3.9:"): - args.append(define("CMAKE_INTERPROCEDURAL_OPTIMIZATION", ipo)) - if primary_generator == "Unix Makefiles": args.append(define("CMAKE_VERBOSE_MAKEFILE", True)) @@ -318,6 +347,7 @@ class CMakeBuilder(BaseBuilder): [define("CMAKE_FIND_FRAMEWORK", "LAST"), define("CMAKE_FIND_APPBUNDLE", "LAST")] ) + _conditional_cmake_defaults(pkg, args) _maybe_set_python_hints(pkg, args) # Set up CMake rpath diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 767a69ee67..641ad1f5e9 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -1501,7 +1501,9 @@ class Spec: result = f"{deptypes_str} {virtuals_str}".strip() return f"[{result}]" - def dependencies(self, name=None, deptype: Union[dt.DepTypes, dt.DepFlag] = dt.ALL): + def dependencies( + self, name=None, deptype: Union[dt.DepTypes, dt.DepFlag] = dt.ALL + ) -> List["Spec"]: """Return a list of direct dependencies (nodes in the DAG). Args: @@ -1512,7 +1514,9 @@ class Spec: deptype = dt.canonicalize(deptype) return [d.spec for d in self.edges_to_dependencies(name, depflag=deptype)] - def dependents(self, name=None, deptype: Union[dt.DepTypes, dt.DepFlag] = dt.ALL): + def dependents( + self, name=None, deptype: Union[dt.DepTypes, dt.DepFlag] = dt.ALL + ) -> List["Spec"]: """Return a list of direct dependents (nodes in the DAG). Args: |