# This file drives compilation of all examples and is installed together with the example sources.
cmake_minimum_required(VERSION 3.30.0)

project(GridTools-examples LANGUAGES CXX)

include(ExternalProject)

enable_testing()

set(EXAMPLE_CUDA_ARCH "" CACHE STRING "CUDA compute capability to be used for this example.")

foreach(ex IN ITEMS stencil;stencil_type_erasure;boundaries)
    ExternalProject_Add(${ex}_example
        DOWNLOAD_COMMAND ""
        SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/${ex}
        CMAKE_ARGS
            -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
            -DCMAKE_CUDA_HOST_COMPILER=${CMAKE_CUDA_HOST_COMPILER}
            -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
            -DEXAMPLE_CUDA_ARCH=${EXAMPLE_CUDA_ARCH}
        INSTALL_COMMAND ""
        )
    ExternalProject_Get_property(${ex}_example BINARY_DIR)
    add_test(NAME ${ex}_example COMMAND ctest WORKING_DIRECTORY ${BINARY_DIR})
endforeach()
