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

# This cmake configuration script builds simple_glide and simple_bisicles
# on titan using the PGI compiler suite.

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

# BUILD OPTIONS:
# The call to cmake below include several input ON/OFF switch parameters, to
# provide a simple way to select different build options.  These are:
# NO_TRILINOS -- OFF by default, set to on for builds without 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_BUILD_SIMPLE_GLIDE -- ON by default, set to OFF to not build simple_glide
# CISM_BUILD_SIMPLE_BISICLES -- OFF by default, set to ON to build simple_bisicles
#      Setting NO_TRILINOS to ON will generate a much smaller executable for this build.
# CISM_BUILD_EXTRA_EXECUTABLES -- OFF by default, set to ON to build eis_glide and others
# CISM_USE_GPTL_INSTRUMENTATION -- OFF by default, set to ON to use GPTL instrumentation

# NOTE: There is currently an incompatibility between simple_bisicles and GPTL.  If
# the CISM_BUILD_SIMPLE_BISICLES is ON, the GPTL instrumentation is turned OFF.

# help user get the correct modules loaded:


# module unload modules

echo
echo Run this script by typing: source titan-pgi-cmake
echo

module unload cmake
module unload 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 boost pgi
module unload PrgEnv-cray PrgEnv-gnu PrgEnv-intel PrgEnv-pathscale PrgEnv-pgi

# Commented out on titan, because of project path that get cleared
# if you do this:
# module --silent purge

module load modules
module load cmake/2.8.10.2
module load PrgEnv-pgi/4.1.40
module load pgi/13.10.0
module load cray-shmem
module load cray-mpich
module load cray-hdf5-parallel/1.8.11
module load cray-netcdf-hdf5parallel/4.3.0
module load python
module load boost/1.53.0

# remove old build data:
rm ./CMakeCache.txt
rm -r ./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_USE_TRILINOS:BOOL=OFF \
  -D CISM_COUPLED:BOOL=OFF \
  -D CISM_MPI_MODE:BOOL=ON \
  -D CISM_SERIAL_MODE:BOOL=OFF \
  -D CISM_USE_GPTL_INSTRUMENTATION:BOOL=ON \
\
  -D CISM_BUILD_SIMPLE_GLIDE:BOOL=ON \
  -D CISM_BUILD_SIMPLE_BISICLES:BOOL=OFF \
  -D CISM_BUILD_GLINT_EXAMPLE:BOOL=OFF \
  -D CISM_BUILD_CISM_DRIVER:BOOL=ON \
\
  -D CISM_TRILINOS_DIR=/ccs/proj/cli062/Trilinos/cism-standard/default-pgi/install \
  -D CISM_TRILINOS_GPTL_DIR=/ccs/proj/cli062/cism_gptl/Trilinos/titan-pgi-ci-nophal/install \
  -D CISM_TRILINOS_ALBANY_DIR= \
\
  -D CISM_GPTL_DIR=/ccs/proj/cli062/cism_gptl/libgptl/libgptl-titan-pgi \
  -D CISM_NETCDF_DIR=/opt/cray/netcdf-hdf5parallel/4.3.0/pgi/121 \
\
  -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="-fast -Kieee --diag_suppress 554,111,611" \
  -D CISM_Fortran_FLAGS:STRING="-fast -Kieee" \
  -D BISICLES_LIB_SUBDIR=libpgi \
  -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 \
  ../..


#  -D GLIMMER_FMAIN=/opt/pgi/13.10.0/linux86-64/13.10/lib/f90main.o \

#  -D GLIMMER_TRILINOS_DIR=/tmp/proj/cli054/trilinos-10.12/FEB2013_FAST_PGI/install \

#  -D CMAKE_CXX_FLAGS:STRING="-O2 --diag_suppress 554,111,611 -DH5_USE_16_API" \
#  -D GLIMMER_Fortran_FLAGS:STRING="-O2" \


#  -D GLIMMER_FMAIN=/opt/pgi/13.7.0/linux86-64/13.7/lib/f90main.o \

# 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" \
