Add a new QtGstreamerUi library that contains a VideoWidget class, a widget that...
[qtgstreamer:qtgstreamer.git] / cmake / modules / FindQtGstreamer.cmake
1 # - Try to find QtGstreamer
2 # Once done this will define
3 #
4 #  QTGSTREAMER_FOUND - system has QtGstreamer
5 #  QTGSTREAMER_INCLUDE_DIR - the QtGstreamer include directory
6 #  QTGSTREAMER_INCLUDES - the include directories needed to use QtGstreamer
7 #  QTGSTREAMER_LIBRARY - the QtGstreamer library
8 #  QTGSTREAMER_LIBRARIES - the libraries needed to use QtGstreamer
9 #  QTGSTREAMER_DEFINITIONS - definitions recommended for using QtGstreamer
10 #  QTGSTREAMER_FLAGS - extra compiler switches recommended for using QtGstreamer
11 #
12 # Copyright (c) 2010, George Kiagiadakis <kiagiadakis.george@gmail.com>
13 #
14 # Redistribution and use is allowed according to the terms of the BSD license.
15 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
16
17
18 # if variables are already in cache or we are building QtGstreamer
19 if((QTGSTREAMER_LIBRARY AND QTGSTREAMER_INCLUDE_DIR) OR BUILDING_QTGSTREAMER)
20     set(QtGstreamer_FIND_QUIETLY TRUE)
21 else()
22     set(QtGstreamer_FIND_QUIETLY FALSE)
23 endif()
24
25 set(_QTGSTREAMER_LINK_TO_QT_REQUIRED FALSE)
26
27 if(BUILDING_QTGSTREAMER)
28     set(QTGSTREAMER_LIBRARY QtGstreamer)
29     set(QTGSTREAMER_UI_LIBRARY QtGstreamerUi)
30     set(QTGSTREAMER_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src)
31 else()
32     # Attempt to find the generated QtGstreamerTargets.cmake in the same directory
33     get_filename_component(_QTGSTREAMER_CONFIG_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
34     find_file(_QTGSTREAMER_TARGETS_FILE QtGstreamerTargets.cmake PATHS ${_QTGSTREAMER_CONFIG_DIR} NO_DEFAULT_PATH)
35
36     if(_QTGSTREAMER_TARGETS_FILE-NOTFOUND)
37         # Targets file not found. Do a typical search for QtGstreamer.
38         # Normally, this path is never executed. It is just provided as a fallback in case something goes wrong.
39         find_library(QTGSTREAMER_LIBRARY QtGstreamer
40                      PATHS "${_QTGSTREAMER_CONFIG_DIR}/../../lib")
41         find_library(QTGSTREAMER_UI_LIBRARY QtGstreamerUi
42                      PATHS "${_QTGSTREAMER_CONFIG_DIR}/../../lib")
43         find_path(QTGSTREAMER_INCLUDE_DIR QGst/global.h
44                   PATHS "${_QTGSTREAMER_CONFIG_DIR}/../../include"
45                   PATH_SUFFIXES QtGstreamer)
46         set(_QTGSTREAMER_LINK_TO_QT_REQUIRED TRUE)
47     else()
48         # Targets file found. Use imported QtGstreamer target and relative include path.
49         # We assume that this file has been installed in $PREFIX/lib/QtGstreamer/,
50         # so the include path should evaluate to $PREFIX/include/QtGstreamer
51         include(${_QTGSTREAMER_TARGETS_FILE})
52         set(QTGSTREAMER_LIBRARY QtGstreamer)
53         set(QTGSTREAMER_UI_LIBRARY QtGstreamerUi)
54         get_filename_component(QTGSTREAMER_INCLUDE_DIR "${_QTGSTREAMER_CONFIG_DIR}/../../include/QtGstreamer" ABSOLUTE)
55     endif()
56 endif()
57
58 include(FindPackageHandleStandardArgs)
59 find_package_handle_standard_args(QtGstreamer DEFAULT_MSG QTGSTREAMER_INCLUDE_DIR
60                                                           QTGSTREAMER_LIBRARY QTGSTREAMER_UI_LIBRARY)
61
62 if(QTGSTREAMER_FOUND)
63     # Find dependencies, if not already found
64     if (NOT DEFINED QT_INCLUDE_DIR)
65         message(STATUS "Qt hasn't been found yet. Looking...")
66         find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
67     endif()
68
69     if (NOT DEFINED Boost_INCLUDE_DIRS)
70         message(STATUS "Boost hasn't been found yet. Looking...")
71         find_package(Boost REQUIRED)
72     endif()
73
74     # Set misc variables
75     set(QTGSTREAMER_INCLUDES ${QTGSTREAMER_INCLUDE_DIR} ${QT_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
76     set(QTGSTREAMER_DEFINITIONS "-DQT_NO_KEYWORDS")
77
78     if (_QTGSTREAMER_LINK_TO_QT_REQUIRED)
79         set(QTGSTREAMER_LIBRARIES ${QTGSTREAMER_LIBRARY} ${QT_QTCORE_LIBRARY})
80         set(QTGSTREAMER_UI_LIBRARIES ${QTGSTREAMER_UI_LIBRARY} ${QTGSTREAMER_LIBRARY}
81                                     ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
82     else()
83         set(QTGSTREAMER_LIBRARIES ${QTGSTREAMER_LIBRARY})
84         set(QTGSTREAMER_UI_LIBRARIES ${QTGSTREAMER_UI_LIBRARY})
85     endif()
86
87     if (CMAKE_COMPILER_IS_GNUCXX)
88         include(TestCXXAcceptsFlag)
89         check_cxx_accepts_flag("-std=c++0x" _QTGSTREAMER_HAVE_CXX0X_SUPPORT)
90         if (_QTGSTREAMER_HAVE_CXX0X_SUPPORT)
91             set(QTGSTREAMER_FLAGS "-std=c++0x")
92         endif()
93     endif()
94 endif()
95
96 mark_as_advanced(QTGSTREAMER_LIBRARY QTGSTREAMER_INCLUDE_DIR)