Skip to content

Commit

Permalink
cmake working in min setup
Browse files Browse the repository at this point in the history
  • Loading branch information
webisu committed Feb 7, 2024
1 parent ebda98b commit 318e30d
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 117 deletions.
133 changes: 69 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
cmake_minimum_required(VERSION 3.12)
project(wgrib2 VERSION 2.0.8 LANGUAGES Fortran C)
project(wgrib2 VERSION 3.1.4 LANGUAGES Fortran C)


option(USE_NETCDF3 "Use NetCDF-3?" off)
option(USE_NETCDF4 "Use NetCDF-4?" off)
option(USE_HDF5 "Use HDF5?" off)
option(USE_REGEX "Use Regex?" on)
option(USE_TIGGE "Use tigge?" on)
option(USE_MYSQL "Use MySQL?" off)
# option(USE_IPOLATES "iplib=0,1,3?" 3)
set(USE_IPOLATES 3)
option(USE_UDF "Use UDF?" off)
option(USE_OPENMP "Use OpenMP?" off)
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)
option(USE_JASPER "Use Jasper?" off)
option(USE_OPENJPEG "Use OpenJPEG?" off)
option(USE_AEC "Use AEC?" off)
option(MAKE_FTN_API "add ftn api?" on)
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")

Expand Down Expand Up @@ -28,28 +58,6 @@ elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_Fortran_FLAGS_DEBUG "-ggdb -O0")
endif()

option(USE_NETCDF3 "Use NetCDF-3?" off)
option(USE_NETCDF4 "Use NetCDF-4?" off)
option(USE_REGEX "Use Regex?" on)
option(USE_TIGGE "Use tigge?" on)
option(USE_MYSQL "Use MySQL?" off)
set(USE_IPOLATES "0" CACHE STRING "")
option(USE_SPECTRAL "Use SP lib?" off)
option(USE_UDF "Use UDF?" off)
option(OPENMP "Use OpenMP?" off)
option(USE_PROJ4 "Use Proj4?" off)
option(USE_WMO_VALIDATION "Use WMO Validation?" off)
option(DISABLE_TIMEZONE "Disable Timezone?" off)
option(DISABLE_ALARM "Disable Alarm?" off)

option(USE_G2CLIB "Use g2c lib?" off)
option(USE_PNG "Use PNG?" off)
option(USE_JASPER "Use Jasper?" off)
option(USE_AEC "Use AEC?" off)

option(BUILD_LIB "Build wgrib2 library?" on)
option(BUILD_SHARED_LIB "Build shared library?" off)


if(USE_G2CLIB)
if(USE_PNG)
Expand All @@ -65,40 +73,14 @@ if(USE_NETCDF3 AND USE_NETCDF4)
message(FATAL_ERROR "USE_NETCDF3 OR USE_NetCDF4, not both")
endif()

if(USE_REGEX)
list(APPEND definitions_list -DUSE_REGEX)
endif()

if(USE_TIGGE)
list(APPEND -DUSE_TIGGE)
endif()

if(DISABLE_ALARM)
list(APPEND definitions_list -DDISABLE_ALARM)
endif()

if(DISABLE_TIMEZONE)
list(APPEND definitions_list -DDISABLE_TIMEZONE)
endif()

if(USE_UDF)
list(APPEND definitions_list -DUSE_UDF)
endif()

if(USE_IPOLATES EQUAL 1)
find_package(ip CONFIG REQUIRED)
find_package(sp CONFIG REQUIRED)
elseif(USE_IPOLATES EQUAL 3)
find_package(ip2 CONFIG REQUIRED)
list(APPEND definitions_list -DUSE_SPECTRAL=1)
endif()

if(NOT USE_IPOLATES EQUAL 0)
list(APPEND definitions_list -DIPOLATES_LIB="ipolates_lib")
endif()

list(APPEND definitions_list -DUSE_IPOLATES=${USE_IPOLATES})

if(USE_NETCDF4)
find_package(NetCDF MODULE REQUIRED COMPONENTS C)
list(APPEND definitions_list -DUSE_NETCDF4 -DUSE_HDF5 -DHDF5="hdf5")
Expand All @@ -112,27 +94,50 @@ if(USE_JASPER)
endif()
endif()

if(OPENMP)
list(APPEND definitions_list -DUSE_OPENMP)
if(USE_OPENMP)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_CXX)
endif()
# if(OpenMP_Fortran_FOUND)
# target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_Fortran)
# endif()
endif()

if(USE_G2CLIB)
list(APPEND definitions_list -DUSE_G2CLIB)
endif()

if(USE_PROJ4)
list(APPEND definitions_list -DUSE_PROJ4)
endif()

if(USE_PNG)
find_package(PNG REQUIRED)
list(APPEND definitions_list -DUSE_PNG)
endif()

if(USE_WMO_VALIDATION)
list(APPEND definitions_list -DUSE_WMO_VALIDATION)
endif()


# write config.h
FILE(WRITE "wgrib2/config.h" "/* config.h generated by cmake */\n")
FOREACH(var IN ITEMS USE_NETCDF3 USE_NETCDF4 USE_HDF5 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")








add_subdirectory(wgrib2)
add_subdirectory(aux_progs)
Expand Down
Loading

0 comments on commit 318e30d

Please sign in to comment.