1 # - Try to find Gstreamer and its plugins
2 # Once done, this will define
4 # GSTREAMER_1_0_FOUND - system has Gstreamer
5 # GSTREAMER_1_0_INCLUDE_DIRS - the Gstreamer include directories
6 # GSTREAMER_1_0_LIBRARIES - link these to use Gstreamer
8 # Additionally, gstreamer-base is always looked for and required, and
9 # the following related variables are defined:
11 # GSTREAMER_1_0_BASE_INCLUDE_DIRS - gstreamer-base's include directory
12 # GSTREAMER_1_0_BASE_LIBRARIES - link to these to use gstreamer-base
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
19 # gstreamer-app: GSTREAMER_1_0_APP_INCLUDE_DIRS and GSTREAMER_1_0_APP_LIBRARIES
20 # gstreamer-audio: GSTREAMER_1_0_AUDIO_INCLUDE_DIRS and GSTREAMER_1_0_AUDIO_LIBRARIES
21 # gstreamer-fft: GSTREAMER_1_0_FFT_INCLUDE_DIRS and GSTREAMER_1_0_FFT_LIBRARIES
22 # gstreamer-pbutils: GSTREAMER_1_0_PBUTILS_INCLUDE_DIRS and GSTREAMER_1_0_PBUTILS_LIBRARIES
23 # gstreamer-video: GSTREAMER_1_0_VIDEO_INCLUDE_DIRS and GSTREAMER_1_0_VIDEO_LIBRARIES
25 # Copyright (C) 2012 Raphael Kubo da Costa <rakuco@webkit.org>
27 # Redistribution and use in source and binary forms, with or without
28 # modification, are permitted provided that the following conditions
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.
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.
48 find_package(PkgConfig)
50 # The minimum Gstreamer version we support.
51 set(GSTREAMER_1_0_MINIMUM_VERSION 1.0.5)
53 # Helper macro to find a Gstreamer plugin (or Gstreamer itself)
54 # _component_prefix is prepended to the _INCLUDE_DIRS and _LIBRARIES variables (eg. "GSTREAMER_1_0_AUDIO")
55 # _pkgconfig_name is the component's pkg-config name (eg. "gstreamer-1.0", or "gstreamer-video-1.0").
56 # _library is the component's library name (eg. "gstreamer-1.0" or "gstvideo-1.0")
57 macro(FIND_GSTREAMER_COMPONENT _component_prefix _pkgconfig_name _library)
58 # FIXME: The QUIET keyword can be used once we require CMake 2.8.2.
60 string(REGEX MATCH "(.*)>=(.*)" _dummy "${_pkgconfig_name}")
61 if ("${CMAKE_MATCH_2}" STREQUAL "")
62 pkg_check_modules(PC_${_component_prefix} "${_pkgconfig_name} >= ${GSTREAMER_1_0_MINIMUM_VERSION}")
64 pkg_check_modules(PC_${_component_prefix} ${_pkgconfig_name})
66 set(${_component_prefix}_INCLUDE_DIRS ${PC_${_component_prefix}_INCLUDE_DIRS})
68 find_library(${_component_prefix}_LIBRARIES
69 NAMES ${_library} gstreamer_android
70 HINTS ${PC_${_component_prefix}_LIBRARY_DIRS} ${PC_${_component_prefix}_LIBDIR} ${GSTREAMER_1_0_ROOT_DIR}
74 # ------------------------
75 # 1. Find Gstreamer itself
76 # ------------------------
78 # 1.1. Find headers and libraries
79 set(GLIB_ROOT_DIR ${GSTREAMER_1_0_ROOT_DIR})
80 find_package(Glib REQUIRED)
81 FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0 gstreamer-1.0 gstreamer-1.0)
82 FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_BASE gstreamer-base-1.0 gstbase-1.0)
84 # 1.2. Check Gstreamer version
85 if (GSTREAMER_1_0_INCLUDE_DIRS)
86 if (EXISTS "${GSTREAMER_1_0_INCLUDE_DIRS}/gst/gstversion.h")
87 file(READ "${GSTREAMER_1_0_INCLUDE_DIRS}/gst/gstversion.h" GSTREAMER_VERSION_CONTENTS)
89 string(REGEX MATCH "#define +GST_VERSION_MAJOR +\\(([0-9]+)\\)" _dummy "${GSTREAMER_VERSION_CONTENTS}")
90 set(GSTREAMER_1_0_VERSION_MAJOR "${CMAKE_MATCH_1}")
92 string(REGEX MATCH "#define +GST_VERSION_MINOR +\\(([0-9]+)\\)" _dummy "${GSTREAMER_1_0_VERSION_CONTENTS}")
93 set(GSTREAMER_1_0_VERSION_MINOR "${CMAKE_MATCH_1}")
95 string(REGEX MATCH "#define +GST_VERSION_MICRO +\\(([0-9]+)\\)" _dummy "${GSTREAMER_1_0_VERSION_CONTENTS}")
96 set(GSTREAMER_1_0_VERSION_MICRO "${CMAKE_MATCH_1}")
98 set(GSTREAMER_1_0_VERSION "${GSTREAMER_1_0_VERSION_MAJOR}.${GSTREAMER_1_0_VERSION_MINOR}.${GSTREAMER_1_0_VERSION_MICRO}")
102 # FIXME: With CMake 2.8.3 we can just pass GSTREAMER_1_0_VERSION to FIND_PACKAGE_HANDLE_STANDARD_ARGS as VERSION_VAR
103 # and remove the version check here (GSTREAMER_1_0_MINIMUM_VERSION would be passed to FIND_PACKAGE).
105 if ("${GSTREAMER_1_0_VERSION}" VERSION_LESS "${GSTREAMER_1_0_MINIMUM_VERSION}")
106 set(VERSION_OK FALSE)
109 # -------------------------
110 # 2. Find Gstreamer plugins
111 # -------------------------
113 FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_APP gstreamer-app-1.0 gstapp-1.0)
114 FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_AUDIO gstreamer-audio-1.0 gstaudio-1.0)
115 FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_FFT gstreamer-fft-1.0 gstfft-1.0)
116 FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_PBUTILS gstreamer-pbutils-1.0 gstpbutils-1.0)
117 FIND_GSTREAMER_COMPONENT(GSTREAMER_1_0_VIDEO gstreamer-video-1.0 gstvideo-1.0)
119 # ------------------------------------------------
120 # 3. Process the COMPONENTS passed to FIND_PACKAGE
121 # ------------------------------------------------
122 set(_GSTREAMER_1_0_REQUIRED_VARS
125 GSTREAMER_1_0_INCLUDE_DIRS
126 GSTREAMER_1_0_LIBRARIES
128 GSTREAMER_1_0_BASE_INCLUDE_DIRS
129 GSTREAMER_1_0_BASE_LIBRARIES)
131 include(FindPackageHandleStandardArgs)
132 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GSTREAMER_1_0 DEFAULT_MSG GSTREAMER_1_0_LIBRARIES GSTREAMER_1_0_INCLUDE_DIRS)
134 list(APPEND GSTREAMER_1_0_INCLUDE_DIRS ${Glib_INCLUDE_DIRS})
135 list(APPEND GSTREAMER_1_0_LIBRARIES ${Glib_LIBRARIES})
136 list(APPEND GSTREAMER_1_0_INCLUDE_DIRS ${GSTREAMER_1_0_BASE_INCLUDE_DIRS})
137 list(APPEND GSTREAMER_1_0_LIBRARIES ${GSTREAMER_1_0_BASE_LIBRARIES})
138 list(APPEND GSTREAMER_1_0_INCLUDE_DIRS ${GSTREAMER_1_0_APP_INCLUDE_DIRS})
139 list(APPEND GSTREAMER_1_0_LIBRARIES ${GSTREAMER_1_0_APP_LIBRARIES})
140 list(APPEND GSTREAMER_1_0_INCLUDE_DIRS ${GSTREAMER_1_0_VIDEO_INCLUDE_DIRS})
141 list(APPEND GSTREAMER_1_0_LIBRARIES ${GSTREAMER_1_0_VIDEO_LIBRARIES})
143 foreach (_component ${Gstreamer_FIND_COMPONENTS})
144 set(_gst_component "GSTREAMER_1_0_${_component}")
145 string(TOUPPER ${_gst_component} _UPPER_NAME)
147 FIND_PACKAGE_HANDLE_STANDARD_ARGS(${_UPPER_NAME} DEFAULT_MSG ${_UPPER_NAME}_INCLUDE_DIRS ${_UPPER_NAME}_LIBRARIES)
148 list(APPEND GSTREAMER_1_0_INCLUDE_DIRS ${${_UPPER_NAME}_INCLUDE_DIRS})
149 list(APPEND GSTREAMER_1_0_LIBRARIES ${${_UPPER_NAME}_LIBRARIES})
152 MARK_AS_ADVANCED(GSTREAMER_1_0_INCLUDE_DIRS GSTREAMER_1_0_LIBRARIES GSTREAMER_1_0_BASE_LIBRARY GSTREAMER_1_0_APP_LIBRARY)