Cross-compiling does not work due to wrong netcdf library
I am compiling a project (MPR) on MacOS and first ran cmake with the command
cmake -DCMAKE_NETCDF_DIR="/usr/local/netcdf-fortran-4.4.4-nagfor/bin/" -DCMAKE_Fortran_COMPILER=nagfor ..
in order to use the nagfor compiler and its associated netcdf installation - all worked fine. When I then want to switch to gfortran and its associated compiler, I get:
cmake -DCMAKE_NETCDF_DIR="/usr/local/netcdf-fortran-4.4.4-gfortran/bin/" -DCMAKE_Fortran_COMPILER=gfortran ..
-- build INDEPENDENT of module system OFF
-- CMake build configuration for MPR 0.4.0
-- search in additional directory /usr/local/netcdf-fortran-4.4.4-gfortran/bin/ for netCDF
-- found /usr/local/netcdf-fortran-4.4.4-nagfor/bin/nf-config
-- netcdff includes /usr/local/netcdf-fortran-4.4.4-nagfor/include
-- netcdff netcdf link flags -I/usr/local/netcdf-fortran-4.4.4-nagfor/include
-- netcdff netcdf library link flags -L/usr/local/netcdf-fortran-4.4.4-nagfor/lib -lnetcdff -L/usr/local/lib -lnetcdf -lnetcdf
-- found /usr/local/netcdf-fortran-4.4.4-nagfor/lib/libnetcdff.a
-- found /usr/local/lib/libnetcdf.dylib
-- found /usr/local/lib/libnetcdf.dylib
-- found netcdf libraries /usr/local/netcdf-fortran-4.4.4-nagfor/lib/libnetcdff.a;/usr/local/lib/libnetcdf.dylib;/usr/local/lib/libnetcdf.dylib
-- found netcdf other flags
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Shapelib: found
-- GDAL library: found
-- Proj library: found
-- shapelib.F90;proj.F90;gdal.F90
-- Found OpenMP_Fortran: -openmp
-- Found OpenMP: TRUE
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_Fortran_COMPILER= gfortran
CMAKE_Fortran_COMPILER= gfortran
-- The Fortran compiler identification is GNU 8.1.0
-- Checking whether Fortran compiler has -isysroot
-- Checking whether Fortran compiler has -isysroot - yes
-- Checking whether Fortran compiler supports OSX deployment target flag
-- Checking whether Fortran compiler supports OSX deployment target flag - yes
-- Check for working Fortran compiler: /usr/local/bin/gfortran
-- Check for working Fortran compiler: /usr/local/bin/gfortran -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/local/bin/gfortran supports Fortran 90
-- Checking whether /usr/local/bin/gfortran supports Fortran 90 -- yes
-- build INDEPENDENT of module system OFF
-- Performing Test CPP_FLAG
-- Performing Test CPP_FLAG - Success
-- CMake build configuration for MPR 0.4.0
-- search in additional directory for netCDF
-- found NETCDFF_CONFIG-NOTFOUND
-- netcdff includes
-- netcdff netcdf link flags
-- netcdff netcdf library link flags
-- found netcdf libraries
-- found netcdf other flags
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- Testing enabled for
-- The C compiler identification is GNU 8.1.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/local/bin/gcc
-- Check for working C compiler: /usr/local/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Shapelib: found
-- GDAL library: found
-- Proj library: found
-- shapelib.F90;proj.F90;gdal.F90
-- Found PythonInterp: /Users/ottor/miniconda3/envs/MPR/bin/python (found version "3.7.3")
-- Found OpenMP_Fortran: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/ottor/nc/Home/local_libs/fortran/MPR/build
It first searches in the already cached paths for netcdf (here, nagfor) and uses these in spite of the path provided in the variable CMAKE_NETCDF_DIR. I tried the recommendation at the bottom of the documentation of find_program, but to no avail. @thober, @kaluza