# Copyright 2020-2025 NVIDIA Corporation.  All rights reserved.
#
# Please refer to the NVIDIA end user license agreement (EULA) associated
# with this source code for terms and conditions that govern your use of
# this software. Any use, reproduction, disclosure, or distribution of
# this software and related documentation outside the terms of the EULA
# is strictly prohibited.

# 3.7 is required for FindVulkan module support in CMake.
cmake_minimum_required(VERSION 3.7)

project(NvCodec)

if(CMAKE_VERSION VERSION_GREATER "3.27.0" OR CMAKE_VERSION VERSION_EQUAL "3.27.0")   
    set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/External/cmake/Modules)
    message("Setting CMAKE_MODULE_PATH to ${CMAKE_MODULE_PATH}")
endif()

# Find CUDA early to set up version variables for all subprojects
# Try modern CUDAToolkit first for CMake 3.17+, fallback to deprecated CUDA module
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17")
    find_package(CUDAToolkit QUIET)
    if(CUDAToolkit_FOUND)
        # Map CUDAToolkit variables to legacy CUDA variable names for compatibility
        set(CUDA_FOUND TRUE)
        set(CUDA_VERSION ${CUDAToolkit_VERSION})
        set(CUDA_VERSION_MAJOR ${CUDAToolkit_VERSION_MAJOR})
        set(CUDA_VERSION_MINOR ${CUDAToolkit_VERSION_MINOR})
    endif()
endif()
if(NOT CUDAToolkit_FOUND)
    find_package(CUDA QUIET)
endif()
if(CUDA_FOUND OR CUDAToolkit_FOUND)
    if(CUDA_VERSION VERSION_GREATER_EQUAL "13.0")
        set(NVCODEC_CUDA_VERSION_13_OR_GREATER TRUE CACHE BOOL "CUDA version is 13.0 or greater")
    else()
        set(NVCODEC_CUDA_VERSION_13_OR_GREATER FALSE CACHE BOOL "CUDA version is less than 13.0")
    endif()
    message("CUDA version: ${CUDA_VERSION}, NVCODEC_CUDA_VERSION_13_OR_GREATER: ${NVCODEC_CUDA_VERSION_13_OR_GREATER}")
endif()
if(CMAKE_CROSSCOMPILING)
    if(NOT CUDAToolkit_FOUND)
        message(FATAL_ERROR "Cross-compilation is supported only with CUDAToolkit")
    endif()
endif()

# Set C++11 for all projects and disable non-standard extensions
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_INSTALL_PREFIX .)

# Check for WSL 
if (EXISTS /usr/lib/wsl/lib)
    set(WSL_FLAG TRUE)
endif()

set(NVCODEC_PUBLIC_INTERFACE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../Interface)
set(NVCODEC_UTILS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Utils)
set(NV_CODEC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/NvCodec)
set(NV_ENC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/NvCodec/NvEncoder)
set(NV_DEC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/NvCodec/NvDecoder)
set(NV_APPENC_COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/AppEncode/Common)
set(NV_APPDEC_COMMON_DIR  ${CMAKE_CURRENT_SOURCE_DIR}/AppDecode/Common)

 if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(NVCODEC_SAMPLES_INSTALL_DIR ${CMAKE_BINARY_DIR})
else()
    set(NVCODEC_SAMPLES_INSTALL_DIR ${CMAKE_BINARY_DIR})
endif()

if(WIN32)
    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
        # Windows x64
        Set(CUVID_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../Lib/win/x64/nvcuvid.lib)
        set(NVENCODEAPI_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../Lib/win/x64/nvencodeapi.lib)
    else()
        Set(CUVID_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../Lib/win/Win32/nvcuvid.lib)
        set(NVENCODEAPI_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../Lib/win/Win32/nvencodeapi.lib)
    endif()
else()
    if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
        set(CUVID_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../Lib/linux/stubs/aarch64/libnvcuvid.so)
        set(NVENCODEAPI_LIB ${CMAKE_CURRENT_SOURCE_DIR}/../Lib/linux/stubs/aarch64/libnvidia-encode.so)
    else()
        find_library(CUVID_LIB nvcuvid)
        find_library(NVENCODEAPI_LIB nvidia-encode)
    endif()
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    message(" ")
    message("======================================================================================================================================= ")  
    message(" Checking for ffmpeg packages: ")
    message("======================================================================================================================================= ") 

    find_package(PkgConfig REQUIRED)
    pkg_check_modules(PC_AVCODEC IMPORTED_TARGET libavcodec)
    if(PC_AVCODEC_FOUND)
        message("libavcodec found (version: ${PC_AVCODEC_VERSION})")
    else()
        message("libavcodec not found, continuing without it.")
    endif()

    pkg_check_modules(PC_AVFORMAT IMPORTED_TARGET libavformat)
    if(PC_AVFORMAT_FOUND)
        message("libavformat found (version: ${PC_AVFORMAT_VERSION})")
    else()
        message("libavformat not found, continuing without it.")
    endif()

    pkg_check_modules(PC_AVUTIL IMPORTED_TARGET libavutil)
    if(PC_AVUTIL_FOUND)
        message("libavutil found (version: ${PC_AVUTIL_VERSION})")
    else()
        message("libavutil not found, continuing without it.")
    endif()

    pkg_check_modules(PC_SWRESAMPLE IMPORTED_TARGET libswresample)
    if(PC_SWRESAMPLE_FOUND)
        message("libswresample found (version: ${PC_SWRESAMPLE_VERSION})")
    else()
        message("libswresample not found, continuing without it.")
    endif()

    set(NV_FFMPEG_HDRS ${PC_AVCODEC_INCLUDE_DIRS})
    find_library(AVCODEC_LIBRARY NAMES avcodec
            HINTS
            ${PC_AVCODEC_LIBDIR}
            ${PC_AVCODEC_LIBRARY_DIRS}
            )
    find_library(AVFORMAT_LIBRARY NAMES avformat
            HINTS
            ${PC_AVFORMAT_LIBDIR}
            ${PC_AVFORMAT_LIBRARY_DIRS}
            )
    find_library(AVUTIL_LIBRARY NAMES avutil
            HINTS
            ${PC_AVUTIL_LIBDIR}
            ${PC_AVUTIL_LIBRARY_DIRS}
            )
    find_library(SWRESAMPLE_LIBRARY NAMES swresample
            HINTS
            ${PC_SWRESAMPLE_LIBDIR}
            ${PC_SWRESAMPLE_LIBRARY_DIRS}
            )
    set(AVCODEC_LIB ${AVCODEC_LIBRARY})
    set(AVFORMAT_LIB ${AVFORMAT_LIBRARY})
    set(AVUTIL_LIB ${AVUTIL_LIBRARY})
    set(SWRESAMPLE_LIB ${SWRESAMPLE_LIBRARY})

    message("--------------------------------------------------------------------------------------------------------------------------------------- ")  
    message(" ")
    message("======================================================================================================================================= ")  
    message(" Checking for FREEGLUT_LIB, GLEW32_LIB, and X11_LIB: ")
    message("======================================================================================================================================= ") 
    message(" ")

    find_library(IsFreeglut_LIBRARY glut)
    if(IsFreeglut_LIBRARY)
        message(STATUS "freeglut library found")
    else()
        message(STATUS "freeglut library NOT found.")
    endif()

    find_library(IsGlew_LIBRARY GLEW)
    if(IsGlew_LIBRARY)
        message(STATUS "GLEW library found")
    else()
        message(STATUS "GLEW library NOT found.")
    endif()

    find_library(IsX11_LIBRARY X11)
    if(IsX11_LIBRARY)
        message(STATUS "X11 library found")
    else()
        message(STATUS "X11 library NOT found.")
    endif()

    find_library(IsGL_LIBRARY GL)
    if(IsGL_LIBRARY)
        message(STATUS "OpenGL (GL) library found")
    else()
        message(STATUS "OpenGL (GL) library NOT found.")
    endif()

    find_library(IsEGL_LIBRARY EGL)
    if(IsEGL_LIBRARY)
        message(STATUS "EGL library found")
    else()
        message(STATUS "EGL library NOT found.")
    endif()

    message("--------------------------------------------------------------------------------------------------------------------------------------- ")  
    message(" ")
endif()

if(DEFINED FFMPEG_DIR)
    Set(FFMPEG_DLL_DIR ${FFMPEG_DIR}/bin/)
    Set(FFMPEG_LIB_DIR ${FFMPEG_DIR}/lib/)
endif()

if(WIN32)
    message(" ")  
    message("======================================================================================================================================= ")  
    message(" APPS SPECIFIC TO WINDOWS: AppEncD3D11, AppEncD3D9, AppEncD3D12")
    message("======================================================================================================================================= ") 
    message(" ")  
    message("Building AppEncD3D11 ")  
    add_subdirectory(AppEncode/AppEncD3D11)
    message(" ")
    message("Building AppEncD3D9 ")
    add_subdirectory(AppEncode/AppEncD3D9)
    message(" ")
    message("---------------------------------------------- ")  
    message(" AGILITY SDK Dependent Apps: AppEncD3D12 ")
    message("---------------------------------------------- ") 
    if (NOT DEFINED AGILITY_SDK_BIN)
        message(WARNING "Agility SDK binary path not configured. Excluding AppEncD3D12")
        message(WARNING "Please get Agility SDK and set AGILITY_SDK_BIN cmake variable to point to the directory containing D3D12Core.dll for your platform")
    elseif(NOT DEFINED AGILITY_SDK_VER)
        message(WARNING "Agility SDK version not specified. Excluding AppEncD3D12")
        message(WARNING "Please set AGILITY_SDK_VER cmake variable to the Agility SDK version you are using")
    else()
        # Exclude if D3D12Core.dll is not found
        if (NOT EXISTS "${AGILITY_SDK_BIN}/D3D12Core.dll")
            message(WARNING "Couldnt find D3D12Core.dll at AGILITY_SDK_BIN (${AGILITY_SDK_BIN})")
            message(WARNING "Excluding AppEncD3D12")
        else()
            message("Building AppEncD3D12 ")
            add_subdirectory(AppEncode/AppEncD3D12)        
        endif()
    endif()  
    message("---------------------------------------------- ") 
    message(" ")
    message("--------------------------------------------------------------------------------------------------------------------------------------- ")  
endif()

if (NOT WSL_FLAG)
    message(" ")
    message("====================================================================================================================================== ")  
    message(" VULKAN Dependent Apps: AppMotionEstimationVkCuda")
    message("====================================================================================================================================== ") 
    #find_package(VULKAN)

    # AUTO_LOCATE_VULKAN - accepted value ON or OFF
    # ON  - Use CMake to auto locate the Vulkan SDK.
    # OFF - Vulkan SDK path can be specified manually. This is helpful to test the build on various Vulkan version.
    option(AUTO_LOCATE_VULKAN "AUTO_LOCATE_VULKAN" ON)

    if(AUTO_LOCATE_VULKAN)
        message(STATUS "Attempting auto locate Vulkan using CMake......")

        # Find Vulkan Path using CMake's Vulkan Module
        # This will return Boolean 'Vulkan_FOUND' indicating the status of find as success(ON) or fail(OFF).
        # Include directory path - 'Vulkan_INCLUDE_DIRS' and 'Vulkan_LIBRARY' with required libraries.
        find_package(Vulkan)

        # Try extracting VulkanSDK path from ${Vulkan_INCLUDE_DIRS}
        if (NOT ${Vulkan_INCLUDE_DIRS} STREQUAL "")
            set(VULKAN_PATH ${Vulkan_INCLUDE_DIRS})
            string(REGEX REPLACE "[/\\][iI]nclude" "" VULKAN_PATH "${VULKAN_PATH}")
        endif()
    endif()

    if(WIN32)
        set(VULKAN_HDR_DIR "${Vulkan_INCLUDE_DIRS}")
        if ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
            set(VULKAN_LIB_DIR ${VULKAN_PATH}/Lib32)
        else()
            set(VULKAN_LIB_DIR ${VULKAN_PATH}/Lib)
                endif()
    else ()
        find_package(PkgConfig REQUIRED)
        pkg_check_modules(PC_VULKAN IMPORTED_TARGET vulkan)
        set(VULKAN_HDR_DIR ${PC_VULKAN_INCLUDE_DIRS})
        find_library(VULKAN_LIBS vulkan)
    endif()

    if(Vulkan_FOUND)
        message("Vulkan package found ")
        add_subdirectory(AppEncode/AppMotionEstimationVkCuda)
    else()
        message("Vulkan package NOT found.")
    endif()

    message("-------------------------------------------------------------------------------------------------------------------------------------- ")  
    message(" ")
endif()

message(" ")
message("====================================================================================================================================== ")  
message(" APPS WITHOUT DEPENDENCIES:")
message("====================================================================================================================================== ")  
message("Building AppEncCuda ")
add_subdirectory(AppEncode/AppEncCuda)
message(" ")
message("Building AppEncLowLatency ")
add_subdirectory(AppEncode/AppEncLowLatency)
message(" ")
message("Building AppEncME ")
add_subdirectory(AppEncode/AppEncME)
message(" ")
message("Building AppEncPerf ")
add_subdirectory(AppEncode/AppEncPerf)
message(" ")
message("Building AppEncMultiInstance ")
add_subdirectory(AppEncode/AppEncMultiInstance)
message(" ")
message("Building AppEncQual ")
add_subdirectory(AppEncode/AppEncQual)
message("--------------------------------------------------------------------------------------------------------------------------------------- ")  

if(WIN32)
    # check if FFMpeg, GLUT and GLEW library cmake variables are set and 
    # add projects having above dependencies accordingly for Windows
    message(" ")
    message("======================================================================================================================================= ")  
    message(" FFMPEG Dependent Apps:")
    message("======================================================================================================================================= ") 
    if(DEFINED FFMPEG_DIR) 
        message("Building AppEncDec: ")
        add_subdirectory(AppEncode/AppEncDec)
        message(" ")
        message("Building AppTrans: ")
        add_subdirectory(AppTranscode/AppTrans)
        message(" ")
        message("Building AppTransOneToN: ")
        add_subdirectory(AppTranscode/AppTransOneToN)
        message(" ")
        message("Building AppTransPerf: ")
        add_subdirectory(AppTranscode/AppTransPerf)
        message(" ")
        message("Building AppDec: ")
        add_subdirectory(AppDecode/AppDec)
        message(" ")
        message("Building AppDecImageProvider: ")
        add_subdirectory(AppDecode/AppDecImageProvider)
        message(" ")
        message("Building AppDecLowLatency: ")
        add_subdirectory(AppDecode/AppDecLowLatency)
        message(" ")
        message("Building AppDecMem: ")
        add_subdirectory(AppDecode/AppDecMem)
        message(" ")
        message("Building AppDecMultiFiles: ")
        add_subdirectory(AppDecode/AppDecMultiFiles)
        message(" ")
        message("Building AppDecMultiInput: ")
        add_subdirectory(AppDecode/AppDecMultiInput)
        message(" ")
        message("Building AppDecPerf: ")
        add_subdirectory(AppDecode/AppDecPerf)
        message(" ")
        message("Building AppDecD3D: ")
        add_subdirectory(AppDecode/AppDecD3D)
	
    elseif((NOT DEFINED FFMPEG_DIR) AND (NOT DEFINED SKIP_FFMPEG_DEPENDENCY))
        message("FFMPEG_DIR not set")
        message("FFMPEG Libraries are needed to build the following apps :")
        message("AppDec, AppDec3D, AppDecGL, AppDecImageProvider, AppDecLowLatency, AppDecMem,")
        message("AppDecMultiFiles, AppDecMultiInput, AppDecPerf, AppEncDec, AppTrans,")
        message("AppTransOneToN, AppTransPerf")
        message("It is required to fetch the prebuilt LGPL FFMPEG libraries and to set the variable FFMPEG_DIR to point to this libraries")
        message("To skip building of apps having FFMPEG dependency, add -DSKIP_FFMPEG_DEPENDENCY=TRUE to commandline")
		message("See Windows Configuration Requirements section in Read_Me.pdf for detailed instructions")
    endif()
    message("--------------------------------------------------------------------------------------------------------------------------------------- ")  
    message(" ")
    
    if(NOT WSL_FLAG)
        message(" ")
        message("======================================================================================================================================= ")  
        message(" OpenGL Dependent Apps:")
        message("======================================================================================================================================= ") 
        if((DEFINED GLUT_DIR) AND (DEFINED GLUT_INC) AND (DEFINED GLEW_DIR))
            message("Building AppDecGL: ")
            add_subdirectory(AppDecode/AppDecGL)
        elseif((NOT DEFINED GLUT_DIR) AND (NOT DEFINED SKIP_GL_DEPENDENCY))
            message("GLUT_DIR not set")
            message("GLUT Libraries are needed to build the following apps : AppDecGL")
            message("It is required to build freeglut locally and to set following cmake variables :")
            message("GLUT_DIR: to point to the GLUT libraries")
            message("GLUT_INC: to point to the GLUT headers")            
            message("To skip building of apps having GLUT dependency, add -DSKIP_GL_DEPENDENCY=TRUE to commandline")
			message("See Windows Configuration Requirements section in Read_Me.pdf for detailed instructions")
        elseif((NOT DEFINED GLEW_DIR) AND (NOT DEFINED SKIP_GL_DEPENDENCY))
            message("GLEW_DIR not set")
            message("GLEW Libraries are needed to build the following apps : AppDecGL")
            message("It is required to fetch prebuilt GLEW libraries and to set variable GLEW_DIR to point to the GLEW libraries") 
            message("To skip building of apps having GLEW dependency, add -DSKIP_GL_DEPENDENCY=TRUE to commandline")
			message("See Windows Configuration Requirements section in Read_Me.pdf for detailed instructions")
        endif()
        message("--------------------------------------------------------------------------------------------------------------------------------------- ")  
        message(" ")
    endif()

