FindFFnvcodec.cmake 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. include(FindPackageHandleStandardArgs)
  23. find_package(PkgConfig QUIET)
  24. if(PKG_CONFIG_FOUND)
  25. pkg_search_module(PC_FFnvcodec QUIET ffnvcodec)
  26. endif()
  27. find_path(
  28. FFnvcodec_INCLUDE_DIR
  29. NAMES ffnvcodec/nvEncodeAPI.h
  30. HINTS ${PC_FFnvcodec_INCLUDE_DIRS}
  31. PATHS /usr/include /usr/local/include
  32. DOC "FFnvcodec include directory"
  33. )
  34. if(PC_FFnvcodec_VERSION VERSION_GREATER 0)
  35. set(FFnvcodec_VERSION ${PC_FFnvcodec_VERSION})
  36. elseif(EXISTS "${FFnvcodec_INCLUDE_DIR}/ffnvcodec/nvEncodeAPI.h")
  37. file(
  38. STRINGS
  39. "${FFnvcodec_INCLUDE_DIR}/ffnvcodec/nvEncodeAPI.h"
  40. _version_string
  41. REGEX "^.*NVENCAPI_(MAJOR|MINOR)_VERSION[ \t]+[0-9]+[ \t]*$"
  42. )
  43. string(REGEX REPLACE ".*MAJOR_VERSION[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}")
  44. string(REGEX REPLACE ".*MINOR_VERSION[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}")
  45. set(FFnvcodec_VERSION "${_version_major}.${_version_minor}")
  46. unset(_version_major)
  47. unset(_version_minor)
  48. else()
  49. if(NOT FFnvcodec_FIND_QUIETLY)
  50. message(AUTHOR_WARNING "Failed to find FFnvcodec version.")
  51. endif()
  52. set(FFnvcodec_VERSION 0.0.0)
  53. endif()
  54. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  55. set(FFnvcodec_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
  56. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  57. set(FFnvcodec_ERROR_REASON "Ensure FFnvcodec headers are available in local include paths.")
  58. endif()
  59. find_package_handle_standard_args(
  60. FFnvcodec
  61. REQUIRED_VARS FFnvcodec_INCLUDE_DIR
  62. VERSION_VAR FFnvcodec_VERSION
  63. HANDLE_VERSION_RANGE
  64. REASON_FAILURE_MESSAGE "${FFnvcodec_ERROR_REASON}"
  65. )
  66. mark_as_advanced(FFnvcodec_INCLUDE_DIR)
  67. unset(FFnvcodec_ERROR_REASON)
  68. if(FFnvcodec_FOUND)
  69. if(NOT TARGET FFnvcodec::FFnvcodec)
  70. add_library(FFnvcodec::FFnvcodec INTERFACE IMPORTED)
  71. set_target_properties(FFnvcodec::FFnvcodec PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FFnvcodec_INCLUDE_DIR}")
  72. endif()
  73. endif()
  74. include(FeatureSummary)
  75. set_package_properties(
  76. FFnvcodec
  77. PROPERTIES
  78. URL "https://github.com/FFmpeg/nv-codec-headers/"
  79. DESCRIPTION "FFmpeg version of headers required to interface with NVIDIA's codec APIs."
  80. )