# -----------------------------------------------------------------
# Programmer(s): Radu Serban @ LLNL
# -----------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2025, Lawrence Livermore National Security,
# University of Maryland Baltimore County, and the SUNDIALS contributors.
# Copyright (c) 2013-2025, Lawrence Livermore National Security
# and Southern Methodist University.
# Copyright (c) 2002-2013, Lawrence Livermore National Security.
# 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 ARKODE 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 4.1.2)

# Set cache variables for compilers and flags
set(CMAKE_C_COMPILER
  "/usr/bin/mpicc"
  CACHE FILEPATH "MPI C compiler")

set(CMAKE_C_FLAGS
  "-march=armv7-a -mfloat-abi=hard -mfpu=neon -O2 -pipe -fno-plt -fexceptions         -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security         -fstack-clash-protection"
  CACHE STRING "C compiler flags")

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

# Specify project name and language
project(ARKODE_C_parallel_examples C)

# Enable testing
include(CTest)

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

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

# Specify the path to SUNDIALS libraries
set(SUNDIALS_LIBRARY_DIR
  /usr/lib
  CACHE PATH "Location of SUNDIALS libraries")

find_library(SUNDIALS_CORE_LIB
  sundials_core ${SUNDIALS_LIBRARY_DIR}
  DOC "SUNDIALS core library")

find_library(SUNDIALS_SOLVER_LIB
  sundials_arkode ${SUNDIALS_LIBRARY_DIR}
  DOC "ARKODE library")
find_library(SUNDIALS_NVECPAR_LIB
  sundials_nvecparallel ${SUNDIALS_LIBRARY_DIR}
  DOC "NVECTOR_PARALLEL library")

find_library(SUNDIALS_NVECSER_LIB
  sundials_nvecserial ${SUNDIALS_LIBRARY_DIR}
  DOC "NVECTOR_SERIAL library")

find_library(SUNDIALS_MANYVEC_LIB
  sundials_nvecmpimanyvector ${SUNDIALS_LIBRARY_DIR}
  DOC "NVECTOR_MPIMANYVECTOR library")

find_library(SUNDIALS_MPIPLUSX_LIB
  sundials_nvecmpiplusx ${SUNDIALS_LIBRARY_DIR}
  DOC "NVECTOR_MPIPLUSX library")

# Set additional libraries
set(SUNDIALS_EXTRA_LIBS  -lm CACHE STRING "Additional libraries")

# For SUNDIALS module examples the solver library is not needed
if(NOT SUNDIALS_SOLVER_LIB)
  set(SUNDIALS_SOLVER_LIB "")
endif()

# List of SUNDIALS libraries
set(SUNDIALS_LIBRARIES
  -L${SUNDIALS_LIBRARY_DIR}
  ${SUNDIALS_SOLVER_LIB}
  ${SUNDIALS_NVECPAR_LIB}
  ${SUNDIALS_NVECSER_LIB}
  ${SUNDIALS_MANYVEC_LIB}
  ${SUNDIALS_MPIPLUSX_LIB}
  ${SUNDIALS_CORE_LIB}
  ${SUNDIALS_EXTRA_LIBS})

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

# Set the names of the examples to be built and their dependencies
set(examples  ark_diurnal_kry_p ark_diurnal_kry_bbd_p ark_brusselator1D_task_local_nls)
set(examples_dependencies )
if(examples)
  list(REMOVE_DUPLICATES examples)
endif()

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

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

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

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

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

endforeach()
