# run this script by typing: source hopper-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 hopper using the PGI compiler suite.  It relies on a build of Trilinos
# located in /global/project/projectdirs/piscees, and a build of BISICLES
# located in the ranken home directory: /global/u1/r/ranken/BISICLES


# This script should be run from the builds/hopper-pgi subdirectory
# of the main seacism 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 hopper-pgi-cmake
echo
echo Warning: Python problem.  After the last hopper system updates 1/28/13, in order to run simple_glide
echo or simple_bisicles, you need to replace the python/2.7.3 module with the python/2.7.1 module.
echo The easiest way to do this: In your .cshrc.ext or .bashrc.ext add the lines:
echo module unload python 
echo module load python/2.7.1
echo

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

module --silent purge

module load modules/3.2.6.6
module load cmake/2.8.7
module load PrgEnv-pgi/4.1.40
module load hdf5-parallel/1.8.8
module load python/2.7.1
module load cray-shmem/5.5.2
module load cray-mpich2/5.5.2



# remove old build data:
rm ./CMakeCache.txt

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

echo
echo "Doing CMake Configuration step"


cmake \
  -D NO_TRILINOS:BOOL=OFF \
  -D CISM_COUPLED:BOOL=OFF \
  -D CISM_MPI_MODE:BOOL=ON \
  -D CISM_SERIAL_MODE:BOOL=OFF \
  -D CISM_BUILD_SIMPLE_GLIDE:BOOL=ON \
  -D CISM_BUILD_SIMPLE_BISICLES:BOOL=OFF \
  -D CISM_BUILD_EXTRA_EXECUTABLES:BOOL=OFF \
  -D CISM_USE_GPTL_INSTRUMENTATION:BOOL=OFF \
  -D CISM_USE_CISM_FRONT_END:BOOL=OFF \
\
  -D GLIMMER_TRILINOS_DIR=/global/project/projectdirs/piscees/trilinos-default/hopper-pgi/install \
  -D GLIMMER_NETCDF_DIR=/opt/cray/netcdf/4.1.2/pgi/109 \
  -D GLIMMER_FMAIN=/opt/pgi/12.4.0/linux86-64/12.4/lib/f90main.o \
\
  -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 CISM_MPI_BASE_DIR=/opt/cray/mpt/5.4.5/xt/gemini/mpich2-pgi/109 \
  -D CISM_SCI_LIB_DIR=/opt/xt-libsci/11.0.06/pgi/109/mc12/lib \
  -D GLIMMER_GPTL_DIR=/project/projectdirs/ccsm1/libgptl/libgptl-pgi \
\
  -D CMAKE_CXX_FLAGS:STRING="-O2 --diag_suppress 554,111,611" \
  -D BISICLES_INTERFACE_DIR=/global/u1/r/ranken/BISICLES/code/interface \
  -D GLIMMER_MPI_LIBS:STRING="mpichf90" \
  ../..

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