Repository: spack/spack

Issue:
Installation issue: netcdf-fortran
Can anyone reproduce this issue with netcdf-fortran and the intel compiler?  The error is confusing because the spack dependency graph indicates that netcdf-fortran is independent of netcdf.  I don't know if the netcdf-fortran is not reading the library flags of netcdf properly, or if the latest version of netcdf-fortran has introduced some dependency on mpi, or if this is something specific to intel and/or intel-mpi.

### Steps to reproduce the issue

```console
$ spack -d install -v netcdf-fortran
...
     172    checking for MPI_File_open... no
     173    checking for library containing MPI_File_open... no
  >> 174    configure: error:
     175          -----------------------------------------------------------------------
     176            The NetCDF C library is built with parallel I/O feature enabled, but
     177            the Fortran compiler '/home/yul18051/src/cmaq/master/spack/lib/spack/env/intel/ifort' supplied in this configure command
     178            does not support MPI-IO. Please use one that does. If parallel I/O
     179            feature is not desired, please use a NetCDF C library with parallel
     180            I/O feature disabled. Abort.
```

### Platform and user environment

Please report your OS here:
```commandline
$ uname -a 
Linux cn01 2.6.32-642.13.1.el6.x86_64 #1 SMP Wed Nov 23 16:03:01 EST 2016 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -d
Description:    Red Hat Enterprise Linux Server release 6.7 (Santiago)
``` 

```yml
# This is a Spack Environment file.
#
# It describes a set of packages to be installed, along with
# configuration settings.
spack:
  # add package specs to the `specs` list
  specs:
  - ioapi
  mirrors: {}
  repos: []
  upstreams: {}
  modules:
    enable: []
  definitions: []
  packages:
    intel-mkl:
      buildable: false
      paths:
        intel-mkl@19.3 +ilp64 threads=openmp: /apps2/intel/ips/2019u3/compilers_and_libraries_2019.3.199/linux
      version: []
      providers: {}
      modules: {}
      compiler: []
      target: []
    intel-mpi:
      buildable: false
      paths:
        intel-mpi@19.3: /apps2/intel/ips/2019u3/compilers_and_libraries_2019.3.199/linux/mpi/intel64
      providers: {}
      modules: {}
      compiler: []
      version: []
      target: []
    all:
      compiler: [intel@19.3]
      providers: {}
      buildable: true
      version: []
      paths: {}
      modules: {}
      target: []
  config: {}
  compilers:
  - compiler:
      operating_system: rhel6
      paths:
        cc: /apps2/intel/ips/2019u3/bin/icc
        cxx: /apps2/intel/ips/2019u3/bin/icpc
        f77: /apps2/intel/ips/2019u3/bin/ifort
        fc: /apps2/intel/ips/2019u3/bin/ifort
      # RHEL 6 gcc 4.4.7 does not support std=c++11
      flags:
        cflags: -gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc
        cxxflags: -gxx-name=/apps2/gcc/5.4.0-alt/bin/g++
        fflags: -gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc
      extra_rpaths:
      - /apps2/intel/ips/2019u3/compilers_and_libraries_2019.3.199/linux/compiler/lib/intel64_lin
      spec: intel@19.3
      target: x86_64
      modules: [intel/2019u3]
      environment: {}
  view: false
  concretization: separately
```

### Additional information

