WRF-CMake / wrf

🌀 The Weather Research and Forecasting (WRF) model with CMake support
Other
44 stars 3 forks source link

CMake cannot find NetCDF Fortran interface #34

Closed dmey closed 5 years ago

dmey commented 5 years ago

In Linux, when using Environment Modules, CMake cannot find the NetCDF Fortran interface when NetCDF-Fortran has been installed under a different path to NetCDF-C.

For example, with the following configuration:

$ nc-config --all

This netCDF 4.4.1.1 has been built with the following features:

  --cc        -> mpiicc
  --cflags    -> -I/external/netcdf/4.4.1-c/include -I/external/hdf5/1.10.1//include
  --libs      -> -L/external/netcdf/4.4.1-c/lib -lnetcdf

  --has-c++   -> no
  --cxx       ->

  --has-c++4  -> no
  --cxx4      ->

  --has-fortran-> yes
  --fc        -> mpiifort
  --fflags    -> -I/external/netcdf/4.4.4-fortran/include
  --flibs     -> -L/external/netcdf/4.4.4-fortran/lib -lnetcdff -L/external/netcdf/4.4.1-c/lib -lnetcdf -lnetcdf
  --has-f90   -> no
  --has-f03   -> yes

  --has-dap   -> yes
  --has-nc2   -> yes
  --has-nc4   -> yes
  --has-hdf5  -> yes
  --has-hdf4  -> no
  --has-logging-> no
  --has-pnetcdf-> no
  --has-szlib ->

  --prefix    -> /external/netcdf/4.4.1-c
  --includedir-> /external/netcdf/4.4.1-c/include
  --libdir    -> /external/netcdf/4.4.1-c/lib
  --version   -> netCDF 4.4.1.1

The configuration fails with the following error:

$ cmake -DNETCDF_DIR=/external/netcdf/4.4.1-c ..
-- Using /home/WRF/cmake/arch/default/Intel_UNIX.cmake (C)
-- Using /home/WRF/cmake/arch/default/Intel_UNIX.cmake (Fortran)
-- Using /home/WRF/cmake/arch/default/Intel_Fortran_UNIX.cmake (Fortran)
-- Using /home/WRF/cmake/arch/default/Intel_UNIX.cmake (linker)
-- Failed to find NetCDF interface for F77
-- Failed to find NetCDF interface for F90
CMake Error at /external/cmake/3.14.0/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find NetCDF (missing: NETCDF_HAS_INTERFACES)
Call Stack (most recent call first):
  /external/cmake/3.14.0/share/cmake-3.14/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindNetCDF.cmake:150 (find_package_handle_standard_args)
  CMakeLists.txt:264 (find_package)
dmey commented 5 years ago

For reference VTK has updated their FindNetCDF.cmake script but also removed the Fortran interface -- see https://github.com/Kitware/VTK/blob/master/CMake/FindNetCDF.cmake

letmaik commented 5 years ago

Looks like our FindNetCDF script would support this case using -DNETCDF_F77_ROOT=/external/netcdf/4.4.4-fortran -DNETCDF_F90_ROOT=/external/netcdf/4.4.4-fortran. Can you try that?

dmey commented 5 years ago

That seems to have, partially, worked -- see below. The PATH to the include dirs is correct however it picks up the libraries from a different path. I checked and external appears before anything else in the PATH.

NETCDF_F90_INCLUDE_DIR:PATH=/external/netcdf/4.4.4-fortran/include
NETCDF_F90_LIBRARY:FILEPATH=/lib64/libnetcdff.so
NETCDF_INCLUDE_DIR:PATH=/external/netcdf/4.4.1-c/include
NETCDF_LIBRARY:FILEPATH=/lib64/libnetcdf.so

Ideally though, the PATH to netcdff should really be found from the config as per nc-config... The new script in VTK seems to always work in the systems tested without the need of specifying the PATH to anything so if we can easily get the information from nc-config after if find netcdf-c that may be a less brittle alternative than currently done...

letmaik commented 5 years ago

I pushed a fix, you can use -DNETCDF_DIR=... -DNETCDF_FORTRAN_DIR=.. to specify the folders separately. Needs some documentation.

dmey commented 5 years ago

@letmaik docs updated in 8c6386d. Feel free to merge in directly if OK, else please comment and will make changes.