# -----------------------------------------------------------------
# Programmer(s): Cody J. Balos and David J. Gardner @ LLNL
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2024, 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
# -----------------------------------------------------------------

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

# Set cache variables for C compilers and flags
set(CMAKE_C_COMPILER
  "${CMAKE_CURRENT_LIST_DIR}/../../../../../bin/clang.exe"
  CACHE FILEPATH "C compiler")

set(CMAKE_C_FLAGS
  "-O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong"
  CACHE STRING "C compiler flags")

if("99")
  set(CMAKE_C_STANDARD "99"
    CACHE STRING "C standard")
endif()

# Set cache variables for C++ compilers and flags
set(CMAKE_CXX_COMPILER
  "${CMAKE_CURRENT_LIST_DIR}/../../../../../bin/clang++.exe"
  CACHE FILEPATH "CXX compiler")

set(CMAKE_CXX_FLAGS
  "-O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong"
  CACHE STRING "CXX compiler flags")

set(CMAKE_CXX_STANDARD
  "14"
  CACHE STRING "C++ standard")

# Specify project name and languages
project(ARKODE_examples C CXX)

# Enable testing
include(CTest)


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

# Specify the path to SUNDIALSConfig.cmake
set(SUNDIALS_DIR
  ${CMAKE_CURRENT_LIST_DIR}/../../../../../lib/cmake/sundials
  CACHE PATH "Location of SUNDIALSConfig.cmake")

# Find SUNDIALS
find_package(SUNDIALS
  COMPONENTS  nvecserial arkode cvode
  REQUIRED NO_DEFAULT_PATH)

# Set the SUNDIALS targets
set(SUNDIALS_TARGETS
   SUNDIALS::nvecserial SUNDIALS::arkode SUNDIALS::cvode)

# Set any additional libraries needed
set(EXTRA_LIBS
  
  CACHE STRING "Additional libraries")

# Additional includes
include_directories(. )

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

# Set the names of the examples to be built and their dependencies
set(examples  ark_analytic_sys.cpp ark_heat2D.cpp ark_kpr_Mt.cpp ark_pendulum.cpp ark_advection_diffusion_reaction.cpp)
set(examples_dependencies )
if(examples)
  list(REMOVE_DUPLICATES examples)
endif()

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

  # get filename without extension
  get_filename_component(example_target ${example} NAME_WE)

  # create target with example source files
  add_executable(${example_target} ${example} ${examples_dependencies})

  # libraries to link against
  target_link_libraries(${example_target} ${SUNDIALS_TARGETS} ${EXTRA_LIBS})

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

endforeach()
