CMakePackage pass python hints automatically (#42201)

This commit ensures that CMake packages that also have Python as a build/link dep get a couple defines for the Python path so that CMake's builtin `FindPython3`, `FindPython`, `FindPythonInterp` modules can locate Python correctly.

The main problem with those CMake modules is that they first search for Python versions known at the time of release, meaning that old CMake maybe find older system Python 3.8 even though Python 3.11 comes first in `CMAKE_PREFIX_PATH` and `PATH`.

Package maintainers can opt out of this by overriding the `find_python_hints = False` attribute in the package class.
This commit is contained in:
kwryankrattiger 2024-01-22 09:31:16 -06:00 committed by GitHub
parent b28692dc72
commit 2d9c6c3222
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
71 changed files with 111 additions and 325 deletions

View File

@ -15,6 +15,7 @@
import spack.build_environment
import spack.builder
import spack.deptypes as dt
import spack.package_base
from spack.directives import build_system, conflicts, depends_on, variant
from spack.multimethod import when
@ -31,8 +32,30 @@ def _extract_primary_generator(generator):
primary generator from the generator string which may contain an
optional secondary generator.
"""
primary_generator = _primary_generator_extractor.match(generator).group(1)
return primary_generator
return _primary_generator_extractor.match(generator).group(1)
def _maybe_set_python_hints(pkg: spack.package_base.PackageBase, args: List[str]) -> None:
"""Set the PYTHON_EXECUTABLE, Python_EXECUTABLE, and Python3_EXECUTABLE CMake variables
if the package has Python as build or link dep and ``find_python_hints`` is set to True. See
``find_python_hints`` for context."""
if not getattr(pkg, "find_python_hints", False):
return
pythons = pkg.spec.dependencies("python", dt.BUILD | dt.LINK)
if len(pythons) != 1:
return
try:
python_executable = pythons[0].package.command.path
except RuntimeError:
return
args.extend(
[
CMakeBuilder.define("PYTHON_EXECUTABLE", python_executable),
CMakeBuilder.define("Python_EXECUTABLE", python_executable),
CMakeBuilder.define("Python3_EXECUTABLE", python_executable),
]
)
def generator(*names: str, default: Optional[str] = None):
@ -86,6 +109,13 @@ class CMakePackage(spack.package_base.PackageBase):
#: Legacy buildsystem attribute used to deserialize and install old specs
legacy_buildsystem = "cmake"
#: When this package depends on Python and ``find_python_hints`` is set to True, pass the
#: defines {Python3,Python,PYTHON}_EXECUTABLE explicitly, so that CMake locates the right
#: Python in its builtin FindPython3, FindPython, and FindPythonInterp modules. Spack does
#: CMake's job because CMake's modules by default only search for Python versions known at the
#: time of release.
find_python_hints = True
build_system("cmake")
with when("build_system=cmake"):
@ -241,9 +271,9 @@ def std_cmake_args(self):
"""Standard cmake arguments provided as a property for
convenience of package writers
"""
std_cmake_args = CMakeBuilder.std_args(self.pkg, generator=self.generator)
std_cmake_args += getattr(self.pkg, "cmake_flag_args", [])
return std_cmake_args
args = CMakeBuilder.std_args(self.pkg, generator=self.generator)
args += getattr(self.pkg, "cmake_flag_args", [])
return args
@staticmethod
def std_args(pkg, generator=None):
@ -288,6 +318,8 @@ def std_args(pkg, generator=None):
[define("CMAKE_FIND_FRAMEWORK", "LAST"), define("CMAKE_FIND_APPBUNDLE", "LAST")]
)
_maybe_set_python_hints(pkg, args)
# Set up CMake rpath
args.extend(
[

View File

@ -458,10 +458,6 @@ def plugin_cmake_variant(plugin_name, spack_variant):
if cuda_arch != "none":
args.append(f"-DCUDA_FLAGS=-arch=sm_{cuda_arch[0]}")
if "+python" in spec:
python = spec["python"].command.path
args.append(f"-DPython_EXECUTABLE={python}")
args.append(self.define_from_variant("CMAKE_CXX_STANDARD", "cxxstd"))
return args

View File

@ -292,10 +292,6 @@ def cmake_args(self):
if "%fj" in spec:
args.extend(["-DCMAKE_Fortran_SUBMODULE_EXT=.smod", "-DCMAKE_Fortran_SUBMODULE_SEP=."])
if "+python" in spec or self.run_tests:
args.append(f"-DPYTHON_EXECUTABLE:FILEPATH={spec['python'].command.path}")
args.append(f"-DPython_EXECUTABLE:FILEPATH={spec['python'].command.path}")
# hip support
if "+cuda" in spec:
args.append(self.builder.define_cuda_architectures(self))

View File

@ -119,8 +119,6 @@ def cmake_args(self):
# different hosts.
args = [
# Choose a particular python version
"-DPYTHON_EXECUTABLE:FILEPATH=" + spec["python"].command.path,
#
# Hard-disable Jupyter, since this would override a config
# file in the user's home directory in some cases during

View File

@ -129,7 +129,6 @@ def cmake_args(self):
spec = self.spec
args = [
("-DPYTHON_EXECUTABLE=%s" % spec["python"].command.path),
"-DBUILD_TESTING=Off",
"-DBUILD_DOCS=Off",
self.define_from_variant("BUILD_SHARED_LIBS", "shared"),

View File

@ -91,22 +91,6 @@ def patch(self):
"clasp/libpotassco/CMakeLists.txt",
)
@property
def cmake_python_hints(self):
"""Return standard CMake defines to ensure that the
current spec is the one found by CMake find_package(Python, ...)
"""
python = self.spec["python"]
return [
self.define("Python_EXECUTABLE", python.command.path),
self.define("Python_INCLUDE_DIR", python.headers.directories[0]),
self.define("Python_LIBRARIES", python.libs[0]),
# XCode command line tools on macOS has no python-config executable, and
# CMake assumes you have python 2 if it does not find a python-config,
# so we set the version explicitly so that it's passed to FindPython.
self.define("CLINGO_PYTHON_VERSION", python.version.up_to(2)),
]
@property
def cmake_py_shared(self):
return self.define("CLINGO_BUILD_PY_SHARED", "ON")
@ -127,8 +111,6 @@ def cmake_args(self):
"-DPYCLINGO_USE_INSTALL_PREFIX=ON",
self.cmake_py_shared,
]
if self.spec["cmake"].satisfies("@3.16.0:"):
args += self.cmake_python_hints
else:
args += ["-DCLINGO_BUILD_WITH_PYTHON=OFF"]

View File

@ -33,6 +33,3 @@ class Cvise(CMakePackage):
depends_on("py-pytest", when="+pytest", type=("build", "run"))
depends_on("colordiff", when="+colordiff", type=("build", "run"))
def cmake_args(self):
return ["-DPYTHON_EXECUTABLE=" + self.spec["python"].command.path]

View File

@ -232,7 +232,6 @@ def cmake_args(self):
"-DBUILD_TESTING={0}".format(self.run_tests),
"-DBOOST_ROOT={0}".format(spec["boost"].prefix),
"-DBoost_NO_BOOST_CMAKE=ON",
"-DPYTHON_EXECUTABLE={0}".format(spec["python"].command.path),
]
subpackages = []
if spec.satisfies("+ddg4"):

View File

@ -539,17 +539,6 @@ def cmake_args(self):
# Python bindings
if spec.satisfies("@8.5.0:"):
options.append(self.define_from_variant("DEAL_II_COMPONENT_PYTHON_BINDINGS", "python"))
if "+python" in spec:
python_exe = spec["python"].command.path
python_library = spec["python"].libs[0]
python_include = spec["python"].headers.directories[0]
options.extend(
[
self.define("PYTHON_EXECUTABLE", python_exe),
self.define("PYTHON_INCLUDE_DIR", python_include),
self.define("PYTHON_LIBRARY", python_library),
]
)
# Simplex support (no longer experimental)
if spec.satisfies("@9.3.0:9.4.0"):

View File

@ -124,12 +124,3 @@ def patch(self):
join_path("cmake", "FindIconv.cmake"),
string=True,
)
def cmake_args(self):
args = [
# Doxygen's build system uses CMake's deprecated `FindPythonInterp`,
# which can get confused by other `python` executables in the PATH.
# See issue: https://github.com/spack/spack/issues/28215
self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path)
]
return args

View File

@ -351,9 +351,6 @@ def cmake_args(self):
# Prevent overriding by environment variables AEC_DIR and AEC_PATH:
args.append(self.define("AEC_DIR", self.spec["libaec"].prefix))
if "+memfs" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", python.path))
return args
@run_after("install")

View File

@ -91,7 +91,6 @@ def cmake_args(self):
self.define_from_variant("ENABLE_SSL", "ssl"),
# https://jira.ecmwf.int/browse/SUP-2641#comment-208943
self.define_from_variant("ENABLE_STATIC_BOOST_LIBS", "static_boost"),
self.define("Python3_EXECUTABLE", spec["python"].package.command),
self.define("BOOST_ROOT", spec["boost"].prefix),
self.define_from_variant("CMAKE_POSITION_INDEPENDENT_CODE", "pic"),
]

View File

@ -73,7 +73,6 @@ def cmake_args(self):
self.define_from_variant("ENABLE_TRANS", "trans"),
self.define_from_variant("ENABLE_EIGEN", "eigen"),
self.define_from_variant("ENABLE_FFTW", "fftw"),
"-DPYTHON_EXECUTABLE:FILEPATH=" + self.spec["python"].command.path,
]
if "~shared" in self.spec:
args.append("-DBUILD_SHARED_LIBS=OFF")

View File

@ -96,9 +96,6 @@ def cmake_args(self):
self.define_from_variant("BUILD_TESTING", "tests"),
self.define("FAISS_OPT_LEVEL", "generic"),
]
if "+python" in spec:
pyexe = spec["python"].command.path
args.append(self.define("Python_EXECUTABLE", pyexe))
if "+cuda" in spec:
key = "CMAKE_CUDA_ARCHITECTURES"

View File

@ -62,7 +62,6 @@ def cmake_args(self):
args = [
self.define_from_variant("ENABLE_ECKIT", "eckit"),
self.define_from_variant("ENABLE_OMP", "openmp"),
"-DPYTHON_EXECUTABLE:FILEPATH=" + self.spec["python"].command.path,
"-DFYPP_NO_LINE_NUMBERING=ON",
]

View File

@ -123,8 +123,4 @@ def cmake_args(self):
use_mpi = "ON" if "+mpi" in spec else "OFF"
args.append("-DUSE_MPI:BOOL={0}".format(use_mpi))
# Configure the proper python executable
if "+python" in spec:
args.append("-DPYTHON_EXECUTABLE={0}".format(spec["python"].command.path))
return args

View File

@ -70,10 +70,7 @@ class Gnina(CMakePackage, CudaPackage):
depends_on("cudnn", when="+cudnn")
def cmake_args(self):
args = [
"-DBLAS=Open", # Use OpenBLAS instead of Atlas' BLAS
f"-DPYTHON_EXECUTABLE={self.spec['python'].command.path}",
]
args = ["-DBLAS=Open"] # Use OpenBLAS instead of Atlas' BLAS
if "+gninavis" in self.spec:
args.append(f"-DRDKIT_INCLUDE_DIR={self.spec['rdkit'].prefix.include.rdkit}")

View File

@ -61,10 +61,7 @@ class Gnuradio(CMakePackage):
extends("python")
def cmake_args(self):
args = []
args.append("-DPYTHON_EXECUTABLE={0}".format(self.spec["python"].command.path))
args.append("-DENABLE_INTERNAL_VOLK=OFF")
return args
return ["-DENABLE_INTERNAL_VOLK=OFF"]
def setup_dependent_build_environment(self, env, dependent_spec):
env.prepend_path("XDG_DATA_DIRS", self.prefix.share)

View File

@ -108,7 +108,6 @@ def cmake_args(self):
if "+python" in spec:
args += [
self.define("Python3_EXECUTABLE", spec["python"].command.path),
self.define("PYBIND11_USE_FETCHCONTENT", False),
self.define("Halide_INSTALL_PYTHONDIR", python_platlib),
]

View File

@ -32,13 +32,8 @@ class Henson(CMakePackage):
conflicts("^openmpi", when="+mpi-wrappers")
def cmake_args(self):
args = [
return [
self.define_from_variant("python", "python"),
self.define_from_variant("mpi-wrappers", "mpi-wrappers"),
self.define_from_variant("use_boost", "boost"),
]
if self.spec.satisfies("+python"):
args += [self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path)]
return args

View File

@ -65,10 +65,7 @@ class HoomdBlue(CMakePackage):
def cmake_args(self):
spec = self.spec
cmake_args = [
"-DPYTHON_EXECUTABLE={0}".format(spec["python"].command.path),
"-DCMAKE_INSTALL_PREFIX={0}".format(python_platlib),
]
cmake_args = ["-DCMAKE_INSTALL_PREFIX={0}".format(python_platlib)]
# MPI support
if "+mpi" in spec:

View File

@ -860,9 +860,6 @@ def cmake_args(self):
if "+rocm" in spec:
args.append(self.define("CMAKE_CXX_COMPILER", spec["hip"].hipcc))
if "+python" in spec:
args.append(self.define("Python_EXECUTABLE", spec["python"].command.path))
return args
def setup_build_environment(self, env):

View File

@ -35,9 +35,4 @@ def cmake_args(self):
ob_incl = os.path.join(self.spec["openbabel"].prefix.include, "openbabel3")
ob_libs = self.spec["openbabel"].libs.joined(";")
args = [
"-DOPENBABEL3_INCLUDE_DIR=" + ob_incl,
"-DOPENBABEL3_LIBRARIES=" + ob_libs,
f"-DPYTHON_EXECUTABLE={self.spec['python'].command.path}",
]
return args
return ["-DOPENBABEL3_INCLUDE_DIR=" + ob_incl, "-DOPENBABEL3_LIBRARIES=" + ob_libs]

View File

@ -278,7 +278,6 @@ def cmake_args(self):
if "+python" in self.spec:
args.append("-DLIBPRESSIO_PYTHON_SITELIB={0}".format(python_platlib))
args.append("-DBUILD_PYTHON_WRAPPER=ON")
args.append("-DPython3_EXECUTABLE={0}".format(self.spec["python"].command))
if "+mpi" in self.spec:
args.append("-DLIBPRESSIO_HAS_MPI4PY=ON")
if "+hdf5" in self.spec:

View File

@ -405,13 +405,11 @@ def cmake_args(self):
define = self.define
from_variant = self.define_from_variant
python = spec["python"]
cmake_args = [
define("LLVM_REQUIRES_RTTI", True),
define("LLVM_ENABLE_RTTI", True),
define("LLVM_ENABLE_EH", True),
define("CLANG_DEFAULT_OPENMP_RUNTIME", "libomp"),
define("PYTHON_EXECUTABLE", python.command.path),
define("LIBOMP_USE_HWLOC", True),
define("LIBOMP_HWLOC_INSTALL_DIR", spec["hwloc"].prefix),
]
@ -420,11 +418,6 @@ def cmake_args(self):
if version_suffix != "none":
cmake_args.append(define("LLVM_VERSION_SUFFIX", version_suffix))
if python.version >= Version("3"):
cmake_args.append(define("Python3_EXECUTABLE", python.command.path))
else:
cmake_args.append(define("Python2_EXECUTABLE", python.command.path))
projects = []
runtimes = []

View File

@ -781,13 +781,11 @@ def cmake_args(self):
define = self.define
from_variant = self.define_from_variant
python = spec["python"]
cmake_args = [
define("LLVM_REQUIRES_RTTI", True),
define("LLVM_ENABLE_RTTI", True),
define("LLVM_ENABLE_LIBXML2", False),
define("CLANG_DEFAULT_OPENMP_RUNTIME", "libomp"),
define("PYTHON_EXECUTABLE", python.command.path),
define("LIBOMP_USE_HWLOC", True),
define("LIBOMP_HWLOC_INSTALL_DIR", spec["hwloc"].prefix),
from_variant("LLVM_ENABLE_ZSTD", "zstd"),
@ -811,11 +809,6 @@ def cmake_args(self):
if shlib_symbol_version is not None and shlib_symbol_version.value != "none":
cmake_args.append(define("LLVM_SHLIB_SYMBOL_VERSION", shlib_symbol_version.value))
if python.version >= Version("3"):
cmake_args.append(define("Python3_EXECUTABLE", python.command.path))
else:
cmake_args.append(define("Python2_EXECUTABLE", python.command.path))
projects = []
runtimes = []

View File

@ -86,9 +86,6 @@ def cmake_options(spec_options):
if "~mpi" in spec and "+coreneuron" in spec:
args.append("-DCORENRN_ENABLE_MPI=OFF")
if "+python" in spec:
args.append("-DPYTHON_EXECUTABLE:FILEPATH=" + spec["python"].command.path)
if spec.variants["build_type"].value == "Debug":
args.append("-DCMAKE_C_FLAGS=-g -O0")
args.append("-DCMAKE_CXX_FLAGS=-g -O0")

View File

@ -53,16 +53,12 @@ def cmake_args(self):
# Specify on command line to alter defaults:
# eg: spack install nlopt@master +guile -octave +cxx
# Spack should locate python by default - but to point to a build
if "+python" in spec:
args.append("-DPYTHON_EXECUTABLE=%s" % spec["python"].command.path)
# On is default
if "-shared" in spec:
if "~shared" in spec:
args.append("-DBUILD_SHARED_LIBS:Bool=OFF")
# On is default
if "-octave" in spec:
if "~octave" in spec:
args.append("-DNLOPT_OCTAVE:Bool=OFF")
if "+cxx" in spec:

View File

@ -41,8 +41,4 @@ class Odgi(CMakePackage):
# >>> Dependencies list ends here
def cmake_args(self):
args = [
"-DCMAKE_CXX_STANDARD_REQUIRED:BOOL=ON",
"-DPYTHON_EXECUTABLE:FILEPATH={0}".format(self.spec["python"].command),
]
return args
return ["-DCMAKE_CXX_STANDARD_REQUIRED:BOOL=ON"]

View File

@ -126,11 +126,6 @@ def cmake_args(self):
tau_root = spec["tau"].prefix
args.append(self.define("TAU_ROOT_DIR", tau_root))
if "+python" in spec:
pyexe = spec["python"].command.path
args.append(self.define("PYTHON_EXECUTABLE", pyexe))
args.append(self.define("Python3_EXECUTABLE", pyexe))
if "+mpi" in spec:
args.append(self.define("MPI_C_COMPILER", spec["mpi"].mpicc))
args.append(self.define("MPI_CXX_COMPILER", spec["mpi"].mpicxx))

View File

@ -70,7 +70,7 @@ def patch(self):
)
def cmake_args(self):
args = [
return [
self.define("BUILD_UNIT_TESTS", self.run_tests),
self.define_from_variant("BUILD_PYTHON_MODULE", "python"),
self.define_from_variant("BUILD_CUDA_MODULE", "cuda"),
@ -95,11 +95,6 @@ def cmake_args(self):
# self.define('USE_SYSTEM_TINYOBJLOADER', True),
]
if "+python" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path))
return args
def check(self):
with working_dir(self.build_directory):
tests = Executable(os.path.join("bin", "tests"))

View File

@ -63,13 +63,7 @@ def cmake_args(self):
args = []
if "+python" in spec:
args.extend(
[
"-DPYTHON_BINDINGS=ON",
"-DPYTHON_EXECUTABLE={0}".format(spec["python"].command.path),
"-DRUN_SWIG=ON",
]
)
args.extend(["-DPYTHON_BINDINGS=ON", "-DRUN_SWIG=ON"])
else:
args.append("-DPYTHON_BINDINGS=OFF")

View File

@ -15,6 +15,7 @@ class Opencv(CMakePackage, CudaPackage):
homepage = "https://opencv.org/"
url = "https://github.com/opencv/opencv/archive/4.5.0.tar.gz"
git = "https://github.com/opencv/opencv.git"
find_python_hints = False # opencv uses custom OpenCVDetectPython.cmake
maintainers("bvanessen", "adamjstewart")

View File

@ -44,11 +44,7 @@ def setup_run_environment(self, env):
env.append_path("PATH", self.prefix)
def cmake_args(self):
args = [
"-DLINALG=OpenBLAS",
"-DOPENBLASROOT=%s" % self.spec["openblas"].prefix,
"-DPYTHON_EXECUTABLE=%s" % self.spec["python"].command.path,
]
args = ["-DLINALG=OpenBLAS", "-DOPENBLASROOT=%s" % self.spec["openblas"].prefix]
if "+mpi" in self.spec:
mpi_args = [
"-DMPI=ON",

View File

@ -123,13 +123,7 @@ def cmake_args(self):
# switch internally shipped third-party libraries for spack
if spec.satisfies("+python"):
py_exe_define = (
"Python_EXECUTABLE" if spec.version >= Version("0.13.0") else "PYTHON_EXECUTABLE"
)
args += [
self.define(py_exe_define, self.spec["python"].command.path),
self.define("openPMD_USE_INTERNAL_PYBIND11", False),
]
args.append(self.define("openPMD_USE_INTERNAL_PYBIND11", False))
args.append(self.define("openPMD_USE_INTERNAL_JSON", False))
if spec.satisfies("@:0.14"): # pre C++17 releases

View File

@ -236,26 +236,19 @@ def set_defaultbase_cmake_options(self, spec, cmake_options):
# Appends to cmake_options the options that will enable
# the appropriate base level options to the openspeedshop
# cmake build.
python_exe = spec["python"].command.path
python_library = spec["python"].libs[0]
python_include = spec["python"].headers.directories[0]
base_options = []
base_options.append("-DBINUTILS_DIR=%s" % spec["binutils"].prefix)
base_options.append("-DLIBELF_DIR=%s" % spec["elfutils"].prefix)
base_options.append("-DLIBDWARF_DIR=%s" % spec["libdwarf"].prefix)
base_options.append("-DPYTHON_EXECUTABLE=%s" % python_exe)
base_options.append("-DPYTHON_INCLUDE_DIR=%s" % python_include)
base_options.append("-DPYTHON_LIBRARY=%s" % python_library)
base_options.append("-DBoost_NO_SYSTEM_PATHS=TRUE")
base_options.append("-DBoost_NO_BOOST_CMAKE=TRUE")
base_options.append("-DBOOST_ROOT=%s" % spec["boost"].prefix)
base_options.append("-DBoost_DIR=%s" % spec["boost"].prefix)
base_options.append("-DBOOST_LIBRARYDIR=%s" % spec["boost"].prefix.lib)
base_options.append("-DDYNINST_DIR=%s" % spec["dyninst"].prefix)
cmake_options.extend(base_options)
cmake_options.extend(
[
self.define("BINUTILS_DIR", spec["binutils"].prefix),
self.define("LIBELF_DIR", spec["elfutils"].prefix),
self.define("LIBDWARF_DIR", spec["libdwarf"].prefix),
self.define("Boost_NO_SYSTEM_PATHS", True),
self.define("Boost_NO_BOOST_CMAKE", True),
self.define("BOOST_ROOT", spec["boost"].prefix),
self.define("Boost_DIR", spec["boost"].prefix),
self.define("BOOST_LIBRARYDIR", spec["boost"].prefix.lib),
self.define("DYNINST_DIR", spec["dyninst"].prefix),
]
)
def set_mpi_cmake_options(self, spec, cmake_options):
# Appends to cmake_options the options that will enable

View File

@ -254,27 +254,19 @@ def set_defaultbase_cmake_options(self, spec, cmake_options):
# Appends to cmake_options the options that will enable
# the appropriate base level options to the openspeedshop
# cmake build.
python_exe = spec["python"].command.path
python_library = spec["python"].libs[0]
python_include = spec["python"].headers.directories[0]
true_value = "TRUE"
base_options = []
base_options.append("-DBINUTILS_DIR=%s" % spec["binutils"].prefix)
base_options.append("-DLIBELF_DIR=%s" % spec["elfutils"].prefix)
base_options.append("-DLIBDWARF_DIR=%s" % spec["libdwarf"].prefix)
base_options.append("-DPYTHON_EXECUTABLE=%s" % python_exe)
base_options.append("-DPYTHON_INCLUDE_DIR=%s" % python_include)
base_options.append("-DPYTHON_LIBRARY=%s" % python_library)
base_options.append("-DBoost_NO_SYSTEM_PATHS=%s" % true_value)
base_options.append("-DBoost_NO_BOOST_CMAKE=%s" % true_value)
base_options.append("-DBOOST_ROOT=%s" % spec["boost"].prefix)
base_options.append("-DBoost_DIR=%s" % spec["boost"].prefix)
base_options.append("-DBOOST_LIBRARYDIR=%s" % spec["boost"].prefix.lib)
base_options.append("-DDYNINST_DIR=%s" % spec["dyninst"].prefix)
cmake_options.extend(base_options)
cmake_options.extend(
[
self.define("BINUTILS_DIR", spec["binutils"].prefix),
self.define("LIBELF_DIR", spec["elfutils"].prefix),
self.define("LIBDWARF_DIR", spec["libdwarf"].prefix),
self.define("Boost_NO_SYSTEM_PATHS", True),
self.define("Boost_NO_BOOST_CMAKE", True),
self.define("BOOST_ROOT", spec["boost"].prefix),
self.define("Boost_DIR", spec["boost"].prefix),
self.define("BOOST_LIBRARYDIR", spec["boost"].prefix.lib),
self.define("DYNINST_DIR", spec["dyninst"].prefix),
]
)
def set_mpi_cmake_options(self, spec, cmake_options):
# Appends to cmake_options the options that will enable

View File

@ -59,10 +59,8 @@ def cmake_args(self):
if "+python" in spec:
args.extend(
[
# By default picks up the system python not the Spack build
"-DPYTHON_EXECUTABLE={0}".format(spec["python"].command.path),
# By default installs to the python prefix
"-DPYTHON_SITE_PACKAGES={0}".format(python_platlib),
"-DPYTHON_SITE_PACKAGES={0}".format(python_platlib)
]
)

View File

@ -55,7 +55,6 @@ def cmake_args(self):
arg.extend([define("BUILD_PYTHON", False), define("BUILD_PYTHON3", True)])
else:
arg.extend([define("BUILD_PYTHON", True), define("BUILD_PYTHON3", False)])
arg.append(define("PYTHON_EXECUTABLE", spec["python"].command.path))
else:
arg.extend([define("BUILD_PYTHON", False), define("BUILD_PYTHON3", False)])
return arg

View File

@ -99,10 +99,8 @@ def cmake_args(self):
if "+python" in spec:
args.extend(
[
# By default picks up the system python not the Spack build
"-DPYTHON_EXECUTABLE={0}".format(spec["python"].command.path),
# By default installs to the python prefix not the pagmo prefix
"-DPYTHON_MODULES_DIR={0}".format(python_platlib),
"-DPYTHON_MODULES_DIR={0}".format(python_platlib)
]
)

View File

@ -537,7 +537,6 @@ def use_x11():
cmake_args.extend(
[
"-DPARAVIEW_%s_PYTHON:BOOL=ON" % py_use_opt,
"-DPYTHON_EXECUTABLE:FILEPATH=%s" % spec["python"].command.path,
"-D%s_PYTHON_VERSION:STRING=%d" % (py_ver_opt, py_ver_val),
]
)

View File

@ -152,7 +152,6 @@ def url_for_version(self, version):
def cmake_args(self):
spec = self.spec
args = [
self.define("Python_EXECUTABLE", spec["python"].command),
self.define("BUILD_SHARED_LIBS", False),
self.define("CMAKE_Fortran_MODULE_DIRECTORY", spec.prefix.include),
self.define_from_variant("ENABLE_BUILD_DOXYGEN", "docs"),

View File

@ -172,7 +172,8 @@ def cmake_args(self):
cmake_args.extend(["-DPETSC_DIR=%s" % spec["petsc"].prefix, "-DPETSC_ARCH=."])
# Python
if "+python" in spec:
if "@:2.3 +python" in spec:
# 2.4.0 and higher use find_package(Python3).
python_library = spec["python"].libs[0]
python_include = spec["python"].headers.directories[0]
numpy_include = join_path(

View File

@ -84,10 +84,7 @@ def patch(self):
class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
def cmake_args(self):
return [
self.define("PYTHON_EXECUTABLE:FILEPATH", self.spec["python"].command.path),
self.define("PYBIND11_TEST", self.pkg.run_tests),
]
return [self.define("PYBIND11_TEST", self.pkg.run_tests)]
def install(self, pkg, spec, prefix):
super().install(pkg, spec, prefix)

View File

@ -44,13 +44,9 @@ class PyPykokkosBase(CMakePackage, PythonExtension):
depends_on("python@3:", type=("build", "run"))
def cmake_args(self):
spec = self.spec
args = [
self.define("ENABLE_INTERNAL_KOKKOS", False),
self.define("ENABLE_INTERNAL_PYBIND11", False),
self.define("PYTHON_EXECUTABLE", spec["python"].command.path),
self.define("Python3_EXECUTABLE", spec["python"].command.path),
self.define_from_variant("ENABLE_VIEW_RANKS", "view_ranks"),
]

View File

@ -33,14 +33,7 @@ class PyTfdlpack(CMakePackage, PythonExtension):
depends_on("py-tensorflow", type=("build", "run"))
def cmake_args(self):
args = ["-DPYTHON_EXECUTABLE=" + self.spec["python"].command.path]
if "+cuda" in self.spec:
args.append("-DUSE_CUDA=ON")
else:
args.append("-DUSE_CUDA=OFF")
return args
return [self.define_from_variant("USE_CUDA", "cuda")]
def install(self, spec, prefix):
with working_dir("python"):

View File

@ -391,7 +391,6 @@ def cmake_args(self):
else:
args.append("-DBUILD_PPCONVERT=0")
args.append(self.define("Python3_EXECUTABLE", self.spec["python"].command.path))
return args
# QMCPACK needs custom install method for the following reason:

View File

@ -107,11 +107,4 @@ def cmake_args(self):
if self.spec.satisfies("~man_pages"):
cmake_args.append("-DNO_MAN_PAGES=1")
if self.spec.satisfies("@:39.0"):
cmake_args.extend(
[
self.define("PYTHON_LIBRARY", self.spec["python"].libs[0]),
self.define("PYTHON_INCLUDE_DIR", self.spec["python"].headers.directories[0]),
]
)
return cmake_args

View File

@ -511,7 +511,6 @@ def _add_variant(variants, features, featurename, variantname):
return " ".join(v)
def cmake_args(self):
spec = self.spec
define = self.define
define_from_variant = self.define_from_variant
options = []
@ -694,9 +693,6 @@ def cmake_args(self):
ftgl_prefix = self.spec["ftgl"].prefix
options.append(define("FTGL_ROOT_DIR", ftgl_prefix))
options.append(define("FTGL_INCLUDE_DIR", ftgl_prefix.include))
if "+python" in self.spec:
# See https://github.com/spack/spack/pull/11579
options.append(define("PYTHON_EXECUTABLE", spec["python"].command.path))
return options

View File

@ -51,11 +51,8 @@ def patch(self):
)
def cmake_args(self):
args = [
return [
self.define("SCINE_BUILD_TESTS", self.run_tests),
self.define("SCINE_BUILD_PYTHON_BINDINGS", "+python" in self.spec),
self.define("SCINE_MARCH", ""),
]
if "+python" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path))
return args

View File

@ -84,7 +84,7 @@ def patch(self):
)
def cmake_args(self):
args = [
return [
self.define("BUILD_SHARED_LIBS", True),
self.define("SCINE_BUILD_TESTS", self.run_tests),
self.define("SCINE_BUILD_PYTHON_BINDINGS", "+python" in self.spec),
@ -95,6 +95,3 @@ def cmake_args(self):
self.define("BOOST_NO_SYSTEM_PATHS", True),
self.define("Boost_NO_BOOST_CMAKE", True),
]
if "+python" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path))
return args

View File

@ -54,7 +54,7 @@ def patch(self):
)
def cmake_args(self):
args = [
return [
self.define("SCINE_BUILD_TESTS", self.run_tests),
self.define("SCINE_BUILD_PYTHON_BINDINGS", "+python" in self.spec),
self.define("SCINE_MARCH", ""),
@ -64,6 +64,3 @@ def cmake_args(self):
self.define("BOOST_NO_SYSTEM_PATHS", True),
self.define("Boost_NO_BOOST_CMAKE", True),
]
if "+python" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path))
return args

View File

@ -57,7 +57,7 @@ def patch(self):
)
def cmake_args(self):
args = [
return [
self.define("SCINE_BUILD_TESTS", self.run_tests),
self.define_from_variant("SCINE_BUILD_PYTHON_BINDINGS", "python"),
self.define("SCINE_MARCH", ""),
@ -69,6 +69,3 @@ def cmake_args(self):
self.define("BOOST_NO_SYSTEM_PATHS", True),
self.define("Boost_NO_BOOST_CMAKE", True),
]
if "+python" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path))
return args

View File

@ -76,7 +76,7 @@ def patch(self):
)
def cmake_args(self):
args = [
return [
self.define("SCINE_BUILD_TESTS", self.run_tests),
self.define("SCINE_BUILD_PYTHON_BINDINGS", "+python" in self.spec),
self.define("SCINE_MARCH", ""),
@ -86,9 +86,6 @@ def cmake_args(self):
self.define("BOOST_NO_SYSTEM_PATHS", True),
self.define("Boost_NO_BOOST_CMAKE", True),
]
if "+python" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path))
return args
# Adapted from ddd in MacPorts: cmake will build the executable
# "sparrow" right next to the copy of the source directory "Sparrow".

View File

@ -67,7 +67,7 @@ def patch(self):
)
def cmake_args(self):
args = [
return [
self.define("SCINE_BUILD_TESTS", self.run_tests),
self.define_from_variant("SCINE_BUILD_PYTHON_BINDINGS", "python"),
self.define("SCINE_MARCH", ""),
@ -77,7 +77,3 @@ def cmake_args(self):
self.define("BOOST_NO_SYSTEM_PATHS", True),
self.define("Boost_NO_BOOST_CMAKE", True),
]
if "+python" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path))
return args

View File

@ -52,7 +52,7 @@ def patch(self):
os.rename("_dev", "dev")
def cmake_args(self):
args = [
return [
self.define("SCINE_BUILD_TESTS", self.run_tests),
self.define("SCINE_BUILD_PYTHON_BINDINGS", "+python" in self.spec),
self.define("SCINE_MARCH", ""),
@ -62,6 +62,3 @@ def cmake_args(self):
self.define("BOOST_NO_SYSTEM_PATHS", True),
self.define("Boost_NO_BOOST_CMAKE", True),
]
if "+python" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path))
return args

View File

@ -116,27 +116,30 @@ class Sensei(CMakePackage):
def cmake_args(self):
spec = self.spec
prefix = ""
if spec.satisfies("@5:"):
prefix = "SENSEI_"
# -Ox flags are set by default in CMake based on the build type
args = [
self.define_from_variant("BUILD_SHARED_LIBS", "shared"),
self.define("SENSEI_USE_EXTERNAL_pugixml", True),
self.define("ENABLE_SENSEI", True),
self.define(f"{prefix}ENABLE_SENSEI", True),
self.define("MPI_C_COMPILER", spec["mpi"].mpicc),
self.define("MPI_CXX_COMPILER", spec["mpi"].mpicxx),
# Don"t rely on MPI found in cray environment for cray systems.
# On non-cray systems this should be a no-op
self.define("ENABLE_CRAY_MPICH", False),
self.define_from_variant("ENABLE_ASCENT", "ascent"),
self.define_from_variant("ENABLE_VTKM", "vtkm"),
self.define_from_variant("ENABLE_CATALYST", "catalyst"),
self.define_from_variant("ENABLE_LIBSIM", "libsim"),
self.define_from_variant("ENABLE_VTK_IO", "vtkio"),
self.define_from_variant("ENABLE_PYTHON", "python"),
self.define_from_variant("ENABLE_ADIOS2", "adios2"),
self.define_from_variant("ENABLE_HDF5", "hdf5"),
self.define_from_variant("ENABLE_PARALLEL3D", "miniapps"),
self.define_from_variant("ENABLE_OSCILLATORS", "miniapps"),
self.define(f"{prefix}ENABLE_CRAY_MPICH", False),
self.define_from_variant(f"{prefix}ENABLE_ASCENT", "ascent"),
self.define_from_variant(f"{prefix}ENABLE_VTKM", "vtkm"),
self.define_from_variant(f"{prefix}ENABLE_CATALYST", "catalyst"),
self.define_from_variant(f"{prefix}ENABLE_LIBSIM", "libsim"),
self.define_from_variant(f"{prefix}ENABLE_VTK_IO", "vtkio"),
self.define_from_variant(f"{prefix}ENABLE_PYTHON", "python"),
self.define_from_variant(f"{prefix}ENABLE_ADIOS2", "adios2"),
self.define_from_variant(f"{prefix}ENABLE_HDF5", "hdf5"),
self.define_from_variant(f"{prefix}ENABLE_PARALLEL3D", "miniapps"),
self.define_from_variant(f"{prefix}ENABLE_OSCILLATORS", "miniapps"),
]
if "+adios2" in spec:
@ -151,11 +154,8 @@ def cmake_args(self):
args.append("-DVISIT_DIR:PATH={0}/current/linux-x86_64".format(spec["visit"].prefix))
if "+python" in spec:
args.append(self.define("PYTHON_EXECUTABLE", spec["python"].command.path))
args.append(self.define("Python_EXECUTABLE", spec["python"].command.path))
args.append(self.define("Python3_EXECUTABLE", spec["python"].command.path))
if spec.satisfies("@3:"):
args.append(self.define("SENSEI_PYTHON_VERSION", 3))
args.append(self.define_from_variant("ENABLE_CATALYST_PYTHON", "catalyst"))
args.append(self.define_from_variant(f"{prefix}ENABLE_CATALYST_PYTHON", "catalyst"))
return args

View File

@ -115,7 +115,7 @@ def patch(self):
)
def cmake_args(self):
args = [
return [
self.define("SERENITY_BUILD_TESTS", self.run_tests),
self.define_from_variant("SERENITY_BUILD_PYTHON_BINDINGS", "python"),
self.define("SERENITY_MARCH", ""),
@ -137,6 +137,3 @@ def cmake_args(self):
self.define("BOOST_NO_SYSTEM_PATHS", True),
self.define("Boost_NO_BOOST_CMAKE", True),
]
if "+python" in self.spec:
args.append(self.define("PYTHON_EXECUTABLE", self.spec["python"].command.path))
return args

View File

@ -259,7 +259,6 @@ def cmake_args(self):
"-DLLVM_ENABLE_RTTI:BOOL=ON",
"-DLLVM_ENABLE_EH:BOOL=ON",
"-DCLANG_DEFAULT_OPENMP_RUNTIME:STRING=libomp",
"-DPYTHON_EXECUTABLE:PATH={0}".format(spec["python"].command.path),
]
# TODO: Instead of unconditionally disabling CUDA, add a "cuda" variant

View File

@ -307,7 +307,6 @@ def cmake_args(self):
args = [
self.define("CHARM_ROOT", self.spec["charmpp"].prefix),
self.define_from_variant("BUILD_SHARED_LIBS", "shared"),
self.define("Python_EXECUTABLE", self.spec["python"].command.path),
self.define_from_variant("BUILD_PYTHON_BINDINGS", "python"),
self.define("BUILD_TESTING", self.run_tests),
self.define_from_variant("BUILD_DOCS", "doc"),

View File

@ -85,7 +85,6 @@ def patch(self):
def cmake_args(self):
args = [
self.define("BLAS_LIBRARIES", self.spec["blas"].libs.joined(";")),
self.define("PYTHON_EXECUTABLE", self.spec["python"].command),
self.define("STEPS_INSTALL_PYTHON_DEPS", False),
self.define_from_variant("BUILD_STOCHASTIC_TESTS", "stochtests"),
self.define_from_variant("BUILD_TESTING", "codechecks"),

View File

@ -114,11 +114,6 @@ def cmake_args(self):
args.append("-DBLAS_LIBRARIES={0}".format(spec["blas"].libs.joined(";")))
args.append("-DLAPACK_LIBRARIES={0}".format(spec["lapack"].libs.joined(";")))
if spec.satisfies("+python"):
args.append(
"-DPYTHON_EXECUTABLE:FILEPATH={0}".format(self.spec["python"].command.path)
)
return args
@run_after("install")

View File

@ -128,7 +128,6 @@ def cmake_args(self):
cmake_args = [
"-DLLVM_REQUIRES_RTTI:BOOL=ON",
"-DCLANG_DEFAULT_OPENMP_RUNTIME:STRING=libomp",
"-DPYTHON_EXECUTABLE:PATH={0}".format(spec["python"].command.path),
"-DLLVM_EXTERNAL_POLLY_BUILD:Bool=OFF",
"-DLLVM_TOOL_POLLY_BUILD:Bool=OFF",
"-DLLVM_POLLY_BUILD:Bool=OFF",

View File

@ -180,6 +180,8 @@ def cmake_args(self):
args.append("-Denable-python-bindings=OFF")
if ("+python" in self.spec) or ("+python_bindings" in self.spec):
# Note: calls find_package(PythonLibs) before find_package(PythonInterp), so these
# variables are required.
python = self.spec["python"]
args.append("-DPYTHON_LIBRARY={0}".format(python.libs[0]))
args.append("-DPYTHON_INCLUDE_DIR={0}".format(python.headers.directories[0]))

View File

@ -322,11 +322,6 @@ def cmake_args(self):
self.define_from_variant("TIMEMORY_USE_ALLINEA_MAP", "allinea_map"),
]
if "+python" in spec:
pyexe = spec["python"].command.path
args.append(self.define("PYTHON_EXECUTABLE=", pyexe))
args.append(self.define("Python3_EXECUTABLE", pyexe))
if "+mpi" in spec:
args.append(self.define("MPI_C_COMPILER", spec["mpi"].mpicc))
args.append(self.define("MPI_CXX_COMPILER", spec["mpi"].mpicxx))

View File

@ -57,10 +57,7 @@ def cmake_args(self):
self.define("USE_FLEXNLP", False),
]
if "+python" in spec:
args += [
self.define("Tiramisu_INSTALL_PYTHONDIR", python_platlib),
self.define("Python3_EXECUTABLE", spec["python"].command.path),
]
args += [self.define("Tiramisu_INSTALL_PYTHONDIR", python_platlib)]
return args
@property

View File

@ -46,10 +46,7 @@ def cmake_args(self):
elif spec.satisfies("target=ppc64le:"):
disable_features.add("fma")
args = [
self.define_from_variant("PRELOAD"),
self.define("PYTHON_EXECUTABLE", spec["python"].command),
]
args = [self.define_from_variant("PRELOAD")]
for f in ["sse", "avx", "avx2", "fma", "neon"]:
args.append(
self.define(f.upper(), f not in disable_features and f in self.spec.target)

View File

@ -310,8 +310,6 @@ def cmake_args(self):
# Enable/Disable wrappers for Python.
if "+python" in spec:
cmake_args.append("-DVTK_WRAP_PYTHON=ON")
if spec.satisfies("@:8"):
cmake_args.append("-DPYTHON_EXECUTABLE={0}".format(spec["python"].command.path))
if "+mpi" in spec and spec.satisfies("@:8"):
cmake_args.append("-DVTK_USE_SYSTEM_MPI4PY:BOOL=ON")
if spec.satisfies("@9.0.0: ^python@3:"):

View File

@ -36,7 +36,6 @@ def cmake_args(self):
"-DPYMOD_INSTALL_LIBDIR=/python{0}/site-packages".format(spec["python"].version[:-1]),
"-DXCFUN_MAX_ORDER=8",
"-DXCFUN_PYTHON_INTERFACE=ON",
"-DPYTHON_EXECUTABLE={0}".format(spec["python"].command),
"-DENABLE_TESTALL=OFF",
]
return args

View File

@ -203,12 +203,7 @@ def cmake_args(self):
]
# see https://github.com/spack/spack/pull/11581
if "+python" in self.spec:
options.extend(
[
define("PYTHON_EXECUTABLE", spec["python"].command.path),
define("XRD_PYTHON_REQ_VERSION", spec["python"].version.up_to(2)),
]
)
options.append(define("XRD_PYTHON_REQ_VERSION", spec["python"].version.up_to(2)))
if "+scitokens-cpp" in self.spec:
options.append("-DSCITOKENS_CPP_DIR=%s" % spec["scitokens-cpp"].prefix)

View File

@ -33,11 +33,3 @@ class XtensorPython(CMakePackage):
depends_on("python", type=("build", "link", "run"))
extends("python")
def cmake_args(self):
spec = self.spec
python_exe = spec["python"].command.path
args = ["-DPYTHON_EXECUTABLE={0}".format(python_exe)]
return args