Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Findwgrib2.cmake #578

Merged
merged 6 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Create Findwgrib2.cmake to handle stock (non-CMake) build of wgrib2
FindWgrib2.cmake uses the target wgrib2::wgrib2 instead of wgrib2::wgrib2_lib and wgrib2::wgrib2_api
  • Loading branch information
kgerheiser committed Sep 30, 2021
commit 10ccd65ac9fbf8b8f4bb35d991c4f3d6d08c1115
12 changes: 8 additions & 4 deletions .github/workflows/debug-docs-test_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/esmf
key: esmf-8.0.1-${{ runner.os }}
key: esmf-8.0.1-${{ runner.os }}3

- name: build-esmf
if: steps.cache-esmf.outputs.cache-hit != 'true'
Expand All @@ -53,7 +53,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/jasper
key: jasper-2.0.25-${{ runner.os }}
key: jasper-2.0.25-${{ runner.os }}3

- name: build-jasper
if: steps.cache-jasper.outputs.cache-hit != 'true'
Expand All @@ -62,7 +62,7 @@ jobs:
tar zxf version-2.0.25.tar.gz
cd jasper-version-2.0.25
mkdir build-jasper && cd build-jasper
cmake .. -DCMAKE_INSTALL_PREFIX=~/jasper
cmake .. -DCMAKE_INSTALL_PREFIX=~/jasper -DJAS_ENABLE_SHARED=OFF
make -j2
make install

Expand All @@ -71,7 +71,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/nceplibs
key: nceplibs-1.3.0-${{ runner.os }}
key: nceplibs-1.3.0-${{ runner.os }}3

- name: build-nceplibs
if: steps.cache-nceplibs.outputs.cache-hit != 'true'
Expand All @@ -97,6 +97,10 @@ jobs:
export CC=mpicc
export CXX=mpicxx
export FC=mpifort
# Findwgrib2 in module form does not search <libname>-version
# as NCEPLIBS installs it
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
export wgrib2_ROOT=`find ~/nceplibs -type d -maxdepth 1 -iname "wgrib2*"`
cmake .. -DCMAKE_PREFIX_PATH='~/jasper;~/nceplibs' -DCMAKE_BUILD_TYPE=Debug -DENABLE_DOCS=On -DCMAKE_Fortran_FLAGS="-g -fprofile-arcs -ftest-coverage -O0"
make -j2

Expand Down
22 changes: 14 additions & 8 deletions .github/workflows/intel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/netcdf
key: netcdf-c-$4.7.4-{{ runner.os }}-intel
key: netcdf-c-$4.7.4-{{ runner.os }}-intel3

- name: build-hdf5
if: steps.cache-netcdf.outputs.cache-hit != 'true'
Expand All @@ -46,7 +46,7 @@ jobs:
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.7/src/hdf5-1.10.7.tar.gz &> /dev/null
tar -xzf hdf5-1.10.7.tar.gz
pushd hdf5-1.10.7
./configure --prefix=${HOME}/netcdf --enable-parallel --disable-tools --disable-fortran --disable-cxx --enable-parallel-tests
./configure --prefix=${HOME}/netcdf --enable-parallel --disable-tools --disable-fortran --disable-cxx --enable-parallel-tests --disable-shared --disable-shared --enable-static
make -j2
make install

Expand All @@ -59,7 +59,7 @@ jobs:
wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-4.7.4.tar.gz &> /dev/null
tar -xzf netcdf-c-4.7.4.tar.gz
pushd netcdf-c-4.7.4
./configure --prefix=${HOME}/netcdf --disable-dap --disable-utilities
./configure --prefix=${HOME}/netcdf --disable-dap --disable-utilities --disable-shared
make -j2
make install

Expand All @@ -72,10 +72,11 @@ jobs:
export FC=mpiifort
export CPPFLAGS=-I${HOME}/netcdf/include
export LDFLAGS=-L${HOME}/netcdf/lib
export LIBS=`nc-config --libs`
wget https://github.com/Unidata/netcdf-fortran/archive/v4.5.3.tar.gz &> /dev/null
tar -xzf v4.5.3.tar.gz
pushd netcdf-fortran-4.5.3
./configure --prefix=${HOME}/netcdf
./configure --prefix=${HOME}/netcdf --disable-shared
make -j2
make install

Expand All @@ -84,7 +85,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/esmf
key: esmf-8.0.1-${{ runner.os }}-intel
key: esmf-8.0.1-${{ runner.os }}-intel3

