add some comments
[makneto-zunavac1.git] / CMakeMod / FindGStreamer.cmake
blob55c3ce97d834dcb3078ba7d897572e408cc30895
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)
24 else()
25     set(GStreamer_FIND_QUIETLY FALSE)
26 endif()
28 set(GSTREAMER_ABI_VERSION "0.10")
31 # Find the main library
32 find_package(PkgConfig)
34 if (PKG_CONFIG_FOUND)
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)
39 endif()
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
46           gst/gst.h
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})
52 else()
53     get_filename_component(_GSTREAMER_LIB_DIR ${GSTREAMER_LIBRARY} PATH)
54     set(_GSTREAMER_PLUGIN_DIR ${_GSTREAMER_LIB_DIR}/gstreamer-${GSTREAMER_ABI_VERSION})
55 endif()
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)
70 endmacro()
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)
83     else()
84         message (AUTHOR_WARNING "FindGStreamerPluginsBase.cmake: Invalid component \"${_component}\" was specified")
85     endif()
86 endforeach()
89 # Version check
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)
95         else()
96             set(GSTREAMER_VERSION_COMPATIBLE TRUE)
97         endif()
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
108 #define G_END_DECLS
109 #include <gst/gstversion.h>
111 #if GST_CHECK_VERSION(${_comma_version})
112 int main() { return 0; }
113 #else
114 # error \"GStreamer version incompatible\"
115 #endif
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")
120         endif()
121     else()
122         # We didn't find gstreamer at all
123         set(GSTREAMER_VERSION_COMPATIBLE FALSE)
124     endif()
125 else()
126     # No version constrain was specified, thus we consider the version compatible
127     set(GSTREAMER_VERSION_COMPATIBLE TRUE)
128 endif()
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})