CMakeLists.txt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. set(NVCODEC_DIR ${CMAKE_SOURCE_DIR}/NvCodec)
  2. set(NVCODEC_UTIL_DIR ${NVCODEC_DIR}/Utils)
  3. set(NVENC_DIR ${NVCODEC_DIR}/NvCodec/NvEncoder)
  4. set(NVDEC_DIR ${NVCODEC_DIR}/NvCodec/NvDecoder)
  5. set(NVCODEC_INCLUDE_DIR
  6. ${NVCODEC_DIR}/include
  7. ${NVCODEC_DIR}/NvCodec
  8. ${NVCODEC_DIR}/Utils
  9. CACHE PATH
  10. "NVCODEC INCLUDE PATH"
  11. )
  12. file(GLOB sources
  13. ${NVCODEC_UTIL_DIR}/*
  14. ${NVENC_DIR}/*
  15. ${NVDEC_DIR}/*
  16. )
  17. add_library(NvCodec STATIC ${sources})
  18. # Delayload on linux
  19. if(Linux)
  20. add_subdirectory(implib)
  21. endif()
  22. target_include_directories(NvCodec
  23. PRIVATE
  24. ${CUDA_INCLUDE_DIRS}
  25. ${Vulkan_INCLUDE_DIR}
  26. ${GLEW_INCLUDE_DIRS}
  27. ${NVCODEC_INCLUDE_DIR}
  28. )
  29. if(Windows)
  30. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  31. set(CUVID_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/x64/nvcuvid.lib)
  32. set(NVENCODEAPI_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/x64/nvencodeapi.lib)
  33. else()
  34. set(CUVID_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/Win32/nvcuvid.lib)
  35. set(NVENCODEAPI_LIB ${CMAKE_CURRENT_SOURCE_DIR}/lib/Win32/nvencodeapi.lib)
  36. endif()
  37. else ()
  38. find_library(CUVID_LIB nvcuvid)
  39. find_library(NVENCODEAPI_LIB nvidia-encode)
  40. endif()
  41. if(Windows)
  42. # Select runtime library (MT, MTD) on windows platform
  43. set_target_properties(NvCodec
  44. PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
  45. )
  46. endif()
  47. if(Linux)
  48. # enable -fPIC option
  49. set_target_properties(NvCodec
  50. PROPERTIES
  51. POSITION_INDEPENDENT_CODE ON
  52. )
  53. endif()
  54. if(Windows)
  55. # Use delayload linker option for nvEncodeAPI64.dll and nvcuvid.dll
  56. set(NVCODEC_LIBRARIES
  57. NvCodec
  58. ${CUVID_LIB}
  59. ${NVENCODEAPI_LIB}
  60. CACHE PATH
  61. "NVCODEC LIBRARIES PATH"
  62. )
  63. elseif(Linux)
  64. # Use implib.so for delayload on Linux
  65. # If you don't use implib, need to link libnvcuvid.so and libnvidia-encode.so
  66. set(NVCODEC_LIBRARIES
  67. NvCodec
  68. CACHE PATH
  69. "NVCODEC LIBRARIES PATH"
  70. )
  71. endif()