# Run this script by typing: source yellowstone-intel-cmake
# After this script completes, type: make -j 8
# If rebuilding, type 'make clean' before running 'make -j 8'

# This cmake configuration script is set up to perform a serial build

module purge
module load ncarenv/1.0
module load ncarbinlibs/1.0
module load intel/13.1.2
module load mkl/11.0.1
module load netcdf/4.3.0
module load ncarcompilers/1.0
module load cmake/2.8.10.2
module load python
module load all-python-libs

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

echo
echo "Doing CMake Configuration step"

# Note: the compilation flags were taken from the defaults for a CESM build on
# yellowstone-intel (using Machines_140218). Some of these options (e.g.,
# -convert big_endian and -assume byterecl) are probably unnecessary for a
# standalone build, but I am keeping things consistent with the CESM build for
# simplicity.

# A few non-intuitive things:
#
# - CISM_FORCE_FORTRAN_LINKER: without this, cmake tries to use a C++ linker, which doesn't work
#
# - CISM_INCLUDE_IMPLICIT_LINK_LIBRARIES: (this is a note that applies to the
#   parallel build with trilinos, and may or may not apply to this serial
#   build): if this is on (the default), some libraries are included on the link
#   line which can't be found (e.g., hdf5). This may be related to the fact that
#   trilinos on yellowstone is old, and/or the fact that cmake wants to use a
#   C++ linker but we're telling it to use a fortran linker.

cmake \
  -D CISM_USE_TRILINOS:BOOL=OFF \
  -D CISM_COUPLED:BOOL=OFF \
  -D CISM_MPI_MODE:BOOL=OFF \
  -D CISM_SERIAL_MODE: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_USE_GPTL_INSTRUMENTATION:BOOL=OFF \
  -D CISM_USE_DEFAULT_IO:BOOL=OFF \
  -D CISM_USE_CISM_FRONT_END:BOOL=OFF \
\
  -D CISM_NETCDF_DIR=$NETCDF \
  -D CISM_FORCE_FORTRAN_LINKER:BOOL=ON \
  -D CISM_INCLUDE_IMPLICIT_LINK_LIBRARIES:BOOL=OFF \
  -D CMAKE_VERBOSE_MAKEFILE:BOOL=OFF \
\
  -D CMAKE_CXX_COMPILER=icpc \
  -D CMAKE_C_COMPILER=icc \
  -D CMAKE_Fortran_COMPILER=ifort \
\
  -D CMAKE_Fortran_FLAGS:STRING="-fp-model source -convert big_endian -assume byterecl -ftz -traceback -assume realloc_lhs -xHost -O2" \
  -D CMAKE_C_FLAGS:STRING="-O2 -fp-model precise -xHost" \
  -D CMAKE_CXX_FLAGS:STRING="-O2 -fp-model precise -xHost" \
 ../..

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