Skip to content

Commit

Permalink
Merge branch 'develop' into cmake4
Browse files Browse the repository at this point in the history
  • Loading branch information
webisu authored Apr 12, 2024
2 parents f48fd2f + 93346bf commit 12bfa3e
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 255 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/Linux_options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# This is the Linux_options workflow for the wgrib2 project. This
# tests different wgrib2 build options.
#
# Ed Hartnett, 3/27/24
name: Linux_options
on:
push:
branches:
- develop
pull_request:
branches:
- develop

# Cancel in-progress workflows when pushing to a branch
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
Linux_options:
runs-on: ubuntu-latest
env:
FC: gfortran
CC: gcc

strategy:
# fail-fast: true
matrix:
config:
- {
options: "-DUSE_IPOLATES=1"
}

steps:

- name: install
run: |
sudo apt-get update
sudo apt-get install libnetcdf-dev libnetcdff-dev netcdf-bin pkg-config
sudo apt-get install libpng-dev autotools-dev autoconf
- name: checkout-jasper
uses: actions/checkout@v2
with:
repository: jasper-software/jasper
path: jasper
ref: version-1.900.1

- name: build-jasper
if: steps.cache-jasper.outputs.cache-hit != 'true'
run: |
cd jasper
./configure --prefix=$HOME/Jasper
make
make install
- name: checkout-sp
uses: actions/checkout@v2
with:
repository: NOAA-EMC/NCEPLIBS-sp
path: sp
ref: v2.3.3

- name: build-sp
run: |
cd sp
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=~/sp -DBUILD_8=ON ..
make -j2
make install
- name: cache-ip
id: cache-ip
uses: actions/cache@v3
with:
path: ~/ip
key: ip-${{ runner.os }}-${{ matrix.ip-version }}

- name: checkout-ip
if: steps.cache-ip.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: NOAA-EMC/NCEPLIBS-ip
path: ip
ref: v3.3.3

- name: build-ip
if: steps.cache-ip.outputs.cache-hit != 'true'
run: |
cd ip
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=~/ip -DCMAKE_PREFIX_PATH=~/sp
make -j2
make install
- name: checkout-ip2
uses: actions/checkout@v2
with:
repository: NOAA-EMC/NCEPLIBS-ip2
path: ip2
ref: develop

- name: build-ip2
run: |
cd ip2
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=~/ip2 -DCMAKE_PREFIX_PATH=~
make -j2
make install
- name: checkout
uses: actions/checkout@v2
with:
path: wgrib2

- name: build
run: |
cd wgrib2
mkdir b
cd b
cmake ${{ matrix.config.options }} -DCMAKE_PREFIX_PATH="~/sp;~/ip;~/ip2" ..
make VERBOSE=1
32 changes: 25 additions & 7 deletions .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ on:
branches:
- develop

# Cancel in-progress workflows when pushing to a branch
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
developer:
runs-on: ubuntu-latest
Expand All @@ -23,10 +28,10 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install libnetcdf-dev libnetcdff-dev netcdf-bin pkg-config
sudo apt-get install libpng-dev autotools-dev autoconf
sudo apt-get install libpng-dev autotools-dev autoconf gcovr
- name: checkout-jasper
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: jasper-software/jasper
path: jasper
Expand All @@ -41,7 +46,7 @@ jobs:
make install
- name: checkout-sp
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: NOAA-EMC/NCEPLIBS-sp
path: sp
Expand All @@ -57,7 +62,7 @@ jobs:
make install
- name: checkout-ip2
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: NOAA-EMC/NCEPLIBS-ip2
path: ip2
Expand All @@ -73,14 +78,27 @@ jobs:
make install
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
path: wgrib2

