# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.20)
project(cuda_green_context LANGUAGES CXX CUDA)

find_package(CUDAToolkit REQUIRED)

set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

find_package(holoscan REQUIRED CONFIG
             PATHS "/opt/nvidia/holoscan" "/workspace/holoscan-sdk/install")

add_executable(cuda_green_context
  cuda_green_context.cpp
  test_kernel.cu
)

# Set CUDA architectures for the target
set_property(TARGET cuda_green_context PROPERTY CUDA_ARCHITECTURES "native")

target_link_libraries(cuda_green_context
  PRIVATE
  holoscan::core
  CUDA::cudart
)

# Testing
if(BUILD_TESTING)
  add_test(NAME EXAMPLE_CPP_CUDA_GREEN_CONTEXT_TEST
           COMMAND cuda_green_context
           WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
          )
  set_tests_properties(EXAMPLE_CPP_CUDA_GREEN_CONTEXT_TEST PROPERTIES
    ENVIRONMENT "HOLOSCAN_LOG_LEVEL=DEBUG"
    PASS_REGULAR_EXPRESSION
      "Rx message value: 25"
    SKIP_RETURN_CODE 77  # indicates Green Context is not supported
  )
endif()
