1 # - Try to find GStreamer
2 # Once done this will define
4 # GSTREAMER_FOUND - system has GStreamer
5 # GSTREAMER_INCLUDE_DIR - the GStreamer include directory
6 # GSTREAMER_LIBRARY - the main GStreamer library
7 # GSTREAMER_PLUGIN_DIR - the GStreamer plugin directory
9 # And for all the plugin libraries specified in the COMPONENTS
10 # of find_package, this module will define:
12 # GSTREAMER_<plugin_lib>_LIBRARY_FOUND - system has <plugin_lib>
13 # GSTREAMER_<plugin_lib>_LIBRARY - the <plugin_lib> library
14 # GSTREAMER_<plugin_lib>_INCLUDE_DIR - the <plugin_lib> include directory
16 # Copyright (c) 2010, Collabora Ltd.
17 # @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk>
19 # Redistribution and use is allowed according to the terms of the BSD license.
20 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
22 if (GSTREAMER_INCLUDE_DIR AND GSTREAMER_LIBRARY)
23 set(GStreamer_FIND_QUIETLY TRUE)
25 set(GStreamer_FIND_QUIETLY FALSE)
28 set(GSTREAMER_ABI_VERSION "0.10")
31 # Find the main library
32 find_package(PkgConfig)
35 pkg_check_modules(PKG_GSTREAMER gstreamer-${GSTREAMER_ABI_VERSION})
36 exec_program(${PKG_CONFIG_EXECUTABLE}
37 ARGS --variable pluginsdir gstreamer-${GSTREAMER_ABI_VERSION}
38 OUTPUT_VARIABLE PKG_GSTREAMER_PLUGIN_DIR)
41 find_library(GSTREAMER_LIBRARY
42 NAMES gstreamer-${GSTREAMER_ABI_VERSION}
43 HINTS ${PKG_GSTREAMER_LIBRARY_DIRS} ${PKG_GSTREAMER_LIBDIR})
45 find_path(GSTREAMER_INCLUDE_DIR
47 HINTS ${PKG_GSTREAMER_INCLUDE_DIRS} ${PKG_GSTREAMER_INCLUDEDIR}
48 PATH_SUFFIXES gstreamer-${GSTREAMER_ABI_VERSION})
50 if (PKG_GSTREAMER_PLUGIN_DIR)
51 set(_GSTREAMER_PLUGIN_DIR ${PKG_GSTREAMER_PLUGIN_DIR})
53 get_filename_component(_GSTREAMER_LIB_DIR ${GSTREAMER_LIBRARY} PATH)
54 set(_GSTREAMER_PLUGIN_DIR ${_GSTREAMER_LIB_DIR}/gstreamer-${GSTREAMER_ABI_VERSION})
57 set(GSTREAMER_PLUGIN_DIR ${_GSTREAMER_PLUGIN_DIR}
58 CACHE PATH "The path to the gstreamer plugins installation directory")
60 mark_as_advanced(GSTREAMER_LIBRARY GSTREAMER_INCLUDE_DIR GSTREAMER_PLUGIN_DIR)
63 # Find additional libraries
64 include(MacroFindGStreamerLibrary)
66 macro(_find_gst_component _name _header)
67 find_gstreamer_library(${_name} ${_header} ${GSTREAMER_ABI_VERSION})
68 set(_GSTREAMER_EXTRA_VARIABLES ${_GSTREAMER_EXTRA_VARIABLES}
69 GSTREAMER_${_name}_LIBRARY GSTREAMER_${_name}_INCLUDE_DIR)
72 foreach(_component ${GStreamer_FIND_COMPONENTS})
73 if (${_component} STREQUAL "base")
74 _find_gst_component(BASE gstbasesink.h)
75 elseif (${_component} STREQUAL "check")
76 _find_gst_component(CHECK gstcheck.h)
77 elseif (${_component} STREQUAL "controller")
78 _find_gst_component(CONTROLLER gstcontroller.h)
79 elseif (${_component} STREQUAL "dataprotocol")
80 _find_gst_component(DATAPROTOCOL dataprotocol.h)
81 elseif (${_component} STREQUAL "net")
82 _find_gst_component(NET gstnet.h)
84 message (AUTHOR_WARNING "FindGStreamerPluginsBase.cmake: Invalid component \"${_component}\" was specified")
90 if (GStreamer_FIND_VERSION)
91 if (PKG_GSTREAMER_FOUND)
92 if("${PKG_GSTREAMER_VERSION}" VERSION_LESS "${GStreamer_FIND_VERSION}")
93 message(STATUS "Found GStreamer version ${PKG_GSTREAMER_VERSION}, but at least version ${GStreamer_FIND_VERSION} is required")
94 set(GSTREAMER_VERSION_COMPATIBLE FALSE)
96 set(GSTREAMER_VERSION_COMPATIBLE TRUE)
98 elseif(GSTREAMER_INCLUDE_DIR)
99 include(CheckCXXSourceCompiles)
101 set(CMAKE_REQUIRED_INCLUDES ${GSTREAMER_INCLUDE_DIR})
102 string(REPLACE "." "," _comma_version ${GStreamer_FIND_VERSION})
103 # Hack to invalidate the cached value
104 set(GSTREAMER_VERSION_COMPATIBLE GSTREAMER_VERSION_COMPATIBLE)
106 check_cxx_source_compiles("
107 #define G_BEGIN_DECLS
109 #include <gst/gstversion.h>
111 #if GST_CHECK_VERSION(${_comma_version})
112 int main() { return 0; }
114 # error \"GStreamer version incompatible\"
116 " GSTREAMER_VERSION_COMPATIBLE)
118 if (NOT GSTREAMER_VERSION_COMPATIBLE)
119 message(STATUS "GStreamer ${GStreamer_FIND_VERSION} is required, but the version found is older")
122 # We didn't find gstreamer at all
123 set(GSTREAMER_VERSION_COMPATIBLE FALSE)
126 # No version constrain was specified, thus we consider the version compatible
127 set(GSTREAMER_VERSION_COMPATIBLE TRUE)
131 include(FindPackageHandleStandardArgs)
132 find_package_handle_standard_args(GStreamer DEFAULT_MSG
133 GSTREAMER_LIBRARY GSTREAMER_INCLUDE_DIR
134 GSTREAMER_VERSION_COMPATIBLE ${_GSTREAMER_EXTRA_VARIABLES})