NOAA-EMC / wgrib2

Provides functionality for interacting with, reading, writing, and manipulating GRIB2 files.
27 stars 13 forks source link

should wrgib2/config.h be generated at build time? #81

Closed edwardhartnett closed 3 months ago

edwardhartnett commented 9 months ago

I note there is a config.h file, with contents like this:

/* config.h */
#define USE_REGEX
#define USE_TIGGE
//#define DISABLE_ALARM
//#define DISABLE_STAT
#define USE_NAMES NCEP
//#define USE_UDF
#define IPOLATES_LIB "ip2lib_d"
#define USE_IPOLATES 3
#define USE_OPENMP
#define MAKE_SHARED_LIB
#define CPPFLAGS "-march=native -mtune=native -I/cpc/home/wd51we/grib2/include -Wall -Wmissing-prototypes -Wold-style-definition -Werror=format-security -O3 -DGFORTRAN -fopenmp -fPIC -g"
#define FFLAGS "-march=native -mtune=native -c -O3 -fopenmp -fPIC -g"
//#define USE_G2CLIB
#define USE_PROJ4
#define USE_JASPER
//#define USE_AEC
#define USE_SPECTRAL 1
#define USE_NETCDF3
//#define USE_MYSQL
#define CC "gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-18)"
#define FORTRAN "GNU Fortran (GCC) 8.5.0 20210514 (Red Hat 8.5.0-18)"
#define BUILD_COMMENTS "stock build"
#define USE_PNG
//#define WMO_VALIDATION

How are these set?

In almost all other C builds I'm aware of, the config.h file is generated at build time by CMake. That allows us to set things that might be build options. For example if the user selects to build without PNG we can set that in the CMake step.

I suspect that's what we should be doing here as well...

edwardhartnett commented 9 months ago

A related issue is that we are defining 4 pre-processor symbols on both the compiler command line and in the config file. (The compiler command line is of course put together by cmake). We need to pick one or the other...

/home/ed/wgrib2/wgrib2/config.h:2: warning: "USE_REGEX" redefined
    2 | #define USE_REGEX
      | 
<command-line>: note: this is the location of the previous definition
In file included from /home/ed/wgrib2/wgrib2/wgrib2.h:13,
                 from /home/ed/wgrib2/wgrib2/AAIG.c:6:
/home/ed/wgrib2/wgrib2/config.h:9: warning: "USE_IPOLATES" redefined
    9 | #define USE_IPOLATES 3
      | 
<command-line>: note: this is the location of the previous definition
In file included from /home/ed/wgrib2/wgrib2/wgrib2.h:13,
                 from /home/ed/wgrib2/wgrib2/AAIG.c:6:
/home/ed/wgrib2/wgrib2/config.h:16: warning: "USE_JASPER" redefined
   16 | #define USE_JASPER
      | 
<command-line>: note: this is the location of the previous definition
In file included from /home/ed/wgrib2/wgrib2/wgrib2.h:13,
                 from /home/ed/wgrib2/wgrib2/AAIG.c:6:
/home/ed/wgrib2/wgrib2/config.h:24: warning: "USE_PNG" redefined
   24 | #define USE_PNG
      | 
<command-line>: note: this is the location of the previous definition

In C code we always use a config.h file. In fortran code we generally use the compile command line, because historically fortran did not have an include or officially support pre-processor symbols.

edwardhartnett commented 9 months ago

Also see fnlist.

We need to generate these in cmake.

edwardhartnett commented 4 months ago

This can be bumped to the next release if we have a working solution...

edwardhartnett commented 3 months ago

See #95