# -----------------------------------------------------------------
# Programmer(s): Cody J. Balos @ 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@ SuperLU_DIST 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_C_COMPILER
  @MPI_C_COMPILER@
  CACHE FILEPATH "MPI C compiler")

set(CMAKE_C_FLAGS
  "@CMAKE_C_FLAGS@"
  CACHE STRING "C compiler 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_superludist_examples C CXX)

# Enable testing
include(CTest)

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

# 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")

# Add SUNDIALS library directory to linker path
link_directories(${SUNDIALS_LIBRARY_DIR})

# List of SUNDIALS libraries to link to
set(SUNDIALS_LIBRARIES @SUNDIALS_LIBS@)

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

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

# Set the SuperLU_DIST include directories and libraries
set(SUPERLUDIST_INCLUDE_DIR
  @SUPERLUDIST_INCLUDE_DIR@
  CACHE STRING
  "Location of SuperLU_DIST header files")

set(SUPERLUDIST_LIBRARIES
  "@SUPERLUDIST_LIBRARIES@;@SUPERLUDIST_LIBRARY@"
  CACHE STRING
  "List of libraries needed for SuperLU_DIST")

# Set the names of the examples to be built and their dependencies
set(examples @EXAMPLES@)
set(examples_dependencies @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 ${SUPERLUDIST_INCLUDE_DIR})

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

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

endforeach()
