Repository: spack/spack

Issue:
Installation issue: fftw+openmp %apple-clang
### Steps to reproduce the issue

```console
spack install fftw+openmp %apple-clang
```

```
checking for OpenMP flag of C compiler... unknown
configure: error: don't know how to enable OpenMP
==> Error: ProcessError: Command exited with status 1:
    '../configure' '--prefix=/Users/jlvay/warpxtest/spack/opt/spack/darwin-catalina-ivybridge/apple-clang-12.0.0/fftw-3.3.9-kdebyf3xpxej56c7ijxf22ezm5pqfrev' '--enable-shared' '--enable-threads' '--enable-openmp' '--enable-mpi' '--enable-sse2' '--enable-avx' '--disable-avx2' '--disable-avx512' '--disable-avx-128-fma' '--disable-kcvi' '--disable-vsx' '--disable-neon' '--disable-fma'

1 error found in build log:
     199    checking how to hardcode library paths into programs... immediate
     200    checking how to get verbose linking output from /Users/jlvay/warpxtest/spack/lib/spack/env/clang/gfortran... -v
     201    checking for Fortran 77 libraries of /Users/jlvay/warpxtest/spack/lib/spack/env/clang/gfortran...  -L/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/gcc/x86_64-apple-darwin19/11.1.0 -L/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/gcc/x86_64-apple-darwin19/11.1.0/../../.. -lgfortran -lquadmath -lm
     202    checking for dummy main to link with Fortran 77 libraries... none
     203    checking for Fortran 77 name-mangling scheme... lower case, underscore, no extra underscore
     204    checking for OpenMP flag of C compiler... unknown
  >> 205    configure: error: don't know how to enable OpenMP

See build log for details:
  /var/folders/wv/6p9cjj9n7plgcx5krp_8kxgr0000gn/T/jlvay/spack-stage/spack-stage-fftw-3.3.9-kdebyf3xpxej56c7ijxf22ezm5pqfrev/spack-build-out.txt

==> Updating view at /Users/jlvay/warpx/spack/var/spack/environments/warpx-dev/.spack-env/view
==> Error: Cannot create view: file already exists and is not a link: /Users/jlvay/warpx/spack/var/spack/environments/warpx-dev/.spack-env/view
jean-lucs-pro:~/warpxtest$ 
```

### Information on your system

`spack debug report`:
* **Spack:** 0.16.2-4280-bd415ec841
* **Python:** 3.9.5
* **Platform:** darwin-catalina-ivybridge
* **Concretizer:** clingo

### Additional information

- [spack-build-env.txt](https://github.com/spack/spack/files/7188063/spack-build-env.1.txt)
- [spack-build-out.txt](https://github.com/spack/spack/files/7188064/spack-build-out.1.txt)

I tried to patch
```diff
diff --git a/var/spack/repos/builtin/packages/fftw/package.py b/var/spack/repos/builtin/packages/fftw/package.py
index 5325545984..13e9cb3ec8 100644
--- a/var/spack/repos/builtin/packages/fftw/package.py
+++ b/var/spack/repos/builtin/packages/fftw/package.py
@@ -101,9 +101,11 @@ def configure(self, spec, prefix):
         # Variants that affect every precision
         if '+openmp' in spec:
             options.append('--enable-openmp')
-            if spec.satisfies('@:2'):
+            if spec.satisfies('@:2') or spec.satisfies('%apple-clang'):
                 # TODO: libtool strips CFLAGS, so 2.x libxfftw_threads
                 #       isn't linked to the openmp library. Patch Makefile?
+                # work-around: autotools in FFTW does not find OpenMP without
+                #              further help with AppleClang
                 options.insert(0, 'CFLAGS=' + self.compiler.openmp_flag)
         if '+mpi' in spec:
             options.append('--enable-mpi')
```
but this does not solve it yet:
```

checking for OpenMP flag of C compiler... unknown
configure: error: don't know how to enable OpenMP
==> Error: ProcessError: Command exited with status 1:
    '../configure' 'CFLAGS=-Xpreprocessor -fopenmp' '--prefix=/Users/jlvay/warpxtest/spack/opt/spack/darwin-catalina-ivybridge/apple-clang-12.0.0/fftw-3.3.9-kdebyf3xpxej56c7ijxf22ezm5pqfrev' '--enable-shared' '--enable-threads' '--enable-openmp' '--enable-mpi' '--enable-sse2' '--enable-avx' '--disable-avx2' '--disable-avx512' '--disable-avx-128-fma' '--disable-kcvi' '--disable-vsx' '--disable-neon' '--disable-fma'

1 error found in build log:
     196    checking how to hardcode library paths into programs... immediate
     197    checking how to get verbose linking output from /Users/jlvay/warpxtest/spack/lib/spack/env/clang/gfortran... -v
     198    checking for Fortran 77 libraries of /Users/jlvay/warpxtest/spack/lib/spack/env/clang/gfortran...  -L/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/gcc/x86_64-apple-darwin19/11.1.0 -L/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11/gcc/x86_64-apple-darwin19/11.1.0/../../.. -lgfortran -lquadmath -lm
     199    checking for dummy main to link with Fortran 77 libraries... none
     200    checking for Fortran 77 name-mangling scheme... lower case, underscore, no extra underscore
     201    checking for OpenMP flag of C compiler... unknown
  >> 202    configure: error: don't know how to enable OpenMP
```

Looks like a problem with Autotools on macOS in general.

### General information

- [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
- [X] 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:
We could try more hints, e.g., as in  https://github.com/spack/spack/blob/bd415ec8417320f42213ebf4a4b5088f753eed0b/var/spack/repos/builtin/packages/lbann/package.py#L278-L287 ?
(I have no mac to test this personally.)
That worked! Will submit a PR.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/fftw/package.py b/var/spack/repos/builtin/packages/fftw/package.py
--- a/var/spack/repos/builtin/packages/fftw/package.py
+++ b/var/spack/repos/builtin/packages/fftw/package.py
@@ -86,6 +86,17 @@ def selected_precisions(self):
         """Precisions that have been selected in this build"""
         return self.spec.variants['precision'].value
 
+    def setup_build_environment(self, env):
+        if self.spec.satisfies('%apple-clang +openmp'):
+            env.append_flags(
+                'CPPFLAGS', self.compiler.openmp_flag)
+            env.append_flags(
+                'CFLAGS', self.spec['llvm-openmp'].headers.include_flags)
+            env.append_flags(
+                'CXXFLAGS', self.spec['llvm-openmp'].headers.include_flags)
+            env.append_flags(
+                'LDFLAGS', self.spec['llvm-openmp'].libs.ld_flags)
+
     def configure(self, spec, prefix):
         # Base options
         options = [


Test patch: