FindPipeWire.cmake 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #[=======================================================================[.rst
  2. FindPipeWire
  3. ------------
  4. FindModule for PipeWire and associated libraries
  5. .. versionchanged:: 3.0
  6. Updated FindModule to CMake standards
  7. Imported Targets
  8. ^^^^^^^^^^^^^^^^
  9. .. versionadded:: 2.0
  10. This module defines the :prop_tgt:`IMPORTED` target ``PipeWire::PipeWire``.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This module sets the following variables:
  14. ``PipeWire_FOUND``
  15. True, if all required components and the core library were found.
  16. ``PipeWire_VERSION``
  17. Detected version of found PipeWire libraries.
  18. Cache variables
  19. ^^^^^^^^^^^^^^^
  20. The following cache variables may also be set:
  21. ``PipeWire_LIBRARY``
  22. Path to the library component of PipeWire.
  23. ``PipeWire_INCLUDE_DIR``
  24. Directory containing ``PipeWire.h``.
  25. #]=======================================================================]
  26. include(FindPackageHandleStandardArgs)
  27. find_package(PkgConfig QUIET)
  28. if(PKG_CONFIG_FOUND)
  29. pkg_search_module(PC_PipeWire libpipewire-0.3 QUIET)
  30. pkg_search_module(PC_Libspa libspa-0.2 QUIET)
  31. endif()
  32. find_path(
  33. PipeWire_INCLUDE_DIR
  34. NAMES pipewire/pipewire.h
  35. HINTS ${PC_PipeWire_INCLUDE_DIRS}
  36. PATH_SUFFIXES pipewire-0.3
  37. PATHS /usr/include /usr/local/include
  38. DOC "PipeWire include directory"
  39. )
  40. find_path(
  41. Libspa_INCLUDE_DIR
  42. NAMES spa/param/props.h
  43. HINTS ${PC_Libspa_INCLUDE_DIRS}
  44. PATH_SUFFIXES spa-0.2
  45. PATHS /usr/include /usr/local/include
  46. DOC "Libspa include directory"
  47. )
  48. find_library(
  49. PipeWire_LIBRARY
  50. NAMES pipewire-0.3
  51. HINTS ${PC_PipeWire_LIBRARY_DIRS}
  52. PATHS /usr/lib /usr/local/lib
  53. DOC "PipeWire location"
  54. )
  55. if(PC_PipeWire_VERSION VERSION_GREATER 0)
  56. set(PipeWire_VERSION ${PC_PipeWire_VERSION})
  57. elseif(EXISTS "${PipeWire_INCLUDE_DIR}/pipewire/version.h")
  58. file(
  59. STRINGS
  60. "${PipeWire_INCLUDE_DIR}/pipewire/version.h"
  61. _version_string
  62. REGEX "^.*PW_(MAJOR|MINOR|MICRO)[ \t]+[0-9]+[ \t]*$"
  63. )
  64. string(REGEX REPLACE ".*PW_MAJOR[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}")
  65. string(REGEX REPLACE ".*PW_MINOR[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}")
  66. string(REGEX REPLACE ".*PW_MICRO[ \t]+([0-9]+).*" "\\1" _version_micro "${_version_string}")
  67. set(PipeWire_VERSION "${_version_major}.${_version_minor}.${_version_micro}")
  68. unset(_version_major)
  69. unset(_version_minor)
  70. unset(_version_micro)
  71. else()
  72. if(NOT PipeWire_FIND_QUIETLY)
  73. message(AUTHOR_WARNING "Failed to find PipeWire version.")
  74. endif()
  75. set(PipeWire_VERSION 0.0.0)
  76. endif()
  77. find_package_handle_standard_args(
  78. PipeWire
  79. REQUIRED_VARS PipeWire_LIBRARY PipeWire_INCLUDE_DIR Libspa_INCLUDE_DIR
  80. VERSION_VAR PipeWire_VERSION
  81. REASON_FAILURE_MESSAGE "Ensure that PipeWire is installed on the system."
  82. )
  83. mark_as_advanced(PipeWire_LIBRARY PipeWire_INCLUDE_DIR)
  84. if(PipeWire_FOUND)
  85. if(NOT TARGET PipeWire::PipeWire)
  86. if(IS_ABSOLUTE "${PipeWire_LIBRARY}")
  87. add_library(PipeWire::PipeWire UNKNOWN IMPORTED)
  88. set_property(TARGET PipeWire::PipeWire PROPERTY IMPORTED_LOCATION "${PipeWire_LIBRARY}")
  89. else()
  90. add_library(PipeWire::PipeWire INTERFACE IMPORTED)
  91. set_property(TARGET PipeWire::PipeWire PROPERTY IMPORTED_LIBNAME "${PipeWire_LIBRARY}")
  92. endif()
  93. set_target_properties(
  94. PipeWire::PipeWire
  95. PROPERTIES
  96. INTERFACE_COMPILE_OPTIONS "${PC_PipeWire_CFLAGS_OTHER}"
  97. INTERFACE_INCLUDE_DIRECTORIES "${PipeWire_INCLUDE_DIR};${Libspa_INCLUDE_DIR}"
  98. VERSION ${PipeWire_VERSION}
  99. )
  100. endif()
  101. endif()
  102. include(FeatureSummary)
  103. set_package_properties(
  104. PipeWire
  105. PROPERTIES URL "https://www.pipewire.org" DESCRIPTION "PipeWire - multimedia processing"
  106. )