This page describes how to build ICON with alongside HDF5 and NetCDF. The description shows each step separately. This is useful to understand how HPCW works with multiple dependencies, however in practice, it would be sufficient to just execute the final shell portion of this document (building ICON). The required dependencies would then be built alongside ICON. To follow best practice, use the build wrapper instead.
Setup
We first define some variables and helpers functions.
HPCW_SOURCE_DIR
: source directory of HPCW
BUILD
: build directory where to build HPCW
add_package $dir
: function setting variables to use a package installed in directory $dir
.
export HPCW_SOURCE_DIR=$PWD
export BUILD=$HPCW_SOURCE_DIR/build
add_package() {
export PATH=$1/bin:$PATH
export CPATH=$1/include${CPATH+:$CPATH}
export LIBRARY_PATH=$1/lib:${LIBRARY_PATH+:$LIBRARY_PATH}
export LD_LIBRARY_PATH=$1/lib:${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
# https://unix.stackexchange.com/a/14896
PATH=$(printf "%s" "$PATH" | awk -v RS=':' '!a[$1]++ { if (NR > 1) printf RS; printf $1 }')
CPATH=$(printf "%s" "$CPATH" | awk -v RS=':' '!a[$1]++ { if (NR > 1) printf RS; printf $1 }')
LIBRARY_PATH=$(printf "%s" "$LIBRARY_PATH" | awk -v RS=':' '!a[$1]++ { if (NR > 1) printf RS; printf $1 }')
LD_LIBRARY_PATH=$(printf "%s" "$LD_LIBRARY_PATH" | awk -v RS=':' '!a[$1]++ { if (NR > 1) printf RS; printf $1 }')
}
We then describe how to use or compile some dependencies for ICON.
HDF5
export HDF5_ROOT=$BUILD/hdf5
export HDF5_DEPS=$PWD/install/hdf5Deps
export SZIP_ROOT_DIR=$HDF5_DEPS
export ZLIB_ROOT=$HDF5_DEPS
cmakeFlags+=" -Dhdf5_INSTALL_DIR=$HDF5_ROOT"
cmakeFlags+=" -Dszip_INSTALL_DIR=$HDF5_DEPS"
cmakeFlags+=" -Dzlib_INSTALL_DIR=$HDF5_DEPS"
mkdir -p $BUILD/hdf5
cd $BUILD/hdf5
cmake $cmakeFlags -DENABLE_hdf5=ON $HPCW_SOURCE_DIR
make
cmakeFlags+=" -DSZIP_ROOT_DIR=$SZIP_ROOT_DIR"
cmakeFlags+=" -DZLIB_ROOT=$ZLIB_ROOT"
To use the compiled HDF5 for any following builds, execute:
add_package $HDF5_ROOT
cmakeFlags+=" -DUSE_SYSTEM_hdf5=ON"
cmakeFlags+=" -DUSE_SYSTEM_szip=ON"
cmakeFlags+=" -DUSE_SYSTEM_zlib=ON"
NetCDF
export NETCDF_ROOT=$BUILD/netcdf
cmakeFlags+=" -Dnetcdf-c_INSTALL_DIR=$NETCDF_ROOT"
cmakeFlags+=" -Dnetcdf-fortran_INSTALL_DIR=$NETCDF_ROOT"
mkdir -p $BUILD/netcdf
cd $BUILD/netcdf
cmake $cmakeFlags -DENABLE_netcdf=ON $HPCW_SOURCE_DIR
make
To use the compiled NetCDF (C and Fortran), execute:
add_package $NETCDF_ROOT
cmakeFlags+=" -DUSE_SYSTEM_netcdf=ON"
cmakeFlags+=" -DNETCDF_DIR=$NETCDF_ROOT"
ICON
mkdir -p $BUILD/icon
cd $BUILD/icon
cmake $cmakeFlags -DENABLE_icon=ON $HPCW_SOURCE_DIR
make
Using the build wrapper instead
Building ICON with external dependencies can be immensely simplified by using the build wrapper, as it takes care of all the steps outlined above (the same is true for all other projects). You are only required to provide an environment and a toolchain file, setting the appropriate options via these files. The toolchains
directory contains many examples, i.e. the environment and toolchain files used on Levante to build ICON with all dependencies provided by the system.