FindGStreamer.cmake 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # - Try to find GStreamer and its plugins
  2. # Once done, this will define
  3. #
  4. # GSTREAMER_FOUND - system has GStreamer
  5. # GSTREAMER_INCLUDE_DIRS - the GStreamer include directories
  6. # GSTREAMER_LIBRARIES - link these to use GStreamer
  7. #
  8. # Additionally, gstreamer-base is always looked for and required, and
  9. # the following related variables are defined:
  10. #
  11. # GSTREAMER_BASE_INCLUDE_DIRS - gstreamer-base's include directory
  12. # GSTREAMER_BASE_LIBRARIES - link to these to use gstreamer-base
  13. #
  14. # Optionally, the COMPONENTS keyword can be passed to find_package()
  15. # and GStreamer plugins can be looked for. Currently, the following
  16. # plugins can be searched, and they define the following variables if
  17. # found:
  18. #
  19. # gstreamer-app: GSTREAMER_APP_INCLUDE_DIRS and GSTREAMER_APP_LIBRARIES
  20. # gstreamer-audio: GSTREAMER_AUDIO_INCLUDE_DIRS and GSTREAMER_AUDIO_LIBRARIES
  21. # gstreamer-fft: GSTREAMER_FFT_INCLUDE_DIRS and GSTREAMER_FFT_LIBRARIES
  22. # gstreamer-pbutils: GSTREAMER_PBUTILS_INCLUDE_DIRS and GSTREAMER_PBUTILS_LIBRARIES
  23. # gstreamer-video: GSTREAMER_VIDEO_INCLUDE_DIRS and GSTREAMER_VIDEO_LIBRARIES
  24. #
  25. # Copyright (C) 2012 Raphael Kubo da Costa <rakuco@webkit.org>
  26. #
  27. # Redistribution and use in source and binary forms, with or without
  28. # modification, are permitted provided that the following conditions
  29. # are met:
  30. # 1. Redistributions of source code must retain the above copyright
  31. # notice, this list of conditions and the following disclaimer.
  32. # 2. Redistributions in binary form must reproduce the above copyright
  33. # notice, this list of conditions and the following disclaimer in the
  34. # documentation and/or other materials provided with the distribution.
  35. #
  36. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
  37. # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38. # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
  40. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  41. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  42. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  43. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  44. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  45. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  46. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. find_package(PkgConfig)
  48. # Helper macro to find a GStreamer plugin (or GStreamer itself)
  49. # _component_prefix is prepended to the _INCLUDE_DIRS and _LIBRARIES variables (eg. "GSTREAMER_AUDIO")
  50. # _pkgconfig_name is the component's pkg-config name (eg. "gstreamer-1.0", or "gstreamer-video-1.0").
  51. # _header is the component's header, relative to the gstreamer-1.0 directory (eg. "gst/gst.h").
  52. # _library is the component's library name (eg. "gstreamer-1.0" or "gstvideo-1.0")
  53. macro(FIND_GSTREAMER_COMPONENT _component_prefix _pkgconfig_name _header _library)
  54. # FIXME: The QUIET keyword can be used once we require CMake 2.8.2.
  55. pkg_check_modules(PC_${_component_prefix} ${_pkgconfig_name})
  56. find_path(${_component_prefix}_INCLUDE_DIRS
  57. NAMES ${_header}
  58. HINTS ${PC_${_component_prefix}_INCLUDE_DIRS} ${PC_${_component_prefix}_INCLUDEDIR}
  59. PATH_SUFFIXES gstreamer-1.0
  60. )
  61. find_library(${_component_prefix}_LIBRARIES
  62. NAMES ${_library}
  63. HINTS ${PC_${_component_prefix}_LIBRARY_DIRS} ${PC_${_component_prefix}_LIBDIR}
  64. )
  65. endmacro()
  66. # ------------------------
  67. # 1. Find GStreamer itself
  68. # ------------------------
  69. # 1.1. Find headers and libraries
  70. FIND_GSTREAMER_COMPONENT(GSTREAMER gstreamer-1.0 gst/gst.h gstreamer-1.0)
  71. FIND_GSTREAMER_COMPONENT(GSTREAMER_BASE gstreamer-base-1.0 gst/gst.h gstbase-1.0)
  72. # 1.2. Check GStreamer version
  73. if (GSTREAMER_INCLUDE_DIRS)
  74. if (EXISTS "${GSTREAMER_INCLUDE_DIRS}/gst/gstversion.h")
  75. file(READ "${GSTREAMER_INCLUDE_DIRS}/gst/gstversion.h" GSTREAMER_VERSION_CONTENTS)
  76. string(REGEX MATCH "#define +GST_VERSION_MAJOR +\\(([0-9]+)\\)" _dummy "${GSTREAMER_VERSION_CONTENTS}")
  77. set(GSTREAMER_VERSION_MAJOR "${CMAKE_MATCH_1}")
  78. string(REGEX MATCH "#define +GST_VERSION_MINOR +\\(([0-9]+)\\)" _dummy "${GSTREAMER_VERSION_CONTENTS}")
  79. set(GSTREAMER_VERSION_MINOR "${CMAKE_MATCH_1}")
  80. string(REGEX MATCH "#define +GST_VERSION_MICRO +\\(([0-9]+)\\)" _dummy "${GSTREAMER_VERSION_CONTENTS}")
  81. set(GSTREAMER_VERSION_MICRO "${CMAKE_MATCH_1}")
  82. set(GSTREAMER_VERSION "${GSTREAMER_VERSION_MAJOR}.${GSTREAMER_VERSION_MINOR}.${GSTREAMER_VERSION_MICRO}")
  83. endif ()
  84. endif ()
  85. # FIXME: With CMake 2.8.3 we can just pass GSTREAMER_VERSION to FIND_PACKAGE_HANDLE_STANDARD_ARGS as VERSION_VAR
  86. # and remove the version check here (GSTREAMER_FIND_VERSION would be passed to FIND_PACKAGE).
  87. set(VERSION_OK TRUE)
  88. if (GSTREAMER_FIND_VERSION_EXACT)
  89. if (NOT(("${GSTREAMER_FIND_VERSION}" VERSION_EQUAL "${GSTREAMER_VERSION}")))
  90. set(VERSION_OK FALSE)
  91. endif ()
  92. else ()
  93. if ("${GSTREAMER_VERSION}" VERSION_LESS "${GSTREAMER_FIND_VERSION}")
  94. set(VERSION_OK FALSE)
  95. endif ()
  96. endif ()
  97. # -------------------------
  98. # 2. Find GStreamer plugins
  99. # -------------------------
  100. FIND_GSTREAMER_COMPONENT(GSTREAMER_APP gstreamer-app-1.0 gst/app/gstappsink.h gstapp-1.0)
  101. FIND_GSTREAMER_COMPONENT(GSTREAMER_AUDIO gstreamer-audio-1.0 gst/audio/audio.h gstaudio-1.0)
  102. FIND_GSTREAMER_COMPONENT(GSTREAMER_FFT gstreamer-fft-1.0 gst/fft/gstfft.h gstfft-1.0)
  103. FIND_GSTREAMER_COMPONENT(GSTREAMER_PBUTILS gstreamer-pbutils-1.0 gst/pbutils/pbutils.h gstpbutils-1.0)
  104. FIND_GSTREAMER_COMPONENT(GSTREAMER_VIDEO gstreamer-video-1.0 gst/video/video.h gstvideo-1.0)
  105. # ------------------------------------------------
  106. # 3. Process the COMPONENTS passed to FIND_PACKAGE
  107. # ------------------------------------------------
  108. set(_GSTREAMER_REQUIRED_VARS GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES VERSION_OK GSTREAMER_BASE_INCLUDE_DIRS GSTREAMER_BASE_LIBRARIES)
  109. foreach (_component ${GStreamer_FIND_COMPONENTS})
  110. set(_gst_component "GSTREAMER_${_component}")
  111. string(TOUPPER ${_gst_component} _UPPER_NAME)
  112. list(APPEND _GSTREAMER_REQUIRED_VARS ${_UPPER_NAME}_INCLUDE_DIRS ${_UPPER_NAME}_LIBRARIES)
  113. endforeach ()
  114. include(FindPackageHandleStandardArgs)
  115. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GStreamer DEFAULT_MSG ${_GSTREAMER_REQUIRED_VARS})