# -----------------------------------------------------------------
# Programmer(s): Daniel R. Reynolds @ SMU
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2021, Lawrence Livermore National Security
# and Southern Methodist University.
# All rights reserved.
#
# See the top-level LICENSE and NOTICE files for details.
#
# SPDX-License-Identifier: BSD-3-Clause
# SUNDIALS Copyright End
# -----------------------------------------------------------------
# CMakeLists.txt for CVODE C++ MPI hypre examples.
#
# This file is generated from a template using variables
# set at configuration time. It can be used as a template for
# other user CMakeLists configuration files.
# -----------------------------------------------------------------

# Set the minimum required cmake version
cmake_minimum_required(VERSION 3.5)

# Set cache variables for compilers and flags
set(CMAKE_CXX_COMPILER
  /usr/bin/mpicxx
  CACHE FILEPATH "MPI C++ compiler")

set(CMAKE_CXX_FLAGS
  "-g -O2 -ffile-prefix-map=/build/sundials-wHsbk6/sundials-5.8.0+dfsg=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX -DLAM_BUILDING"
  CACHE STRING "C++ compiler flags")

# Specify project name and language
project(CVODE_CXX_parhyp_examples CXX)

# Enable testing
include(CTest)

# ------------------------------------------------------------------------------

# Specify the path to SUNDIALS header files
set(SUNDIALS_INCLUDE_DIR
  /usr/include
  CACHE PATH "Location of SUNDIALS header files")

# Specify the path to SUNDIALS libraries
set(SUNDIALS_LIBRARY_DIR
  /usr/lib/x86_64-linux-gnu
  CACHE PATH "Location of SUNDIALS libraries")

# Find the SUNDIALS libraries
find_library(SUNDIALS_SOLVER_LIB
  sundials_cvode ${SUNDIALS_LIBRARY_DIR}
  DOC "CVODE library")

find_library(SUNDIALS_NVEC_LIB
  sundials_nvecparallel ${SUNDIALS_LIBRARY_DIR}
  DOC "NVECTOR_PARALLEL library")

find_library(SUNDIALS_NVECPH_LIB
  sundials_nvecparhyp ${SUNDIALS_LIBRARY_DIR}
  DOC "NVECTOR_PARHYP library")

# Set additional libraries
set(SUNDIALS_EXTRA_LIBS  -lm /usr/lib/x86_64-linux-gnu/librt.a CACHE STRING "Additional libraries")

# For SUNDIALS module examples the solver library is not needed
if(NOT SUNDIALS_SOLVER_LIB)
  set(SUNDIALS_SOLVER_LIB "")
endif()

# List of SUNDIALS libraries
set(SUNDIALS_LIBRARIES
  -L${SUNDIALS_LIBRARY_DIR}
  ${SUNDIALS_SOLVER_LIB}
  ${SUNDIALS_NVEC_LIB}
  ${SUNDIALS_NVECPH_LIB}
  ${SUNDIALS_EXTRA_LIBS})

# ------------------------------------------------------------------------------

# Set hypre include directory and libraries
set(HYPRE_INCLUDE_DIR
  /usr/include/hypre
  CACHE PATH "Location of hypre header files")

set(HYPRE_LIBRARIES
  -lHYPRE;
  CACHE STRING "HYPRE libraries")

# Set the names of the examples to be built and their dependencies
set(examples  cv_heat2D_hypre_ls cv_heat2D_hypre_pfmg)
set(examples_dependencies )
if(examples)
  list(REMOVE_DUPLICATES examples)
endif()

# Create targets for each example
foreach(example ${examples})

  # example source files
  add_executable(${example} ${example}.cpp ${examples_dependencies})

  # directories to include
  target_include_directories(${example} PRIVATE ${SUNDIALS_INCLUDE_DIR})
  target_include_directories(${example} PRIVATE ${HYPRE_INCLUDE_DIR})

  # libraries to link against
  target_link_libraries(${example} ${SUNDIALS_LIBRARIES})
  target_link_libraries(${example} ${HYPRE_LIBRARIES})

  # add the example to ctest
  add_test(NAME ${example} COMMAND ${example})

endforeach()
