Skip to content

Commit

Permalink
Merge pull request NOAA-EMC#145 from AlysonStahl-NOAA/as_config
Browse files Browse the repository at this point in the history
build config.h with cmake
  • Loading branch information
AlysonStahl-NOAA authored Jul 8, 2024
2 parents 806606b + 9401f02 commit f21c83a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build
.DS_Store
*.o
*.o
29 changes: 3 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ option(USE_PROJ4 "Use Proj4?" off)
option(USE_WMO_VALIDATION "Use WMO Validation?" off)
option(DISABLE_TIMEZONE "Disable posix Timezone?" off)
option(DISABLE_ALARM "Disable Alarm?" off)
option(DISABLE_STAT "disable posix feature" off)
set(USE_NAMES "NCEP")
option(USE_G2CLIB "Use g2c lib?" off)
option(USE_PNG "Use PNG?" off)
Expand Down Expand Up @@ -137,31 +136,8 @@ endif()

# write config.h
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")
FILE(APPEND "wgrib2/config.h" "#define _CONFIG_H\n")

FOREACH(var IN ITEMS USE_NETCDF3 USE_REGEX USE_TIGGE USE_MYSQL
USE_IPOLATES USE_UDF USE_OPENMP USE_PROJ4 USE_WMO_VALIDATION DISABLE_TIMEZONE
DISABLE_ALARM USE_NAMES USE_G2CLIB USE_PNG USE_JASPER USE_OPENJPEG MAKE_FTN_API USE_AEC BUILD_COMMENTS)

# FILE(APPEND "wgrib2/config.h" "#test ${var} ${${var}}\n")
if(${var} STREQUAL ON)
FILE(APPEND "wgrib2/config.h" "#define ${var}\n")
elseif(${var} STREQUAL OFF)
FILE(APPEND "wgrib2/config.h" "// #define ${var}\n")
elseif(${${var}} MATCHES " ")
FILE(APPEND "wgrib2/config.h" "#define ${var} \"${${var}}\"\n")
else()
FILE(APPEND "wgrib2/config.h" "#define ${var} ${${var}}\n")
endif()
ENDFOREACH()

FILE(APPEND "wgrib2/config.h" "#define CC \"${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ID}\"\n")
FILE(APPEND "wgrib2/config.h" "#define FORTRAN \"${CMAKE_Fortran_COMPILER} ${CMAKE_Fortran_COMPILER_ID}\"\n")
FILE(APPEND "wgrib2/config.h" "#define CPPFLAGS \"${CMAKE_C_FLAGS}\"\n")
FILE(APPEND "wgrib2/config.h" "#define FFLAGS \"${CMAKE_Fortran_FLAGS}\"\n")
FILE(APPEND "wgrib2/config.h" "#endif\n")
configure_file("${PROJECT_SOURCE_DIR}/wgrib2/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h")
include_directories(${CMAKE_CURRENT_BINARY_DIR})

message(STATUS "Adding wgrib2, aux_probs subdirectories...")
add_subdirectory(wgrib2)
Expand Down Expand Up @@ -200,6 +176,7 @@ endif()
if (BUILD_WGRIB)
add_subdirectory(wgrib)
endif()

# Turn on unit testing.
include(CTest)
if(BUILD_TESTING)
Expand Down
40 changes: 40 additions & 0 deletions wgrib2/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* config.h generated by cmake */
#ifndef _CONFIG_H
#define _CONFIG_H

#cmakedefine USE_NETCDF3
#cmakedefine USE_NETCDF4
#cmakedefine USE_HDF5
#cmakedefine USE_REGEX
#cmakedefine USE_TIGGE
#cmakedefine USE_MYSQL
#cmakedefine USE_IPOLATES
#cmakedefine USE_UDF
#cmakedefine USE_OPENMP
#cmakedefine USE_PROJ4
#cmakedefine USE_WMO_VALIDATION
#cmakedefine DISABLE_TIMEZONE
#cmakedefine DISABLE_ALARM
#cmakedefine USE_NAMES @USE_NAMES@
#cmakedefine USE_G2CLIB
#cmakedefine USE_PNG
#cmakedefine USE_JASPER
#cmakedefine USE_OPENJPEG
#cmakedefine USE_AEC
#cmakedefine FTP_TEST_FILES
#cmakedefine FTP_LARGE_TEST_FILES
#cmakedefine FTP_EXTRA_TEST_FILES
#cmakedefine MAKE_FTN_API
#cmakedefine DISABLE_STAT
#cmakedefine BUILD_LIB
#cmakedefine BUILD_SHARED_LIB
#cmakedefine BUILD_WGRIB
#cmakedefine TEST_FILE_DIR "@TEST_FILE_DIR@"

#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
25 changes: 0 additions & 25 deletions wgrib2/config.h.ori

This file was deleted.

6 changes: 0 additions & 6 deletions wgrib2/wgrib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
#define USE_NETCDF
#endif

#ifndef WGRIB2_VERSION
#define WGRIB2_VERSION "v3.1.4beta1 11/2023 Wesley Ebisuzaki, Reinoud Bokhorst, John Howard, Jaakko Hyvätti, Dusan Jovic, \
Daniel Lee, Kristian Nilssen, Karl Pfeiffer, Pablo Romero, Manfred Schwarb, Gregor Schee, Arlindo da Silva, \
Niklas Sondell, Sam Trahan, George Trojan, Sergey Varlamov"
#endif

#ifndef BUILD_COMMENTS
#define BUILD_COMMENTS "unknown build"
#endif
Expand Down

0 comments on commit f21c83a

Please sign in to comment.