Repository: spack/spack

Issue:
Installation issue: cgns tries to use mpifc even if fortran is disabled 
### Steps to reproduce the issue

```console
$ spack spec -I cgns@4.3.0~fortran ^mpich@4.1.1~fortran
Input spec
--------------------------------
 -   cgns@4.3.0~fortran
 -       ^mpich@4.1.1~fortran

Concretized
--------------------------------
 -   cgns@4.3.0%clang@16.0.0~base_scope~fortran+hdf5~int64~ipo~legacy~mem_debug+mpi+scoping+shared~static~testing~tools build_system=cmake build_type=RelWithDebInfo generator=make arch=linux-ubuntu20.04-haswell
[+]      ^cmake@3.25.1%clang@16.0.0~doc+ncurses+ownlibs~qt build_system=generic build_type=Release arch=linux-ubuntu20.04-haswell
[+]      ^gmake@4.2.1%clang@16.0.0~guile build_system=autotools patches=ca60bd9,fe5b60d arch=linux-ubuntu20.04-haswell
[+]      ^hdf5@1.12.2%clang@16.0.0~cxx~fortran~hl~ipo~java+mpi+shared~szip~threadsafe+tools api=default build_system=cmake build_type=RelWithDebInfo generator=make arch=linux-ubuntu20.04-haswell
[+]          ^pkgconf@1.8.0%clang@16.0.0 build_system=autotools arch=linux-ubuntu20.04-haswell
[+]          ^zlib@1.2.13%clang@16.0.0+optimize+pic+shared build_system=makefile arch=linux-ubuntu20.04-haswell
[+]      ^mpich@4.1.1%clang@16.0.0~argobots~cuda~fortran+hwloc+hydra+libxml2+pci~rocm+romio~slurm~two_level_namespace~vci~verbs+wrapperrpath build_system=autotools datatype-engine=auto device=ch4 netmod=ofi pmi=pmi arch=linux-ubuntu20.04-haswell
[+]          ^findutils@4.7.0%clang@16.0.0 build_system=autotools arch=linux-ubuntu20.04-haswell
[+]          ^hwloc@2.9.1%clang@16.0.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~oneapi-level-zero~opencl+pci~rocm build_system=autotools libs=shared,static arch=linux-ubuntu20.04-haswell
[+]              ^ncurses@6.2.20200212%clang@16.0.0+symlinks+termlib abi=6 build_system=autotools arch=linux-ubuntu20.04-haswell
[+]          ^libfabric@1.18.0%clang@16.0.0~debug~kdreg build_system=autotools fabrics=sockets,tcp,udp arch=linux-ubuntu20.04-haswell
[+]          ^libpciaccess@0.17%clang@16.0.0 build_system=autotools arch=linux-ubuntu20.04-haswell
[+]              ^libtool@2.4.6%clang@16.0.0 build_system=autotools arch=linux-ubuntu20.04-haswell
[+]              ^util-macros@1.19.3%clang@16.0.0 build_system=autotools arch=linux-ubuntu20.04-haswell
[+]          ^libxml2@2.10.3%clang@16.0.0~python build_system=autotools arch=linux-ubuntu20.04-haswell
[+]              ^libiconv@1.17%clang@16.0.0 build_system=autotools libs=shared,static arch=linux-ubuntu20.04-haswell
[+]              ^xz@5.2.4%clang@16.0.0~pic build_system=autotools libs=shared,static arch=linux-ubuntu20.04-haswell
[+]          ^yaksa@0.2%gcc@12.2.0~cuda~rocm build_system=autotools arch=linux-ubuntu20.04-haswell
[-]              ^autoconf@2.69%gcc@12.2.0 build_system=autotools patches=7793209 arch=linux-ubuntu20.04-haswell
[-]              ^automake@1.16.1%gcc@12.2.0 build_system=autotools arch=linux-ubuntu20.04-haswell
[-]              ^libtool@2.4.6%gcc@12.2.0 build_system=autotools arch=linux-ubuntu20.04-haswell
[-]              ^m4@1.4.18%gcc@12.2.0+sigsegv build_system=autotools patches=3877ab5,fc9b616 arch=linux-ubuntu20.04-haswell
[-]              ^python@3.8.10%gcc@12.2.0+bz2+crypt+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tkinter+uuid+zlib build_system=generic patches=0d98e93,4c24573,f2fd060 arch=linux-ubuntu20.04-haswell
```

```console
spack install cgns@4.3.0~fortran ^mpich@4.1.1~fortran
```

### Error message

<details><summary>Error message</summary>

<pre>
==> Error: AttributeError: 'Spec' object has no attribute 'mpifc'

The 'cgns' package cannot find an attribute while trying to build from sources. This might be due to a change in Spack's package format to support multiple build-systems for a single package. You can fix this by updating the build recipe, and you can also report the issue as a bug. More information at https://spack.readthedocs.io/en/latest/packaging_guide.html#installation-procedure

/path/to/spack/var/spack/repos/builtin/packages/cgns/package.py:93, in cmake_args:
         90                [
         91                    "-DCMAKE_C_COMPILER=%s" % spec["mpi"].mpicc,
         92                    "-DCMAKE_CXX_COMPILER=%s" % spec["mpi"].mpicxx,
  >>     93                    "-DCMAKE_Fortran_COMPILER=%s" % spec["mpi"].mpifc,
         94                ]
         95            )
         96

See build log for details:
/path/to/spack-stage/spack-stage-cgns-4.3.0-h42e75qpcnab3ozroegcqbrx2ghlqkat/spack-build-out.txt


</pre></details>


### Information on your system

```
* **Spack:** 0.20.0.dev0 (f5c32d57e051a8ea6f04bc86f3df5867ea1ab49e)
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-skylake_avx512
* **Concretizer:** clingo
```

### Additional information

Maintainer: @gsjaardema

Note the bug here is that the recipe for cgns unconditionally sets the fortran compiler to mpifc even if mpifc is not available in the mpi install.

spack-build-out.txt
```
==> cgns: Executing phase: 'cmake'
```

I can't upload my spack-build-env but please contact me if you need some specific info. I don't think it's too relevant to the bug however.


### 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:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/cgns/package.py b/var/spack/repos/builtin/packages/cgns/package.py
--- a/var/spack/repos/builtin/packages/cgns/package.py
+++ b/var/spack/repos/builtin/packages/cgns/package.py
@@ -87,6 +87,7 @@ def cmake_args(self):
                 self.define_from_variant("CGNS_ENABLE_LEGACY", "legacy"),
                 self.define_from_variant("CGNS_ENABLE_MEM_DEBUG", "mem_debug"),
                 self.define_from_variant("CMAKE_POSITION_INDEPENDENT_CODE", "pic"),
+                self.define_from_variant("CGNS_ENABLE_64BIT", "int64"),
             ]
         )
 
@@ -95,11 +96,10 @@ def cmake_args(self):
                 [
                     "-DCMAKE_C_COMPILER=%s" % spec["mpi"].mpicc,
                     "-DCMAKE_CXX_COMPILER=%s" % spec["mpi"].mpicxx,
-                    "-DCMAKE_Fortran_COMPILER=%s" % spec["mpi"].mpifc,
                 ]
             )
-
-        options.append(self.define_from_variant("CGNS_ENABLE_64BIT", "int64"))
+            if "+fortran" in spec:
+                options.append(self.define("CMAKE_Fortran_COMPILER", spec["mpi"].mpifc))
 
         if "+hdf5" in spec:
             options.extend(


Test patch: