File size: 28,203 Bytes
ea55f45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# 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()