FindFFnvcodec.cmake 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #[=======================================================================[.rst
  2. FindFFnvcodec
  3. -------------
  4. FindModule for FFnvcodec and the associated headers
  5. Imported Targets
  6. ^^^^^^^^^^^^^^^^
  7. .. versionadded:: 3.0
  8. This module defines the :prop_tgt:`IMPORTED` target ``FFnvcodec::FFnvcodec``.
  9. Result Variables
  10. ^^^^^^^^^^^^^^^^
  11. This module sets the following variables:
  12. ``FFnvcodec_FOUND``
  13. True, if headers was found.
  14. ``FFnvcodec_VERSION``
  15. Detected version of found FFnvcodec headers.
  16. Cache variables
  17. ^^^^^^^^^^^^^^^
  18. The following cache variables may also be set:
  19. ``FFnvcodec_INCLUDE_DIR``
  20. Directory containing ``nvEncodeAPI.h``.
  21. #]=======================================================================]
  22. # cmake-format: off
  23. # cmake-lint: disable=C0103
  24. # cmake-lint: disable=C0301
  25. # cmake-format: on
  26. include(FindPackageHandleStandardArgs)
  27. find_package(PkgConfig QUIET)
  28. if(PKG_CONFIG_FOUND)
  29. pkg_search_module(PC_FFnvcodec QUIET ffnvcodec)
  30. endif()
  31. find_path(
  32. FFnvcodec_INCLUDE_DIR
  33. NAMES ffnvcodec/nvEncodeAPI.h
  34. HINTS ${PC_FFnvcodec_INCLUDE_DIRS}
  35. PATHS /usr/include /usr/local/include
  36. DOC "FFnvcodec include directory")
  37. if(PC_FFnvcodec_VERSION VERSION_GREATER 0)
  38. set(FFnvcodec_VERSION ${PC_FFnvcodec_VERSION})
  39. elseif(EXISTS "${FFnvcodec_INCLUDE_DIR}/ffnvcodec/nvEncodeAPI.h")
  40. file(STRINGS "${FFnvcodec_INCLUDE_DIR}/ffnvcodec/nvEncodeAPI.h" _version_string
  41. REGEX "^.*NVENCAPI_(MAJOR|MINOR)_VERSION[ \t]+[0-9]+[ \t]*$")
  42. string(REGEX REPLACE ".*MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}")
  43. string(REGEX REPLACE ".*MINOR_VERSION[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}")
  44. set(FFnvcodec_VERSION "${_version_major}.${_version_minor}")
  45. unset(_version_major)
  46. unset(_version_minor)
  47. else()
  48. if(NOT FFnvcodec_FIND_QUIETLY)
  49. message(AUTHOR_WARNING "Failed to find FFnvcodec version.")
  50. endif()
  51. set(FFnvcodec_VERSION 0.0.0)
  52. endif()
  53. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  54. set(FFnvcodec_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
  55. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  56. set(FFnvcodec_ERROR_REASON "Ensure FFnvcodec headers are available in local include paths.")
  57. endif()
  58. find_package_handle_standard_args(
  59. FFnvcodec
  60. REQUIRED_VARS FFnvcodec_INCLUDE_DIR
  61. VERSION_VAR FFnvcodec_VERSION HANDLE_VERSION_RANGE REASON_FAILURE_MESSAGE "${FFnvcodec_ERROR_REASON}")
  62. mark_as_advanced(FFnvcodec_INCLUDE_DIR)
  63. unset(FFnvcodec_ERROR_REASON)
  64. if(FFnvcodec_FOUND)
  65. if(NOT TARGET FFnvcodec::FFnvcodec)
  66. add_library(FFnvcodec::FFnvcodec INTERFACE IMPORTED)
  67. set_target_properties(FFnvcodec::FFnvcodec PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFnvcodec_INCLUDE_DIR}")
  68. endif()
  69. endif()
  70. include(FeatureSummary)
  71. set_package_properties(
  72. FFnvcodec PROPERTIES
  73. URL "https://github.com/FFmpeg/nv-codec-headers/"
  74. DESCRIPTION "FFmpeg version of headers required to interface with NVIDIA's codec APIs.")