else()
    if(NOT WSL_FLAG)
        message(" ")
        message("======================================================================================================================================= ")  
        message(" OpenGL Dependent Apps: AppEncGL(specific to Linux), AppDecGL ")
        message("======================================================================================================================================= ")
        if(PC_AVCODEC_FOUND AND PC_AVFORMAT_FOUND AND PC_AVUTIL_FOUND AND PC_SWRESAMPLE_FOUND AND IsFreeglut_LIBRARY AND
            IsGlew_LIBRARY AND IsX11_LIBRARY AND IsGL_LIBRARY AND IsEGL_LIBRARY)
                message("Building AppDecGL ")
                add_subdirectory(AppDecode/AppDecGL) 
                message("Building AppEncGL ")
                add_subdirectory(AppEncode/AppEncGL)        
        else()
                message("OpenGL libraries are needed to build the following apps: AppEncGL, AppDecGL ")
                message("Following packages are not found: freeglut, glew32, X11, GL, EGL")
                message("Use: sudo apt-get install MISSING_LIB command for the missing packages")
        endif ()
        message("---------------------------------------------------------------------------------------------------------------------------------------- ")  
    endif ()


    message(" ")
    message("======================================================================================================================================= ")  
    message(" FFMPEG Dependent Apps:")
    message("======================================================================================================================================= ") 
    if(PC_AVCODEC_FOUND AND PC_AVFORMAT_FOUND AND PC_AVUTIL_FOUND AND PC_SWRESAMPLE_FOUND)
        message("Building AppEncDec: ")
        add_subdirectory(AppEncode/AppEncDec)
        message(" ")
        message("Building AppTrans: ")
        add_subdirectory(AppTranscode/AppTrans)
        message(" ")
        message("Building AppTransOneToN: ")
        add_subdirectory(AppTranscode/AppTransOneToN)
        message(" ")
        message("Building AppTransPerf: ")
        add_subdirectory(AppTranscode/AppTransPerf)
        message(" ")
        message("Building AppDec: ")
        add_subdirectory(AppDecode/AppDec)
        message(" ")
        message("Building AppDecImageProvider: ")
        add_subdirectory(AppDecode/AppDecImageProvider)
        message(" ")
        message("Building AppDecLowLatency: ")
        add_subdirectory(AppDecode/AppDecLowLatency)
        message(" ")
        message("Building AppDecMem: ")
        add_subdirectory(AppDecode/AppDecMem)
        message(" ")
        message("Building AppDecMultiFiles: ")
        add_subdirectory(AppDecode/AppDecMultiFiles)
        message(" ")
        message("Building AppDecMultiInput: ")
        add_subdirectory(AppDecode/AppDecMultiInput)
        message(" ")
        message("Building AppDecPerf: ")
        add_subdirectory(AppDecode/AppDecPerf)
        message("---------------------------------------------------------------------------------------------------------------------------------------- ")  
        message(" ")
    else()
        message("FFMPEG Libraries are needed to build the following apps :")
        message("AppDec, AppDecGL, AppDecImageProvider, AppDecLowLatency, AppDecMem,")
        message("AppDecMultiFiles, AppDecMultiInput, AppDecPerf, AppEncDec, AppTrans,")
        message("AppTransOneToN, AppTransPerf, AppEncGL")
        message("Following packages are not found: libavcodec-dev, libavformat-dev, libavutil-dev, libswresample-dev")
        message("Use: sudo apt-get install MISSING_LIB command for the missing packages")
    endif()
endif()

if(DEFINED FFMPEG_DIR)
    file(GLOB externalLibList 
        ${FFMPEG_DLL_DIR}*.dll 
        ${FFMPEG_LIB_DIR}*.lib
    )    
    add_custom_target(copyFFMPEGFiles ALL)
    add_custom_command(TARGET copyFFMPEGFiles COMMAND ${CMAKE_COMMAND} -E make_directory  ${NVCODEC_SAMPLES_INSTALL_DIR}/$<CONFIG>/)

    foreach(externalLib ${externalLibList})
        add_custom_command(TARGET copyFFMPEGFiles COMMAND ${CMAKE_COMMAND} -E copy ${externalLib} ${NVCODEC_SAMPLES_INSTALL_DIR}/$<CONFIG>/)
    endforeach()
endif()

if(WIN32)
    # Summary of apps built, apps not built and reason for its failure.
 
    message("======================================================================================================================================= ")  
    message(" SUMMARY:")
    message("======================================================================================================================================= ")  
    message("APPS BUILT:")

    # Apps with no dependencies
    message("AppEncCuda, AppEncLowLatency, AppEncME, AppEncPerf, AppEncMultiInstance, ")
    message("AppEncD3D11, AppEncD3D9, AppEncQual,")
    if(DEFINED FFMPEG_DIR) 
        message("AppDec, AppDec3D, AppDecGL, AppDecImageProvider, AppDecLowLatency, AppDecMem, AppDecMultiFiles,")
        message("AppDecMultiInput, AppDecPerf, AppEncDec, AppTrans, AppTransOneToN, AppTransPerf")
    endif()

    # OpenGL dependent apps.
    if(NOT WSL_FLAG)
        if((DEFINED GLUT_DIR) AND (DEFINED GLUT_INC) AND (DEFINED GLEW_DIR))
             message("AppDecGL ")
        endif()
    endif()

    # Agility SDK
    if (DEFINED AGILITY_SDK_BIN OR  DEFINED AGILITY_SDK_VER OR (EXISTS "${AGILITY_SDK_BIN}/D3D12Core.dll"))
        message("AppEncD3D12 ")
    endif()	
    message("--------------------------------------------------------------------------------------------------------------------------------------- ")  

    # Apps not built if any of below is true
    if((NOT DEFINED FFMPEG_DIR) AND (NOT DEFINED SKIP_FFMPEG_DEPENDENCY) OR ((NOT DEFINED GLUT_DIR) AND (NOT DEFINED SKIP_GL_DEPENDENCY)) OR ((NOT DEFINED GLEW_DIR) AND (NOT DEFINED SKIP_GL_DEPENDENCY)) 
     OR ((NOT DEFINED AGILITY_SDK_BIN OR NOT DEFINED AGILITY_SDK_VER OR (NOT EXISTS "${AGILITY_SDK_BIN}/D3D12Core.dll"))))
        message("APPS NOT BUILT:")
    endif()

    if((NOT DEFINED FFMPEG_DIR) AND (NOT DEFINED SKIP_FFMPEG_DEPENDENCY))
        message("AppDec, AppDec3D, AppDecGL, AppDecImageProvider, AppDecLowLatency, AppDecMem, AppDecMultiFiles,")
        message("AppDecMultiInput, AppDecPerf, AppEncDec, AppTrans, AppTransOneToN, AppTransPerf")
        message("For more information, refer to the FFMPEG Dependent Apps section above. ")
        message(" ")
    endif()

    if(NOT WSL_FLAG)
        if((NOT DEFINED GLUT_DIR) AND (NOT DEFINED SKIP_GL_DEPENDENCY) OR ((NOT DEFINED GLEW_DIR) AND (NOT DEFINED SKIP_GL_DEPENDENCY)))
            message("AppDecGL ")
            message("For more information, refer to the OpenGL Dependent Apps section above. ")
            message(" ")
        endif()
    endif()

    if (NOT DEFINED AGILITY_SDK_BIN OR NOT DEFINED AGILITY_SDK_VER OR (NOT EXISTS "${AGILITY_SDK_BIN}/D3D12Core.dll"))
        message("AppEncD3D12 ")
        message("For more information, refer to the AGILITY SDK section above. ")
        message(" ")
    endif()

    message(" Note: Applications that depend on OpenGL will not be built unless both the FFmpeg and OpenGL libraries are present.")
    message("======================================================================================================================================= ")  
    message(" ")

else()
    message("======================================================================================================================================= ")  
    message(" SUMMARY:")
    message("======================================================================================================================================= ")  
    message("APPS BUILT:")
    message("AppEncCuda, AppEncLowLatency, AppEncME, AppEncPerf,")
    message("AppEncQual, AppEncMultiInstance")

    if(PC_AVCODEC_FOUND AND PC_AVFORMAT_FOUND AND PC_AVUTIL_FOUND AND PC_SWRESAMPLE_FOUND)
        message("AppDec, AppDecGL, AppDecImageProvider, AppDecLowLatency, AppDecMem, AppDecMultiFiles,")
        message("AppDecMultiInput, AppDecPerf, AppEncDec, AppTrans, AppTransOneToN, AppTransPerf, AppEncGL,") 
    endif()
    
    if(IsFreeglut_LIBRARY AND IsGlew_LIBRARY AND IsX11_LIBRARY AND IsGL_LIBRARY AND IsEGL_LIBRARY)
        message("AppDecGL, AppEncGL")
    endif()

    message("--------------------------------------------------------------------------------------------------------------------------------------- ") 

   if(NOT (PC_AVCODEC_FOUND AND PC_AVFORMAT_FOUND AND PC_AVUTIL_FOUND AND PC_SWRESAMPLE_FOUND AND 
     IsFreeglut_LIBRARY AND IsGlew_LIBRARY AND IsX11_LIBRARY AND IsGL_LIBRARY AND IsEGL_LIBRARY))
        message("APPS NOT BUILT:")
    endif()

    if(NOT (PC_AVCODEC_FOUND AND PC_AVFORMAT_FOUND AND PC_AVUTIL_FOUND AND PC_SWRESAMPLE_FOUND))
        message("AppDec, AppDecGL, AppDecImageProvider, AppDecLowLatency, AppDecMem, AppDecMultiFiles,")
        message("AppDecMultiInput, AppDecPerf, AppEncDec, AppTrans, AppTransOneToN, AppTransPerf, AppEncGL,") 
        message("For more information, refer to the FFMPEG Dependent Apps section above. ")
        message(" ")
    endif()
    
    if(NOT (IsFreeglut_LIBRARY AND IsGlew_LIBRARY AND IsX11_LIBRARY AND IsGL_LIBRARY AND IsEGL_LIBRARY))
        message("AppDecGL, AppEncGL")
        message("For more information, refer to the OpenGL Dependent Apps section above.")
        message(" ")
    endif()

    message(" Note: Applications that depend on OpenGL will not be built unless both the FFmpeg and OpenGL libraries are present.")
    message("======================================================================================================================================= ")  
    message(" ")
endif()
