# SPDX-FileCopyrightText: Copyright (c) 2024-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.


####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was GXFConfig.cmake.in                            ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

macro(check_required_components _NAME)
  foreach(comp ${${_NAME}_FIND_COMPONENTS})
    if(NOT ${_NAME}_${comp}_FOUND)
      if(${_NAME}_FIND_REQUIRED_${comp})
        set(${_NAME}_FOUND FALSE)
      endif()
    endif()
  endforeach()
endmacro()

####################################################################################

include(CMakeFindDependencyMacro)

# core/std dependencies

find_dependency(Threads)
find_dependency(dlpack)
find_dependency(magic_enum)
find_dependency(yaml-cpp)

if(13 EQUAL 13)
    # Need CMake >= 3.31 for CUDA 13 support
    cmake_minimum_required(VERSION 3.31 FATAL_ERROR)
else()
    # Need CMake >= 3.25 for CUDA nvtx3 target
    cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
endif()
find_dependency(CUDAToolkit 13 COMPONENTS nvtx3 cudart)

# dependencies for other components

if(GXF_FIND_COMPONENTS AND ("ucx" IN_LIST GXF_FIND_COMPONENTS))
    # TODO: Multiple UCX "find"s will result in target redefinition.
    # We arbitrarily select the `ucx:ucs` target as a proxy workaround
    # to determine whether ucx has already been included.
    # https://github.com/openucx/ucx/issues/9614
    if(NOT TARGET ucx::ucs)
        find_dependency(ucx)
    endif()
endif()

set(_GXF_components app;core;logger;std;test_extension;cuda;multimedia;serialization;pubsub;sample;rmm;ucx;gxe)

include(${CMAKE_CURRENT_LIST_DIR}/GXFCoreTargets.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/GXFExtensionTargets.cmake)

foreach(component ${_GXF_components})
    set(GXF_${component}_FOUND TRUE)
endforeach()

foreach(component ${GXF_FIND_COMPONENTS})
    if(NOT GXF_${component}_FOUND)
        set(GXF_${component}_FOUND FALSE)
        if(NOT GXF_FIND_QUIETLY)
            message(WARNING "Missing required GXF component \"${component}\"")
        endif()
    endif()
endforeach()

set(GXF_ROOT ${CMAKE_CURRENT_LIST_DIR}/../../..)
cmake_path(NORMAL_PATH GXF_ROOT)
set_and_check(GXF_ROOT ${GXF_ROOT})
set_and_check(GXF_INCLUDE_DIR ${GXF_ROOT}/include)

check_required_components(GXF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
