From 7b2895109cac96174949b51ba19c5fc9aa011ad7 Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Thu, 30 Jan 2020 12:34:54 -0800 Subject: Document how to add conditional dependencies (#14694) * add short docs section on conditional dependencies * add reference to spec syntax * add note that conditional dependencies can save time --- lib/spack/docs/packaging_guide.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib') diff --git a/lib/spack/docs/packaging_guide.rst b/lib/spack/docs/packaging_guide.rst index 223c509ac1..e566cb4545 100644 --- a/lib/spack/docs/packaging_guide.rst +++ b/lib/spack/docs/packaging_guide.rst @@ -1989,6 +1989,28 @@ inject the dependency's ``prefix/lib`` directory, but the package needs to be in ``PATH`` and ``PYTHONPATH`` during the build process and later when a user wants to run the package. +^^^^^^^^^^^^^^^^^^^^^^^^ +Conditional dependencies +^^^^^^^^^^^^^^^^^^^^^^^^ + +You may have a package that only requires a dependency under certain +conditions. For example, you may have a package that has optional MPI support, +- MPI is only a dependency when you want to enable MPI support for the +package. In that case, you could say something like: + +.. code-block:: python + + variant('mpi', default=False) + depends_on('mpi', when='+mpi') + +``when`` can include constraints on the variant, version, compiler, etc. and +the :mod:`syntax` is the same as for Specs written on the command +line. + +If a dependency/feature of a package isn't typically used, you can save time +by making it conditional (since Spack will not build the dependency unless it +is required for the Spec). + .. _dependency_dependency_patching: ^^^^^^^^^^^^^^^^^^^ -- cgit v1.2.3-70-g09d2