diff --git a/CMakeLists.txt b/CMakeLists.txt index 8417db41..7fb56d3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,14 +34,12 @@ option(USE_AEC "Use AEC?" off) option(MAKE_FTN_API "add ftn api?" off) option(DISABLE_STAT "disable posix feature" off) set(BUILD_COMMENTS "stock build") - option(BUILD_LIB "Build wgrib2 library?" on) option(BUILD_SHARED_LIB "Build shared library?" off) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -#set default install path if not provided +# Set default install path if not provided. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" @@ -129,7 +127,8 @@ if(USE_PNG) find_package(PNG REQUIRED) endif() -# write config.h +# write config.h. This is used internally by wgrib2 code and is not +# installed. message(STATUS "Writing config.h...") FILE(WRITE "wgrib2/config.h" "/* config.h generated by cmake */\n") FILE(APPEND "wgrib2/config.h" "#ifndef _CONFIG_H\n") diff --git a/wgrib2/CMakeLists.txt b/wgrib2/CMakeLists.txt index 24013ec5..e0508874 100644 --- a/wgrib2/CMakeLists.txt +++ b/wgrib2/CMakeLists.txt @@ -52,13 +52,22 @@ if(MAKE_FTN_API) endif() add_subdirectory(gctpc) + # make this an object lib so we can re-use most of object files # The only files that differ are ${callable_src} which are compiled # with -DCALLABLE_WGRIB2 add_library(obj_lib OBJECT ${lib_src}) target_compile_definitions(obj_lib PUBLIC ${definitions_list}) +# Write wgrib2_meta.h. This is installed and contains pre-processor +# defines for other packages using wgrib2. +configure_file ( + "${PROJECT_SOURCE_DIR}/wgrib2/wgrib2_meta.h.in" + "${PROJECT_BINARY_DIR}/wgrib2/wgrib2_meta.h" + ) + if(BUILD_LIB) + # with -DCALLABLE_WGRIB2 for the lib if(BUILD_SHARED_LIB) add_library(wgrib2_lib SHARED ${lib_src} $ ${callable_src}) @@ -132,7 +141,7 @@ target_link_libraries(wgrib2_exe PRIVATE gctpc) target_link_libraries(wgrib2_exe PRIVATE obj_lib) if(BUILD_LIB) - set(headers wgrib2_api.h wgrib2.h) + set(headers wgrib2_api.h wgrib2.h ${CMAKE_BINARY_DIR}/wgrib2_meta.h) target_link_libraries(wgrib2_lib PUBLIC gctpc) # if(USE_IPOLATES EQUAL 1) # target_link_libraries(wgrib2_lib PRIVATE ip:ip_4 sp:sp_4) diff --git a/wgrib2/wgrib2_meta.h.in b/wgrib2/wgrib2_meta.h.in new file mode 100644 index 00000000..fda745e6 --- /dev/null +++ b/wgrib2/wgrib2_meta.h.in @@ -0,0 +1,37 @@ +/* This header file may be used by other packages to learn about this + * wgrib2 build. + * + * Edward Hartnett 3/29/24 */ +#ifndef _WGRIB2_META_H +#define _WGRIB2_META_H + +#cmakedefine USE_NETCDF3 +#cmakedefine USE_NETCDF4 +#cmakedefine USE_HDF5 +#cmakedefine USE_REGEX +#cmakedefine USE_TIGGE +#cmakedefine USE_MYSQL +#define USE_IPOLATES @USE_IPOLATES@ +#cmakedefine USE_UDF +#cmakedefine USE_OPENMP +#cmakedefine USE_PROJ4 +#cmakedefine USE_WMO_VALIDATION +#cmakedefine DISABLE_TIMEZONE +#cmakedefine DISABLE_ALARM +#cmakedefine USE_NAMES NCEP +#cmakedefine USE_G2CLIB +#cmakedefine USE_PNG +#cmakedefine USE_JASPER +#cmakedefine USE_OPENJPEG +#cmakedefine MAKE_FTN_API +#cmakedefine USE_AEC + +#define WGRIB2_VERSION "@CMAKE_PROJECT_VERSION@" +#define BUILD_COMMENTS "@BUILD_COMMENTS@" +#define CC "@CMAKE_C_COMPILER@ @CMAKE_C_COMPILER_ID@" +#define FORTRAN "@CMAKE_Fortran_COMPILER@ @CMAKE_Fortran_COMPILER_ID@" +#define CPPFLAGS "@CMAKE_C_FLAGS@" +#define FFLAGS "@CMAKE_Fortran_FLAGS@" +#define WGRIB2_VERSION "@CMAKE_PROJECT_VERSION@" + +#endif