# run this script by typing: source cori-bisicles-gnu-cmake
# After thus script completes, type: make -j 8
# If rebuilding, type 'make clean' before running 'make -j 8'

# This cmake configuration script builds cism_driver
# on cori using the gnu compiler suite.  It no longer relies on a build
# of Trilinos, but does need a BISICLES build located in BISICLES_INTERFACE_DIR
# (currently set to ./../../../BISICLES/CISM-interface/interface )


# This script should be run from the builds/cori-gnu subdirectory
# of the main seacism repository (reflected in the two instances
# of "../.." below).

# BUILD OPTIONS:
# The call to cmake below includes several input ON/OFF switch parameters, to
# provide a simple way to select different build options.  These are:
# CISM_BUILD_CISM_DRIVER -- ON by default, set to OFF to only build the CISM libraries.
# CISM_ENABLE_BISICLES -- OFF by default, set to ON to build a BISICLES-capable cism_driver.
# CISM_ENABLE_FELIX -- OFF by default, set to ON to build a FELIX-capable cism_driver.
# CISM_USE_TRILINOS -- OFF by default, set to on for builds with Trilinos.
# CISM_MPI_MODE -- ON by default, only set to OFF for serial builds.
# CISM_SERIAL_MODE -- OFF by default, set to ON for serial builds.
# CISM_USE_GPTL_INSTRUMENTATION -- ON by default, set to OFF to not use GPTL instrumentation.
# CISM_COUPLED -- OFF by default, set to ON to build with CESM.
echo
echo Run this script by typing: source cori-bisicles-gnu-cmake
echo

module unload cmake
module unload hdf5
module unload hdf5-parallel cray-hdf5-parallel
module unload netcdf cray-netcdf-hdf5parallel
module unload python
module unload cray-shmem
module unload cray-mpich2
module unload cray-mpich
module unload boost
module unload gcc
module unload PrgEnv-cray PrgEnv-gnu PrgEnv-intel PrgEnv-pathscale PrgEnv-pgi
module unload craype

module load modules/3.2.10.2
module load cmake/3.1.3
module load PrgEnv-gnu/5.2.40
module load gcc/4.9.2
module load cray-shmem/7.1.1
module load cray-mpich/7.1.1
module load cray-hdf5-parallel
module load cray-netcdf-hdf5parallel/4.3.2
module load cray-parallel-netcdf/1.5.0
module load python/2.7.9
module load boost/1.57

# (hopefully) temporary fix for PKG_CONFIG_PATH problem
#source PKG_CONFIG_PATH_fix.csh

# remove old build data:
rm -rf ./CMakeCache.txt
rm -rf ./CMakeFiles

# run a script that creates some CISM source files:
#pushd .
#cd ..
#../cmake-scripts/autogenerate-script
#popd

echo
echo "Doing CMake Configuration step"

cmake \
  -D CISM_BUILD_CISM_DRIVER:BOOL=ON \
  -D CISM_ENABLE_BISICLES=ON \
  -D CISM_ENABLE_FELIX=OFF \
\
  -D CISM_USE_TRILINOS:BOOL=OFF \
  -D CISM_MPI_MODE:BOOL=ON \
  -D CISM_SERIAL_MODE:BOOL=OFF \
\
  -D CISM_USE_GPTL_INSTRUMENTATION:BOOL=ON \
  -D CISM_COUPLED:BOOL=OFF \
\
  -D ALBANY_FELIX_DYCORE:BOOL=OFF \
\
  -D CISM_TRILINOS_DIR=/project/projectdirs/piscees/trilinos/trilinos-albany-build/install \
  -D CISM_TRILINOS_GPTL_DIR=/project/projectdirs/piscees/cism_gptl/Trilinos-11.12.1/cori-gnu-ci-nophal/install \
  -D CISM_TRILINOS_ALBANY_DIR=/project/projectdirs/piscees/trilinos/trilinos-albany-build/install \
\
  -D CISM_NETCDF_DIR=$NETCDF_DIR \
  -D CISM_HDF5_LIB_DIR=$HDF5_DIR \
  -D CISM_MPI_BASE_DIR=$MPICH_DIR \
\
  -D CISM_GPTL_DIR=/project/projectdirs/piscees/cism_gptl/libgptl/libgptl-cori-gnu \
\
  -D CMAKE_INSTALL_PREFIX:PATH=$PWD/install \
  -D CMAKE_VERBOSE_MAKEFILE:BOOL=ON \
  -D CMAKE_VERBOSE_CONFIGURE:BOOL=ON \
\
  -D CMAKE_CXX_COMPILER=CC \
  -D CMAKE_C_COMPILER=cc \
  -D CMAKE_Fortran_COMPILER=ftn \
\
\
  -D CMAKE_CXX_FLAGS:STRING="-O2" \
  -D CISM_Fortran_FLAGS:STRING="-O2 -DNO_RESCALE -ffree-line-length-none " \
  -D CISM_EXTRA_LIBS:STRING="-L$PETSC_DIR/lib -lpetsc -lHYPRE -lparmetis -lmetis  -lpthread -ldl" \
  -D BISICLES_LIB_SUBDIR=libgnu \
  -D BISICLES_INTERFACE_DIR=$PWD/../../../BISICLES/CISM-interface/interface \
  -D CISM_MPI_LIBS:STRING="mpichf90" \
  -D CISM_STATIC_LINKING:BOOL=ON \
  ../..


#  Explicit paths to libs after mid-March 2015 upgrade; NERSC help recommended replacing with
#  the generic env var names used above instead.
#
#  -D CISM_NETCDF_DIR=/opt/cray/netcdf-hdf5parallel/4.3.2/GNU/49 \
#  -D CISM_HDF5_LIB_DIR=/opt/cray/hdf5/1.8.13/GNU/49/lib \
#  -D CISM_MPI_BASE_DIR=/opt/cray/mpt/7.1.1/gni/mpich2-gnu/49 \  

