# -----------------------------------------------------------------
# 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 KINSOL Fortran 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(FKINSOL_parallel_examples Fortran)

# Enable testing
include(CTest)

mark_as_advanced(EXECUTABLE_OUTPUT_PATH LIBRARY_OUTPUT_PATH)

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

# Set name of MPI compiler to be used (F77 or MPIF77)
set(MPI_MPIF77 /usr/bin/mpif90 CACHE STRING "MPIF77 compiler script")
set(CMAKE_Fortran_COMPILER ${MPI_MPIF77})

# 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_kinsol ${SUNDIALS_LIB_DIR}
  DOC "KINSOL library")

find_library(SUNDIALS_SOLVER_FLIB
  sundials_fkinsol ${SUNDIALS_LIB_DIR}
  DOC "KINSOL Fortran-C library")

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

find_library(SUNDIALS_NVEC_FLIB
  sundials_fnvecparallel ${SUNDIALS_LIB_DIR}
  DOC "NVECTOR Fortran-C 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_FLIB}
  ${SUNDIALS_SOLVER_LIB}
  ${SUNDIALS_NVEC_FLIB}
  ${SUNDIALS_NVEC_LIB}
  ${SUNDIALS_EXTRA_LIB})

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

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

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

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

endforeach(example ${examples})
