Repository: spack/spack

Issue:
Installation issue:  py-matplotlib
@adamjstewart this one is for you.
Basically, I tried to build openfoam and among its dependencies, there is py-matplotlib which is unable to find ImageMagick libraries even though they are installed and in the proper location.

<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

### Steps to reproduce the issue

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack install openfoam@2012+int64+kahip+metis+mgridgen+paraview+vtk ^cairo+X+gobject+pdf ^hdf5+cxx~debug+fortran+hl+mpi+pic+shared+szip+threadsafe ^paraview@5.6.2+hdf5+python3+qt build_type=Release ^py-matplotlib+animation+latex+movies backend=qt5cairo ^qt+gtk+opengl ^vtk@8.1.2+python+qt build_type=Release
...
==> Installing py-matplotlib-3.4.1-i54zjrlstw6ragjt55tayjryoqwee3sg
==> No binary for py-matplotlib-3.4.1-i54zjrlstw6ragjt55tayjryoqwee3sg found: installing from source
...
==> Error: NoLibrariesError: Unable to recursively locate imagemagick libraries in /var/lib/localadmin/stack/stack.v0.16.x/opt/zen2/imagemagick/7.0.8-7-gcc-op5z7vv

/var/lib/localadmin/stack/stack.v0.16.x/spack/var/spack/repos/builtin/packages/py-matplotlib/package.py:167, in setup_build_environment:
        164        for dep in self.spec.dependencies(deptype='link'):
        165            query = self.spec[dep.name]
        166            include.extend(query.headers.directories)
  >>    167            library.extend(query.libs.directories)
        168
        169        # Build uses a mix of Spack's compiler wrapper and the actual compiler,
        170        # so this is needed to get parts of the build working.
```
However, the imagemagick library seems to be properly installed and the libraries are there:

```console
$ ll /var/lib/localadmin/stack/stack.v0.16.x/opt/zen2/imagemagick/7.0.8-7-gcc-op5z7vv/lib/
total 86668
drwxr-sr-x. 3 localadmin localadmin     4096 Apr  7 06:59 ImageMagick-7.0.8
-rw-r--r--. 1 localadmin localadmin 14091966 Apr  7 06:59 libMagick++-7.Q16HDRI.a
lrwxrwxrwx. 1 localadmin localadmin       30 Apr  7 06:59 libMagick++-7.Q16HDRI.so -> libMagick++-7.Q16HDRI.so.4.0.0
lrwxrwxrwx. 1 localadmin localadmin       30 Apr  7 06:59 libMagick++-7.Q16HDRI.so.4 -> libMagick++-7.Q16HDRI.so.4.0.0
-rwxr-xr-x. 1 localadmin localadmin  5335488 Apr  7 06:59 libMagick++-7.Q16HDRI.so.4.0.0
-rw-r--r--. 1 localadmin localadmin 37703538 Apr  7 06:59 libMagickCore-7.Q16HDRI.a
lrwxrwxrwx. 1 localadmin localadmin       32 Apr  7 06:59 libMagickCore-7.Q16HDRI.so -> libMagickCore-7.Q16HDRI.so.6.0.0
lrwxrwxrwx. 1 localadmin localadmin       32 Apr  7 06:59 libMagickCore-7.Q16HDRI.so.6 -> libMagickCore-7.Q16HDRI.so.6.0.0
-rwxr-xr-x. 1 localadmin localadmin 19694920 Apr  7 06:59 libMagickCore-7.Q16HDRI.so.6.0.0
-rw-r--r--. 1 localadmin localadmin  7799584 Apr  7 06:59 libMagickWand-7.Q16HDRI.a
lrwxrwxrwx. 1 localadmin localadmin       32 Apr  7 06:59 libMagickWand-7.Q16HDRI.so -> libMagickWand-7.Q16HDRI.so.6.0.0
lrwxrwxrwx. 1 localadmin localadmin       32 Apr  7 06:59 libMagickWand-7.Q16HDRI.so.6 -> libMagickWand-7.Q16HDRI.so.6.0.0
-rwxr-xr-x. 1 localadmin localadmin  4104136 Apr  7 06:59 libMagickWand-7.Q16HDRI.so.6.0.0
drwxr-sr-x. 2 localadmin localadmin     4096 Apr  7 06:59 pkgconfig
```

### Information on your system

<!-- Please include the output of `spack debug report` -->

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->
If necessary, I can upload the build log and the build env.

<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

@adamjstewart

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [] I have uploaded the build log and environment files
- [x] I have searched the issues of this repo and believe this is not a duplicate



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/imagemagick/package.py b/var/spack/repos/builtin/packages/imagemagick/package.py
--- a/var/spack/repos/builtin/packages/imagemagick/package.py
+++ b/var/spack/repos/builtin/packages/imagemagick/package.py
@@ -36,3 +36,7 @@ def configure_args(self):
         return [
             '--with-gs-font-dir={0}'.format(gs_font_dir)
         ]
+
+    @property
+    def libs(self):
+        return find_libraries('libMagick*', root=self.prefix, recursive=True)


Test patch: