netcdf-fortran icon indicating copy to clipboard operation
netcdf-fortran copied to clipboard

would like to list the netcdf-c version in the build summary, but how?

Open edwardhartnett opened this issue 5 years ago • 5 comments

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...

edwardhartnett avatar Aug 04 '20 15:08 edwardhartnett

Let me double check but I have an idea for this.

WardF avatar Aug 05 '20 22:08 WardF

You also can get that info from libnetcdf.settings if that is any easier.

DennisHeimbigner avatar Aug 05 '20 23:08 DennisHeimbigner

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 ()

edwardhartnett avatar Aug 06 '20 17:08 edwardhartnett

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.

WardF avatar Aug 06 '20 20:08 WardF

A couple of other approaches:

  1. for CMake, use CMake string operations to extract some pattern from libnetcdf.settings
  2. 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

DennisHeimbigner avatar Aug 07 '20 19:08 DennisHeimbigner