# -----------------------------------------------------------------
# Programmer: David J. Gardner @ LLNL
# -----------------------------------------------------------------
# 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 @SOLVER@ + XBraid C++ MPI 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
  "@MPI_CXX_COMPILER@"
  CACHE FILEPATH "MPI C++ compiler")

set(CMAKE_CXX_FLAGS
  "@CMAKE_CXX_FLAGS@"
  CACHE STRING "C++ compiler flags")

# Specify project name and languages
project(@SOLVER@_CXX_xbraid_examples CXX)

# Enable testing
include(CTest)

# ------------------------------------------------------------------------------
# Find SUNDIALS libraries
# ------------------------------------------------------------------------------

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

# Specify the path to SUNDIALS libraries
set(SUNDIALS_LIBRARY_DIR
  "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@"
  CACHE PATH "Location of SUNDIALS libraries")

# Find the @SOLVER@ library
find_library(SUNDIALS_SOLVER_LIB
  @SOLVER_LIB@ ${SUNDIALS_LIBRARY_DIR}
  DOC "@SOLVER@ library")

# Find the parallel vector library
find_library(SUNDIALS_NVECPAR_LIB
  sundials_nvecparallel ${SUNDIALS_LIBRARY_DIR}
  DOC "NVECTOR_PARALLEL library")

# Find the @SOLVER@ + XBraid interface library
find_library(SUNDIALS_XBRAID_LIB
  @SOLVER_LIB@_xbraid ${SUNDIALS_LIBRARY_DIR}
  DOC "XBRAID Interface library")

# Set additional libraries
set(SUNDIALS_EXTRA_LIBS @LIBS@ CACHE STRING "Additional libraries")

# List of SUNDIALS libraries
set(SUNDIALS_LIBRARIES
  ${SUNDIALS_SOLVER_LIB}
  ${SUNDIALS_NVECPAR_LIB}
  ${SUNDIALS_XBRAID_LIB}
  ${SUNDIALS_EXTRA_LIBS})

# ------------------------------------------------------------------------------
# XBraid library variables
# ------------------------------------------------------------------------------

# Set hypre include directory and libraries
set(XBRAID_INCLUDE_DIR
  "@XBRAID_INCS@"
  CACHE PATH "Location of XBraid header files")

set(XBRAID_LIBRARIES
  "@XBRAID_LIBS@"
  CACHE STRING "XBraid libraries")

# ------------------------------------------------------------------------------
# @SOLVER@ + XBraid examples
# ------------------------------------------------------------------------------

# Set the names of the examples to build
set(examples @EXAMPLES@)

if(examples)
  list(REMOVE_DUPLICATES examples)
endif()

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

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

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

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

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

endforeach()

# ------------------------------------------------------------------------------
# @SOLVER@ + XBraid + hypre examples
# ------------------------------------------------------------------------------

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

set(HYPRE_LIBRARIES
  @HYPRE_LIBRARIES@
  CACHE STRING "HYPRE libraries")

# Set the names of the examples to build
set(examples_hypre @EXAMPLES_HYPRE@)

if(examples_hypre)
  list(REMOVE_DUPLICATES examples_hypre)
endif()

if(HYPRE_LIBRARIES AND examples_hypre)

  # Create target for each example
  foreach(example ${examples_hypre})

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

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

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

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

  endforeach()

endif()