```console
$ spack spec --install-status <spec>
[yul18051@cn01 master]$ spack spec -I ioapi
Input spec
--------------------------------
 -   ioapi

Concretized
--------------------------------
 -   ioapi@3.2%intel@19.3 cflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" cxxflags="-gxx-name=/apps2/gcc/5.4.0-alt/bin/g++" fflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc"  arch=linux-rhel6-westmere
 -       ^netcdf@4.7.2%intel@19.3 cflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" cxxflags="-gxx-name=/apps2/gcc/5.4.0-alt/bin/g++" fflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" ~dap~hdf4 maxdims=1024 maxvars=8192 +mpi~parallel-netcdf+pic+shared arch=linux-rhel6-westmere
 -           ^hdf5@1.10.5%intel@19.3 cflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" cxxflags="-gxx-name=/apps2/gcc/5.4.0-alt/bin/g++" fflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" ~cxx~debug~fortran+hl+mpi patches=b61e2f058964ad85be6ee5ecea10080bf79e73f83ff88d1fa4b602d00209da9c +pic+shared~szip~threadsafe arch=linux-rhel6-westmere
 -               ^intel-mpi@19.3%intel@19.3 cflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" cxxflags="-gxx-name=/apps2/gcc/5.4.0-alt/bin/g++" fflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc"  arch=linux-rhel6-westmere
[+]              ^zlib@1.2.11%intel@19.3 cflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" cxxflags="-gxx-name=/apps2/gcc/5.4.0-alt/bin/g++" fflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" +optimize+pic+shared arch=linux-rhel6-westmere
[+]          ^m4@1.4.18%intel@19.3 cflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" cxxflags="-gxx-name=/apps2/gcc/5.4.0-alt/bin/g++" fflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc"  patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00,fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8 +sigsegv arch=linux-rhel6-westmere
[+]              ^libsigsegv@2.12%intel@19.3 cflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" cxxflags="-gxx-name=/apps2/gcc/5.4.0-alt/bin/g++" fflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc"  arch=linux-rhel6-westmere
 -       ^netcdf-fortran@4.5.2%intel@19.3 cflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" cxxflags="-gxx-name=/apps2/gcc/5.4.0-alt/bin/g++" fflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" +pic arch=linux-rhel6-westmere
 -       ^sed@4.2.2%intel@19.3 cflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc" cxxflags="-gxx-name=/apps2/gcc/5.4.0-alt/bin/g++" fflags="-gcc-name=/apps2/gcc/5.4.0-alt/bin/gcc"  arch=linux-rhel6-westmere
```

```console
$ spack log-parse --show=errors,warnings /tmp/yul18051/spack-stage/spack-stage-netcdf-fortran-4.5.2-3bk4vhnhn6hntkfq25djm3xn4sbf3aa4/spack-build-out.txt
1 errors
0 warnings
     171    checking for library containing dlopen... none required
     172    checking for MPI_File_open... no
     173    checking for library containing MPI_File_open... no
  >> 174    configure: error:
     175          -----------------------------------------------------------------------
     176            The NetCDF C library is built with parallel I/O feature enabled, but
     177            the Fortran compiler '/home/yul18051/src/cmaq/master/spack/lib/spack/env/intel/ifort' supplied in this configure command
```
- [config.log](https://github.com/spack/spack/files/3786954/config.log)
- [spack-cc-netcdf-fortran-3bk4vhn.in.log](https://github.com/spack/spack/files/3786955/spack-cc-netcdf-fortran-3bk4vhn.in.log)
- [spack-cc-netcdf-fortran-3bk4vhn.out.log](https://github.com/spack/spack/files/3786956/spack-cc-netcdf-fortran-3bk4vhn.out.log)



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/netcdf-fortran/package.py b/var/spack/repos/builtin/packages/netcdf-fortran/package.py
--- a/var/spack/repos/builtin/packages/netcdf-fortran/package.py
+++ b/var/spack/repos/builtin/packages/netcdf-fortran/package.py
@@ -20,10 +20,17 @@ class NetcdfFortran(AutotoolsPackage):
     version('4.4.4', sha256='b2d395175f8d283e68c8be516e231a96b191ade67ad0caafaf7fa01b1e6b5d75')
     version('4.4.3', sha256='330373aa163d5931e475b5e83da5c1ad041e855185f24e6a8b85d73b48d6cda9')
 
+    variant('mpi', default=True,
+            description='Enable parallel I/O for netcdf-4')
     variant('pic', default=True,
             description='Produce position-independent code (for shared libs)')
 
-    depends_on('netcdf-c')
+    # We need to build with MPI wrappers if parallel I/O features is enabled:
+    # https://www.unidata.ucar.edu/software/netcdf/docs/building_netcdf_fortran.html
+    depends_on('mpi', when='+mpi')
+
+    depends_on('netcdf-c~mpi', when='~mpi')
+    depends_on('netcdf-c+mpi', when='+mpi')
 
     # The default libtool.m4 is too old to handle NAG compiler properly:
     # https://github.com/Unidata/netcdf-fortran/issues/94
@@ -56,3 +63,13 @@ def libs(self):
         return find_libraries(
             libraries, root=self.prefix, shared=shared, recursive=True
         )
+
+    def configure_args(self):
+        config_args = []
+
+        if '+mpi' in self.spec:
+            config_args.append('CC=%s' % self.spec['mpi'].mpicc)
+            config_args.append('FC=%s' % self.spec['mpi'].mpifc)
+            config_args.append('F77=%s' % self.spec['mpi'].mpif77)
+
+        return config_args


Test patch: