# -----------------------------------------------------------------
# Programmer(s): Radu Serban @ LLNL
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2019, 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  parallel examples
#
# This file is generated from a template using  various variables
# set at configuration time. It can be used as a template for
# other user CMakeLists configuration files.
# -----------------------------------------------------------------

cmake_minimum_required(VERSION 3.5)

# Specify project name
project(_parallel_examples C)

# Enable testing
include(CTest)

mark_as_advanced(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH)

# Set the names of the examples to be built
set(examples  test_sunlinsol_spgmr_parallel)

# Set names of examples specific dependency source files
set(examples_dependencies  test_sunlinsol sundials_nvector sundials_linearsolver)

# Set name of MPI compiler to be used (CC or MPICC)
set(MPI_MPICC /usr/bin/mpicc CACHE STRING "MPICC compiler script")
set(CMAKE_C_COMPILER ${MPI_MPICC})

# Specify path to SUNDIALS header files
set(SUNDIALS_INC_DIR
  /usr/include
  CACHE STRING
  "Location of SUNDIALS header files")

# Add path to SUNDIALS header files
include_directories(${SUNDIALS_INC_DIR})

# Set search path for SUNDIALS libraries
set(SUNDIALS_LIB_DIR /usr/lib)

# Find the SUNDIALS solver's library
find_library(SUNDIALS_SOLVER_LIB
  sundials_sunlinsolspgmr ${SUNDIALS_LIB_DIR}
  DOC " library")

# Find the NVECTOR library
find_library(SUNDIALS_NVECPAR_LIB
  sundials_nvecparallel ${SUNDIALS_LIB_DIR}
  DOC "NVECTOR parallel library")

find_library(SUNDIALS_NVECSER_LIB
  sundials_nvecserial ${SUNDIALS_LIB_DIR}
  DOC "NVECTOR serial library")

find_library(SUNDIALS_MANYVEC_LIB
  sundials_nvecmpimanyvector ${SUNDIALS_LIB_DIR}
  DOC "NVECTOR mpimanyvector library")

find_library(SUNDIALS_MPIPLUSX_LIB
  sundials_nvecmpiplusx ${SUNDIALS_LIB_DIR}
  DOC "NVECTOR mpiplusx library")

# Set additional libraries
set(SUNDIALS_EXTRA_LIB  -lm /usr/lib/librt.so CACHE STRING "Additional libraries")

# List of all libraries
set(SUNDIALS_LIBS ${SUNDIALS_SOLVER_LIB} ${SUNDIALS_NVECPAR_LIB} ${SUNDIALS_NVECSER_LIB}
                  ${SUNDIALS_MANYVEC_LIB} ${SUNDIALS_MPIPLUSX_LIB} ${SUNDIALS_EXTRA_LIB})

# Build each example one by one
foreach(example ${examples})

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

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

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

endforeach(example ${examples})
