netcdf-fortran
netcdf-fortran copied to clipboard
would like to list the netcdf-c version in the build summary, but how?
It would be great to add the netcdf-c version to the build summary in libnetcdff.settings. But how?
It's right here in netcdf_meta.h:
#define NC_VERSION "4.8.0-development"
But how do I get this value from the .h file into an autoconf shell variable? I don't know...
Let me double check but I have an idea for this.
You also can get that info from libnetcdf.settings if that is any easier.
Here's something I'm now doing in the PIO config to detect version 4.7.2, which won't work. One could imagine doing this for every version, and so learning the version in configure:
# Is this version 4.7.2, which does not work?
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include "netcdf_meta.h"],
[[#if NC_VERSION_MAJOR == 4 && NC_VERSION_MINOR == 7 && NC_VERSION_PATCH == 2
# error
#endif]
])], [have_472=no], [have_472=yes])
AC_MSG_CHECKING([whether this is netcdf-c-4.7.2])
AC_MSG_RESULT([${have_472}])
if test "x$have_472" = xyes; then
 AC_MSG_ERROR([PIO cannot build with netcdf-c-4.7.2, please upgrade your netCDF version.])
fi
 The CMake version is:
###
# Check to see if this is netcdf-c-4.7.2, which won't work.
###
CHECK_C_SOURCE_COMPILES("
#include <netcdf_meta.h>
#if NC_VERSION_MAJOR == 4 && NC_VERSION_MINOR == 7 && NC_VERSION_PATCH == 2
#else
 choke me
#endif
int main() {return 0;}" HAVE_472)
if (HAVE_472)
 message (FATAL_ERROR "PIO cannot build with netcdf-c-4.7.2, please upgrade your netCDF library")
endif ()
Just turning back to this and what you've suggested is very much in line with what I was thinking, although in cmake at least it can be turned into a utility macro in expectation we'll want to keep using this down the line for other versions as well.
A couple of other approaches:
- for CMake, use CMake string operations to extract some pattern from libnetcdf.settings
- for automake create a shell script that does the same thing as #1 e.g. findsetting.sh "NetCDF Version" ${NCDIR}/libnetcdf.settings where NCDIR is the root dir for the netcdf-c installation or build directory