- name: build-esmf
if: steps.cache-esmf.outputs.cache-hit != 'true'
Expand All @@ -103,6 +104,7 @@ jobs:
export ESMF_NETCDF=split
export ESMF_NETCDF_INCLUDE=${HOME}/netcdf/include
export ESMF_NETCDF_LIBPATH=${HOME}/netcdf/lib
export ESMF_NETCDF_LIBS="-lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz"
make -j2
make install

Expand All @@ -111,7 +113,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/jasper
key: jasper-2.0.25-${{ runner.os }}-intel
key: jasper-2.0.25-${{ runner.os }}-intel3

- name: build-jasper
if: steps.cache-jasper.outputs.cache-hit != 'true'
Expand All @@ -120,7 +122,7 @@ jobs:
tar zxf version-2.0.25.tar.gz
cd jasper-version-2.0.25
mkdir build-jasper && cd build-jasper
cmake .. -DCMAKE_INSTALL_PREFIX=~/jasper
cmake .. -DCMAKE_INSTALL_PREFIX=~/jasper -DJAS_ENABLE_SHARED=OFF
make -j2
make install

Expand All @@ -135,7 +137,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/nceplibs
key: nceplibs-1.3.0-${{ runner.os }}-intel
key: nceplibs-1.3.0-${{ runner.os }}-intel3

- name: build-nceplibs
if: steps.cache-nceplibs.outputs.cache-hit != 'true'
Expand All @@ -158,6 +160,10 @@ jobs:
export ESMFMKFILE=~/esmf/lib/esmf.mk
cd ufs_utils
mkdir build && cd build
# Findwgrib2 in module form does not search <libname>-version
# as NCEPLIBS installs it
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
export wgrib2_ROOT=`find ~/nceplibs -type d -maxdepth 1 -iname "wgrib2*"`
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH='~;~/jasper;~/nceplibs;~/netcdf'
make -j2

Expand Down
23 changes: 15 additions & 8 deletions .github/workflows/linux-mac-nceplibs-mpi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/netcdf
key: netcdf-c-${{ matrix.netcdf_version }}-${{ runner.os }}-${{ matrix.mpi_type }}
key: netcdf-c-${{ matrix.netcdf_version }}-${{ runner.os }}-${{ matrix.mpi_type }}3

- name: build-hdf5
if: steps.cache-netcdf.outputs.cache-hit != 'true'
Expand All @@ -84,7 +84,7 @@ jobs:
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.7/src/hdf5-1.10.7.tar.gz &> /dev/null
tar -xzf hdf5-1.10.7.tar.gz
pushd hdf5-1.10.7
./configure --prefix=${HOME}/netcdf --enable-parallel --disable-tools --disable-fortran --disable-cxx --enable-parallel-tests
./configure --prefix=${HOME}/netcdf --enable-parallel --disable-tools --disable-fortran --disable-cxx --enable-parallel-tests --disable-shared --enable-static
make -j2
make install

Expand All @@ -97,7 +97,7 @@ jobs:
wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-${{ matrix.netcdf_version }}.tar.gz &> /dev/null
tar -xzf netcdf-c-${{ matrix.netcdf_version }}.tar.gz
cd netcdf-c-${{ matrix.netcdf_version }}
./configure --prefix=${HOME}/netcdf --disable-dap --disable-utilities
./configure --prefix=${HOME}/netcdf --disable-dap --disable-utilities --disable-shared
make -j2
make install

Expand All @@ -110,10 +110,11 @@ jobs:
export FC=mpifort
export CPPFLAGS=-I${HOME}/netcdf/include
export LDFLAGS=-L${HOME}/netcdf/lib
export LIBS=`nc-config --libs`
wget https://github.com/Unidata/netcdf-fortran/archive/v4.5.3.tar.gz &> /dev/null
tar -xzf v4.5.3.tar.gz
pushd netcdf-fortran-4.5.3
./configure --prefix=${HOME}/netcdf
./configure --prefix=${HOME}/netcdf --disable-shared
make -j2
make install

Expand All @@ -122,7 +123,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/esmf
key: esmf--8.0.1-${{ runner.os }}-${{ matrix.mpi_type }}-netcdf-${{ matrix.netcdf_version }}
key: esmf--8.0.1-${{ runner.os }}-${{ matrix.mpi_type }}-netcdf-${{ matrix.netcdf_version }}3

