# run this script by typing: source titan-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 titan using the GNU compiler suite.

# This script should be run from the builds/titan-gnu subdirectory
# of the main CISM 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 titan-gnu-cmake
echo

setenv CRAY_CPU_TARGET istanbul

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

module load modules
module load cmake/2.8.11.2
module load PrgEnv-gnu/5.2.40
module unload gcc
module load cray-shmem
module load cray-mpich
module load gcc/4.8.2
module load cray-hdf5-parallel/1.8.13
module load cray-netcdf-hdf5parallel/4.3.2
module load python
module load boost/1.57.0

echo module list

# 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=OFF \
  -D CISM_ENABLE_FELIX=OFF \
\
  -D CISM_USE_TRILINOS:BOOL=ON \
  -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 CISM_TRILINOS_DIR=/lustre/atlas/world-shared/cli900/cesm/software/Trilinos/Trilinos-11.12.1_gptl/titan-gnu-ci-nophal/install \
  -D CISM_TRILINOS_GPTL_DIR=/lustre/atlas/world-shared/cli900/cesm/software/Trilinos/Trilinos-11.12.1_gptl/titan-gnu-ci-nophal/install \
  -D CISM_TRILINOS_ALBANY_DIR=/lustre/atlas/world-shared/cli900/cesm/software/Trilinos/Trilinos-11.12.1_gptl/titan-gnu-ci-nophal/install \
\
  -D CISM_GPTL_DIR=/lustre/atlas/world-shared/cli900/cesm/software/libgptl/libgptl-titan-gnu \
  -D CISM_NETCDF_DIR=/opt/cray/netcdf-hdf5parallel/4.3.2/GNU/48 \
\
  -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 -fopenmp" \
  -D CISM_Fortran_FLAGS:STRING="-O2 -ffree-line-length-none -fno-range-check -fopenmp" \
  -D BISICLES_LIB_SUBDIR=libgnu \
  -D BISICLES_INTERFACE_DIR=$PWD/../../../BISICLES/CISM-interface/interface \
  -D CISM_MPI_LIBS:STRING="mpichf90" \
  -D CISM_USE_CXX_IMPLICIT_LIBS:BOOL=OFF \
  -D CISM_STATIC_LINKING:BOOL=ON \
  ../..


# Note: last argument above  "../.."  is path to top seacism directory

# ADD: 

#  -D CMAKE_PREFIX_PATH="/opt/cray/hdf5/1.8.8/pgi/119;/opt/cray/hdf5-parallel/1.8.8/pgi/119" \

#  -D TPL_ENABLE_MPI:BOOL=ON \


#  -D CISM_HDF5_LIB_DIR=/opt/cray/hdf5-parallel/1.8.8/pgi/119/lib \
#  -D CISM_HDF5_LIBS="-lhdf5_pgi_parallel -lz" \
