Skip to content

Commit cfcd089

Browse files
authored
Add CMake build to WW3 (#533)
CMake provides a portable and standardized build system and out-of-source builds. This means a faster and simpler build system. See README for more documentation.
1 parent 0496d36 commit cfcd089

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5053
-406
lines changed

.github/workflows/gnu.yml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: GNU Linux Build
2+
on: [push, pull_request]
3+
4+
env:
5+
cache_key: gnu3
6+
CC: gcc-10
7+
FC: gfortran-10
8+
CXX: g++-10
9+
10+
# Split into a steup step, and a WW3 build step which
11+
# builds multiple switches in a matrix. The setup is run once and
12+
# the environment is cached so each build of WW3 can share the dependencies.
13+
14+
jobs:
15+
setup:
16+
runs-on: ubuntu-20.04
17+
18+
steps:
19+
# Cache spack, OASIS, and compiler
20+
# No way to flush Action cache, so key may have # appended
21+
- name: cache-env
22+
id: cache-env
23+
uses: actions/cache@v2
24+
with:
25+
path: |
26+
spack
27+
~/.spack
28+
work_oasis3-mct
29+
key: spack-${{ runner.os }}-${{ env.cache_key }}
30+
31+
- name: checkout-ww3
32+
if: steps.cache-env.outputs.cache-hit != 'true'
33+
uses: actions/checkout@v2
34+
with:
35+
path: ww3
36+
37+
# Build WW3 spack environment
38+
- name: install-dependencies-with-spack
39+
if: steps.cache-env.outputs.cache-hit != 'true'
40+
run: |
41+
# Install NetCDF, ESMF, g2, etc using Spack
42+
git clone -c feature.manyFiles=true https://github.com/spack/spack.git
43+
source spack/share/spack/setup-env.sh
44+
spack env create ww3-gnu ww3/model/ci/spack.yaml
45+
spack env activate ww3-gnu
46+
spack compiler find
47+
spack external find m4 cmake pkgconf openssl
48+
49+
spack concretize
50+
spack install --dirty -v
51+
52+
- name: build-oasis
53+
if: steps.cache-env.outputs.cache-hit != 'true'
54+
run: |
55+
source spack/share/spack/setup-env.sh
56+
spack env activate ww3-gnu
57+
export WWATCH3_DIR=${GITHUB_WORKSPACE}/ww3/model
58+
cd ww3/regtests/ww3_tp2.14/input/oasis3-mct/util/make_dir
59+
mkdir build && cd build
60+
cmake ..
61+
make VERBOSE=1
62+
cp -r ${GITHUB_WORKSPACE}/ww3/regtests/ww3_tp2.14/work_oasis3-mct ${GITHUB_WORKSPACE}
63+
64+
build:
65+
needs: setup
66+
strategy:
67+
matrix:
68+
switch: [Ifremer1, NCEP_st2, NCEP_st4, ite_pdlib, NCEP_st4sbs, NCEP_glwu, OASACM, UKMO, MULTI_ESMF]
69+
runs-on: ubuntu-20.04
70+
71+
steps:
72+
- name: checkout-ww3
73+
uses: actions/checkout@v2
74+
with:
75+
path: ww3
76+
77+
- name: cache-env
78+
id: cache-env
79+
uses: actions/cache@v2
80+
with:
81+
path: |
82+
spack
83+
~/.spack
84+
work_oasis3-mct
85+
key: spack-${{ runner.os }}-${{ env.cache_key }}
86+
87+
- name: build-ww3
88+
run: |
89+
source spack/share/spack/setup-env.sh
90+
spack env activate ww3-gnu
91+
cd ww3
92+
export CC=mpicc
93+
export FC=mpif90
94+
export OASISDIR=${GITHUB_WORKSPACE}/work_oasis3-mct
95+
mkdir build && cd build
96+
if [[ ${{ matrix.switch }} == "MULTI_ESMF" ]]; then
97+
cmake .. -DMULTI_ESMF=ON -DSWITCH=multi_esmf
98+
else
99+
cmake .. -DSWITCH=${{ matrix.switch }}
100+
fi
101+
make -j2 VERBOSE=1
102+
103+

.github/workflows/intel.yml

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Intel Linux Build
2+
on: [push, pull_request]
3+
4+
# Use custom shell with -l so .bash_profile is sourced which loads intel/oneapi/setvars.sh
5+
# without having to do it in manually every step
6+
defaults:
7+
run:
8+
shell: bash -leo pipefail {0}
9+
10+
# Set I_MPI_CC/F90 so Intel MPI wrapper uses icc/ifort instead of gcc/gfortran
11+
env:
12+
cache_key: intel4
13+
CC: icc
14+
FC: ifort
15+
CXX: icpc
16+
I_MPI_CC: icc
17+
I_MPI_F90: ifort
18+
19+
# Split into a dependency build step, and a WW3 build step which
20+
# builds multiple switches in a matrix. The setup is run once and
21+
# the environment is cached so each build of WW3 can share the dependencies.
22+
23+
jobs:
24+
setup:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
# Cache spack, OASIS, and compiler
29+
# No way to flush Action cache, so key may have # appended
30+
- name: cache-env
31+
id: cache-env
32+
uses: actions/cache@v2
33+
with:
34+
path: |
35+
spack
36+
~/.spack
37+
work_oasis3-mct
38+
/opt/intel
39+
key: spack-${{ runner.os }}-${{ env.cache_key }}
40+
41+
- name: install-intel-compilers
42+
if: steps.cache-env.outputs.cache-hit != 'true'
43+
run: |
44+
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
45+
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
46+
echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
47+
sudo apt-get update
48+
sudo apt-get install intel-oneapi-dev-utilities intel-oneapi-mpi-devel intel-oneapi-openmp intel-oneapi-compiler-fortran intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic
49+
echo "source /opt/intel/oneapi/setvars.sh" >> ~/.bash_profile
50+
51+
- name: checkout-ww3
52+
if: steps.cache-env.outputs.cache-hit != 'true'
53+
uses: actions/checkout@v2
54+
with:
55+
path: ww3
56+
57+
# Build WW3 spack environment
58+
- name: install-dependencies-with-spack
59+
if: steps.cache-env.outputs.cache-hit != 'true'
60+
run: |
61+
# Install NetCDF, ESMF, g2, etc using Spack
62+
git clone -c feature.manyFiles=true https://github.com/spack/spack.git
63+
source spack/share/spack/setup-env.sh
64+
spack env create ww3-intel ww3/model/ci/spack.yaml
65+
spack env activate ww3-intel
66+
spack compiler find
67+
spack external find m4 cmake pkgconf openssl
68+
spack add intel-oneapi-mpi
69+
spack concretize
70+
spack install --dirty -v
71+
72+
- name: build-oasis
73+
if: steps.cache-env.outputs.cache-hit != 'true'
74+
run: |
75+
source spack/share/spack/setup-env.sh
76+
spack env activate ww3-intel
77+
export WWATCH3_DIR=${GITHUB_WORKSPACE}/ww3/model
78+
cd ww3/regtests/ww3_tp2.14/input/oasis3-mct/util/make_dir
79+
mkdir build && cd build
80+
cmake ..
81+
make
82+
cp -r ${GITHUB_WORKSPACE}/ww3/regtests/ww3_tp2.14/work_oasis3-mct ${GITHUB_WORKSPACE}
83+
84+
build:
85+
needs: setup
86+
strategy:
87+
matrix:
88+
switch: [Ifremer1, NCEP_st2, NCEP_st4, ite_pdlib, NCEP_st4sbs, NCEP_glwu, OASACM, UKMO, MULTI_ESMF]
89+
runs-on: ubuntu-latest
90+
91+
steps:
92+
- name: checkout-ww3
93+
uses: actions/checkout@v2
94+
with:
95+
path: ww3
96+
97+
- name: install-intel
98+
run: |
99+
echo "source /opt/intel/oneapi/setvars.sh" >> ~/.bash_profile
100+
101+
- name: cache-env
102+
id: cache-env
103+
uses: actions/cache@v2
104+
with:
105+
path: |
106+
spack
107+
~/.spack
108+
work_oasis3-mct
109+
/opt/intel
110+
key: spack-${{ runner.os }}-${{ env.cache_key }}
111+
112+
- name: build-ww3
113+
run: |
114+
source spack/share/spack/setup-env.sh
115+
spack env activate ww3-intel
116+
cd ww3
117+
export CC=mpicc
118+
export FC=mpif90
119+
export OASISDIR=${GITHUB_WORKSPACE}/work_oasis3-mct
120+
mkdir build && cd build
121+
if [[ ${{ matrix.switch }} == "MULTI_ESMF" ]]; then
122+
cmake .. -DMULTI_ESMF=ON -DSWITCH=multi_esmf
123+
else
124+
cmake .. -DSWITCH=${{ matrix.switch }}
125+
fi
126+
make -j2
127+
128+

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,5 @@ model/bin/wwatch3.env
169169
*/.*.swp
170170
*/*/.*.swp
171171
*/*/*/.*.swp
172+
.DS_Store
173+
build

CMakeLists.txt

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# CMake build written by Kyle Gerheiser
2+
3+
# Requires CMake 3.19 for JSON strings
4+
cmake_minimum_required(VERSION 3.19)
5+
6+
# Get VERSION from VERSION file
7+
file(STRINGS "VERSION" pVersion)
8+
9+
project(
10+
WW3
11+
VERSION ${pVersion}
12+
LANGUAGES C Fortran)
13+
14+
set(MULTI_ESMF OFF CACHE BOOL "Build ww3_multi_esmf library")
15+
set(NETCDF ON CACHE BOOL "Build NetCDF programs (requires NetCDF)")
16+
17+
# Make Find modules visible to CMake
18+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
19+
20+
# Set switch file on command line when running CMake
21+
set(SWITCH "" CACHE STRING "Switch file, either full path, relative path from location of top-level WW3/ dir, or a switch in model/bin")
22+
23+
# Search for switch file as a full path or in model/bin
24+
if(EXISTS ${SWITCH})
25+
set(switch_file ${SWITCH})
26+
else()
27+
set(switch_file ${CMAKE_CURRENT_SOURCE_DIR}/model/bin/switch_${SWITCH})
28+
if(NOT EXISTS ${switch_file})
29+
message(FATAL_ERROR "Switch file '${switch_file}' does not exist, set switch with -DSWITCH=<switch>")
30+
endif()
31+
endif()
32+
33+
message(STATUS "Build with switch: ${switch_file}")
34+
# Copy switch file to build dir
35+
configure_file(${switch_file} ${CMAKE_BINARY_DIR}/switch COPYONLY)
36+
37+
# Re-configure CMake when switch changes
38+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_BINARY_DIR}/switch)
39+
40+
if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$")
41+
message(STATUS "Setting build type to 'Release' as none was specified.")
42+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
43+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
44+
endif()
45+
46+
add_subdirectory(model)

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.14

0 commit comments

Comments
 (0)