- name: build-esmf
if: steps.cache-esmf.outputs.cache-hit != 'true'
Expand All @@ -146,6 +147,7 @@ jobs:
export ESMF_NETCDF=split
export ESMF_NETCDF_INCLUDE=${HOME}/netcdf/include
export ESMF_NETCDF_LIBPATH=${HOME}/netcdf/lib
export ESMF_NETCDF_LIBS="-lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz"
make -j2
make install

Expand All @@ -154,7 +156,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/jasper
key: jasper-2.0.25-${{ runner.os }}
key: jasper-2.0.25-${{ runner.os }}3

- name: build-jasper
if: steps.cache-jasper.outputs.cache-hit != 'true'
Expand All @@ -165,7 +167,7 @@ jobs:
tar zxf version-2.0.25.tar.gz
cd jasper-version-2.0.25
mkdir build-jasper && cd build-jasper
cmake .. -DCMAKE_INSTALL_PREFIX=~/jasper
cmake .. -DCMAKE_INSTALL_PREFIX=~/jasper -DJAS_ENABLE_SHARED=OFF
make -j2
make install

Expand All @@ -187,7 +189,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/nceplibs
key: nceplibs-${{ matrix.nceplibs_version }}-${{ runner.os }}-${{ matrix.mpi_type }}-${{ hashFiles('nceplibs/hash.txt') }}
key: nceplibs-${{ matrix.nceplibs_version }}-${{ runner.os }}-${{ matrix.mpi_type }}-${{ hashFiles('nceplibs/hash.txt') }}3

- name: build-nceplibs
if: steps.cache-nceplibs.outputs.cache-hit != 'true'
Expand All @@ -212,6 +214,11 @@ jobs:
export CC=mpicc
export CXX=mpicxx
export FC=mpifort
# Findwgrib2 in module form does not search <libname>-version
# as NCEPLIBS installs it
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
export DYLD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
export wgrib2_ROOT=`find ~/nceplibs -type d -maxdepth 1 -iname "wgrib2*"`
cmake .. -DCMAKE_PREFIX_PATH='~/jasper;~/nceplibs;~/netcdf'
make -j2

Expand Down
22 changes: 14 additions & 8 deletions .github/workflows/netcdf-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/netcdf
key: netcdf-c-${{ matrix.netcdf_version }}-${{ runner.os }}
key: netcdf-c-${{ matrix.netcdf_version }}-${{ runner.os }}3

- name: build-hdf5
if: steps.cache-netcdf.outputs.cache-hit != 'true'
Expand All @@ -37,7 +37,7 @@ jobs:
wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.7/src/hdf5-1.10.7.tar.gz &> /dev/null
tar -xzf hdf5-1.10.7.tar.gz
pushd hdf5-1.10.7
./configure --prefix=${HOME}/netcdf --enable-parallel --disable-tools --disable-fortran --disable-cxx --enable-parallel-tests
./configure --prefix=${HOME}/netcdf --enable-parallel --disable-tools --disable-fortran --disable-cxx --enable-parallel-tests --disable-shared --enable-static
make -j2
make install

Expand All @@ -50,7 +50,7 @@ jobs:
wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-${{ matrix.netcdf_version }}.tar.gz &> /dev/null
tar -xzf netcdf-c-${{ matrix.netcdf_version }}.tar.gz
cd netcdf-c-${{ matrix.netcdf_version }}
./configure --prefix=${HOME}/netcdf --disable-dap --disable-utilities
./configure --prefix=${HOME}/netcdf --disable-dap --disable-utilities --disable-shared
make -j2
make install

Expand All @@ -63,10 +63,11 @@ jobs:
export FC=mpifort
export CPPFLAGS=-I${HOME}/netcdf/include
export LDFLAGS=-L${HOME}/netcdf/lib
export LIBS=`nc-config --libs`
wget https://github.com/Unidata/netcdf-fortran/archive/v4.5.3.tar.gz &> /dev/null
tar -xzf v4.5.3.tar.gz
pushd netcdf-fortran-4.5.3
./configure --prefix=${HOME}/netcdf
./configure --prefix=${HOME}/netcdf --disable-shared
make -j2
make install

Expand All @@ -75,7 +76,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/esmf
key: esmf-8.0.1-${{ runner.os }}-netcdf-${{ matrix.netcdf_version }}
key: esmf-8.0.1-${{ runner.os }}-netcdf-${{ matrix.netcdf_version }}3

