#.rst:
# FindVulkanSCDriverLibs
# -----------------
#
# Try to find VulkanSC driver lib and its dependencies.
#
# This module is intended to be used by projects that build VulkanSC
# samples.
# When VulkanSC loader is not found, VulkanSC applications has to link
# to VulkanSC driver directly.
#
# When using this find module to libs, the variable TARGET_LIB_PATH that
# defines the search paths must be defined in main CMakeLists.txt.
#
#    TARGET_LIB_PATH
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables::
#
#   VKSC_DEP_LIBS          - List including all the required libs path
#

# Add Vulkan SC dependencies on nvsci
list(APPEND DEP_LIBS "libnvscisync.so.1")
list(APPEND DEP_LIBS "libnvscibuf.so.1")

# Search for Vulkan SC loader library first
find_library(VULKANSC_LOADER NAMES libvulkansc.so libvulkansc.so.1 HINTS ${VULKANSC_LIB_PATH})

if (VULKANSC_LOADER)
    list(APPEND VKSC_DEP_LIBS ${VULKANSC_LOADER})
else()
    # If we didn't find Vulkan SC loader, then use Vulkan SC driver library directly.
    message(WARNING "Vulkan SC loader is not found, will directly link to Vulkan SC driver")
    set(DIRECT_DRIVER_LINK "ON")
    list(APPEND DEP_LIBS "libnvidia-vksc-core.so")
endif()

foreach (LIB ${DEP_LIBS})
    find_library(LIB_PATH NAMES ${LIB} HINTS ${TARGET_LIB_PATH} REQUIRED)
    list(APPEND VKSC_DEP_LIBS ${LIB_PATH})
    unset(LIB_PATH CACHE)
endforeach()