- name: build
run: |
cd wgrib2
mkdir b
cd b
mkdir build
cd build
export CFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
export FCFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
export FFLAGS='-Wall -g -fprofile-abs-path -fprofile-arcs -ftest-coverage -O0'
cmake ..
make VERBOSE=1
ctest --verbose --output-on-failure --rerun-failed
gcovr --root .. -v --html-details --exclude ../tests --exclude CMakeFiles --print-summary -o test-coverage.html &> /dev/null
- name: upload-test-coverage
uses: actions/upload-artifact@v4
with:
name: wgrib2-test-coverage
path: |
wgrib2/build/*.html
wgrib2/build/*.css
52 changes: 36 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# this is the main CMake file for wgrib2
# 3/2024 wesley ebisuzaki, kyle gerheiser,
# This is the main CMake build file for the wgrib2 project.
#
# Kyle Gerheiser, Edward Hartnett, Wesley Ebisuzaki
cmake_minimum_required(VERSION 3.15)

cmake_minimum_required(VERSION 3.12)
project(wgrib2 VERSION 3.1.4 LANGUAGES Fortran C)
# Read the current version number from file VERSION.
file(STRINGS "VERSION" pVersion)

# Set up project with version number from VERSION file.
project(wgrib2 VERSION ${pVersion} LANGUAGES Fortran C)

# Handle user build options.
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 0)
option(USE_IPOLATES "iplib=0,1,3?" 3)
option(USE_UDF "Use UDF?" off)
option(USE_OPENMP "Use OpenMP?" on)
option(USE_PROJ4 "Use Proj4?" off)
Expand All @@ -30,14 +34,12 @@ option(USE_AEC "Use AEC?" on)
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"
Expand All @@ -46,11 +48,12 @@ endif()

include(GNUInstallDirs)

message(STATUS "Setting compiler flags...")
if(CMAKE_C_COMPILER_ID MATCHES "^(Intel)$")
set(CMAKE_C_FLAGS "-g -traceback ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-g -traceback ${CMAKE_C_FLAGS} -DIFORT")
set(CMAKE_C_FLAGS_DEBUG "-O0")
elseif(CMAKE_C_COMPILER_ID MATCHES "^(GNU)$")
set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS} -DGFORTRAN")
set(CMAKE_C_FLAGS_DEBUG "-O0")
endif()

Expand All @@ -63,6 +66,7 @@ elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$")
endif()


message(STATUS "Checking if user wants to use NCEPLIBS-g2c...")
if(USE_G2CLIB)
if(USE_PNG)
message(FATAL_ERROR "If USE_G2CLIB is on, USE_PNG must be off")
Expand All @@ -77,19 +81,27 @@ if(USE_NETCDF3 AND USE_NETCDF4)
message(FATAL_ERROR "USE_NETCDF3 OR USE_NetCDF4, not both")
endif()


# If user wants to use NCEPLIBS-ip, find it and the sp library.
message(STATUS "Checking if the user want to use NCEPLIBS-ip...")
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)
endif()

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

message(STATUS "Checking if the user want to use NetCDF...")
if(USE_NETCDF4)
find_package(NetCDF MODULE REQUIRED COMPONENTS C)
list(APPEND definitions_list -DUSE_NETCDF4 -DUSE_HDF5 -DHDF5="hdf5")
endif()

message(STATUS "Checking if the user wants to use Jasper...")
if(USE_JASPER)
list(APPEND definitions_list -DUSE_JASPER)
find_package(Jasper REQUIRED)
Expand All @@ -98,6 +110,7 @@ if(USE_JASPER)
endif()
endif()

message(STATUS "Checking if the user want to use OpenMP...")
if(USE_OPENMP)
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
Expand All @@ -108,13 +121,15 @@ if(USE_OPENMP)
# endif()
endif()

message(STATUS "Checking of the user wants to use PNG...")
if(USE_PNG)
find_package(ZLIB REQUIRED)
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")
FILE(APPEND "wgrib2/config.h" "#define _CONFIG_H\n")
Expand Down Expand Up @@ -154,9 +169,8 @@ endif()
add_subdirectory(wgrib2)
add_subdirectory(aux_progs)


if(BUILD_LIB)

message(STATUS "Adding wgrib2 library build...")
### Package config
include(CMakePackageConfigHelpers)
set(CONFIG_INSTALL_DESTINATION lib/cmake/${PROJECT_NAME})
Expand Down Expand Up @@ -185,3 +199,9 @@ if(BUILD_LIB)
DESTINATION ${CONFIG_INSTALL_DESTINATION})
endif()

# Turn on unit testing.
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
endif()

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.0
30 changes: 30 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This is the CMake file for the test directory in the wgrib2
# project.
#
# Ed Hartnett 3/27/24

# Run each shell test.
function(shell_test name)
# Copy the test scripts.
file(COPY "${CMAKE_SOURCE_DIR}/tests/${name}.sh"
DESTINATION ${CMAKE_BINARY_DIR}/tests
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
# Add the shell script as a test.
add_test(NAME ${name}.sh COMMAND bash ${name}.sh)
endfunction()

# Some very small test files may be committed to the repo. This
# function copies such a data file to the build directory.
function(copy_test_data name)
message(STATUS "Copying test file ${name}")
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/data/${name}"
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endfunction()

# Copy test data file into buiild directory for testing.
copy_test_data(gdaswave.t00z.wcoast.0p16.f000.grib2)
copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib2.inv)

# Run these shell tests.
shell_test(run_wgrib2_tests)
Binary file added tests/data/gdaswave.t00z.wcoast.0p16.f000.grib2
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2.inv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
1:0:d=2021113000:WIND:surface:anl:
2:15254:d=2021113000:WDIR:surface:anl:
3:37897:d=2021113000:UGRD:surface:anl:
4:53794:d=2021113000:VGRD:surface:anl:
5:69064:d=2021113000:HTSGW:surface:anl:
6:79482:d=2021113000:PERPW:surface:anl:
7:91308:d=2021113000:DIRPW:surface:anl:
8:108541:d=2021113000:WVHGT:surface:anl:
9:116716:d=2021113000:SWELL:1 in sequence:anl:
10:128832:d=2021113000:SWELL:2 in sequence:anl:
11:140848:d=2021113000:SWELL:3 in sequence:anl:
12:151732:d=2021113000:WVPER:surface:anl:
13:161021:d=2021113000:SWPER:1 in sequence:anl:
14:173676:d=2021113000:SWPER:2 in sequence:anl:
15:189425:d=2021113000:SWPER:3 in sequence:anl:
16:205285:d=2021113000:WVDIR:surface:anl:
17:218263:d=2021113000:SWDIR:1 in sequence:anl:
18:237035:d=2021113000:SWDIR:2 in sequence:anl:
19:259223:d=2021113000:SWDIR:3 in sequence:anl:
Loading

0 comments on commit 12bfa3e

Please sign in to comment.