- name: build-esmf
#if: steps.cache-esmf.outputs.cache-hit != 'true'
Expand All @@ -94,6 +95,7 @@ jobs:
export ESMF_NETCDF=split
export ESMF_NETCDF_INCLUDE=${HOME}/netcdf/include
export ESMF_NETCDF_LIBPATH=${HOME}/netcdf/lib
export ESMF_NETCDF_LIBS="-lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz"
make -j2
make install

Expand All @@ -102,7 +104,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/jasper
key: jasper-2.0.25-${{ runner.os }}
key: jasper-2.0.25-${{ runner.os }}3

- name: build-jasper
if: steps.cache-jasper.outputs.cache-hit != 'true'
Expand All @@ -111,7 +113,7 @@ jobs:
tar zxf version-2.0.25.tar.gz
cd jasper-version-2.0.25
mkdir build-jasper && cd build-jasper
cmake .. -DCMAKE_INSTALL_PREFIX=~/jasper
cmake .. -DCMAKE_INSTALL_PREFIX=~/jasper -DJAS_ENABLE_SHARED=OFF
make -j2
make install

Expand All @@ -120,7 +122,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/nceplibs
key: nceplibs-1.3.0-${{ runner.os }}-netcdf-${{ matrix.netcdf_version }}
key: nceplibs-1.3.0-${{ runner.os }}-netcdf-${{ matrix.netcdf_version }}3

- name: build-nceplibs
if: steps.cache-nceplibs.outputs.cache-hit != 'true'
Expand All @@ -146,6 +148,10 @@ jobs:
export CC=mpicc
export CXX=mpicxx
export FC=mpifort
# Findwgrib2 in module form does not search <libname>-version
# as NCEPLIBS installs it
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
export wgrib2_ROOT=`find ~/nceplibs -type d -maxdepth 1 -iname "wgrib2*"`
cmake .. -DCMAKE_PREFIX_PATH='~/jasper;~/nceplibs;~/netcdf' -DCMAKE_BUILD_TYPE=Debug
make -j2

Expand Down
41 changes: 41 additions & 0 deletions cmake/Findwgrib2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This module produces the target wgrib2::wgrib2

find_path(WGRIB2_INCLUDES wgrib2api.mod)
find_library(WGRIB2_LIB libwgrib2.a)
find_library(WGRIB2_API_LIB libwgrib2_api.a)

add_library(wgrib2::wgrib2 UNKNOWN IMPORTED)

# Library builds are different between CMake build and the make build.
# libwgrib2_api.a is only necessary in the CMake build and must come first when linking
if(WGRIB2_API_LIB)
# CMake build. Need both.
set(first_lib ${WGRIB2_API_LIB})
set(second_lib ${WGRIB2_LIB})
else()
# Makefile build. Only need libwgrib2.a
set(FIRST_LIB ${WGRIB2_LIB})
set(second_lib "")
endif()

set_target_properties(wgrib2::wgrib2 PROPERTIES
IMPORTED_LOCATION "${first_lib}"
INTERFACE_INCLUDE_DIRECTORIES "${WGRIB2_INCLUDES}"
INTERFACE_LINK_LIBRARIES "${second_lib}")

set(WGRIB2_LIBRARIES "${first_lib}" "${second_lib}")

find_program(WGRIB2_EXE wgrib2)
execute_process(COMMAND ${WGRIB2_EXE} --version OUTPUT_VARIABLE version_str)

# Wgrib2 changed how it output --version from "v0.x.y.z" to "vx.y.z" starting in wgrib2 3.0
if(version_str MATCHES "^v0.*")
string(SUBSTRING "${version_str}" 3 5 version)
else()
string(SUBSTRING "${version_str}" 1 5 version)
endif()

find_package_handle_standard_args(wgrib2
REQUIRED_VARS WGRIB2_LIBRARIES WGRIB2_INCLUDES WGRIB2_EXE
VERSION_VAR version
)
3 changes: 1 addition & 2 deletions sorc/chgres_cube.fd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ target_link_libraries(
sp::sp_d
w3nco::w3nco_d
esmf
wgrib2::wgrib2_lib
wgrib2::wgrib2_api
wgrib2::wgrib2
MPI::MPI_Fortran
NetCDF::NetCDF_Fortran)

Expand Down