Open rouson opened 7 years ago
You could try pkg-config, which is probably a better option these days. I haven't tested FindNetCDF.cmake in quite a while (and no longer use CMake in any of my projects). I don't think it was ever tested for a Fortran project. I'm sorry, but I don't have time to add this feature or help you debug at this time. I'd be happy to merge a reasonable patch if you learn how to do it.
You might solve your problem merely by telling your Fortran compiler about NETCDF_INCLUDES.
Thanks for the quick reply. I'll let you know once it's sorted out. If I don't sort it out on my own, I'll ask for help from Kitware, Inc., on CMake.
Hi Damian,
You need to add the NetCDF includes:
cmake_minimum_required(VERSION 3.7)
project(build_against_netcdf LANGUAGES Fortran)
# Find the native NetCDF includes and library
include(cmake-modules/FindNetCDF.cmake)
set (NETCDF_F90 "YES") # Require Fortran interfaces to be FOUND
find_package (NetCDF REQUIRED)
include_directories(${NETCDF_INCLUDES})
add_library(io_routines src/io_routines.f90)
target_link_libraries (io_routines ${NETCDF_LIBRARIES})
A really good way to see what facilities a find module provides is to run ccmake
or cmake-gui
and then toggle the advanced options. In ccmake
t toggles the advanced options. Ctrl-n is go to the next line, Ctrl-p is go to the previous line, c is configure (i.e. run cmake), g is configure, generate and quit:
Pleas let me know if you can offer any advice on resolving the following problem:
I set up a small repository to learn how to use FindNetCDF. The repository has just two Fortran source files, only one of which depends on NetCDF as specified in a single use netcdf statement. An abbreviated transcript of my results using my repository's add-cmake-file branch follows:
I used MacPorts on macOS Sierra to install netcdf and netcdf-fortran with the resulting installed files: