Improve the build system; add new features and examples:
[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_QTCORE_REQUIRED FALSE)
26
27 if(BUILDING_QTGSTREAMER)
28     set(QTGSTREAMER_LIBRARY QtGstreamer)
29     set(QTGSTREAMER_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src)
30 else()
31     # Attempt to find the generated QtGstreamerTargets.cmake in the same directory
32     get_filename_component(_QTGSTREAMER_CONFIG_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
33     find_file(_QTGSTREAMER_TARGETS_FILE QtGstreamerTargets.cmake PATHS ${_QTGSTREAMER_CONFIG_DIR} NO_DEFAULT_PATH)
34
35     if(_QTGSTREAMER_TARGETS_FILE-NOTFOUND)
36         # Targets file not found. Do a typical search for QtGstreamer.
37         # Normally, this path is never executed. It is just provided as a fallback in case something goes wrong.
38         find_library(QTGSTREAMER_LIBRARY QtGstreamer
39                      PATHS "${_QTGSTREAMER_CONFIG_DIR}/../../lib")
40         find_path(QTGSTREAMER_INCLUDE_DIR QGst/global.h
41                   PATHS "${_QTGSTREAMER_CONFIG_DIR}/../../include"
42                   PATH_SUFFIXES QtGstreamer)
43         set(_QTGSTREAMER_LINK_TO_QTCORE_REQUIRED TRUE)
44     else()
45         # Targets file found. Use imported QtGstreamer target and relative include path.
46         # We assume that this file has been installed in $PREFIX/lib/QtGstreamer/,
47         # so the include path should evaluate to $PREFIX/include/QtGstreamer
48         include(${_QTGSTREAMER_TARGETS_FILE})
49         set(QTGSTREAMER_LIBRARY QtGstreamer)
50         get_filename_component(QTGSTREAMER_INCLUDE_DIR "${_QTGSTREAMER_CONFIG_DIR}/../../include/QtGstreamer" ABSOLUTE)
51     endif()
52 endif()
53
54 include(FindPackageHandleStandardArgs)
55 find_package_handle_standard_args(QtGstreamer DEFAULT_MSG QTGSTREAMER_INCLUDE_DIR QTGSTREAMER_LIBRARY)
56
57 if(QTGSTREAMER_FOUND)
58     # Find dependencies, if not already found
59     if (NOT DEFINED QT_INCLUDE_DIR)
60         message(STATUS "Qt hasn't been found yet. Looking...")
61         find_package(Qt4 COMPONENTS QtCore REQUIRED)
62     endif()
63
64     if (NOT DEFINED Boost_INCLUDE_DIRS)
65         message(STATUS "Boost hasn't been found yet. Looking...")
66         find_package(Boost REQUIRED)
67     endif()
68
69     # Set misc variables
70     set(QTGSTREAMER_INCLUDES ${QTGSTREAMER_INCLUDE_DIR} ${QT_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
71     set(QTGSTREAMER_DEFINITIONS "-DQT_NO_KEYWORDS")
72
73     if (_QTGSTREAMER_LINK_TO_QTCORE_REQUIRED)
74         set(QTGSTREAMER_LIBRARIES ${QTGSTREAMER_LIBRARY} ${QT_QTCORE_LIBRARY})
75     else()
76         set(QTGSTREAMER_LIBRARIES ${QTGSTREAMER_LIBRARY})
77     endif()
78
79     if (CMAKE_COMPILER_IS_GNUCXX)
80         include(TestCXXAcceptsFlag)
81         check_cxx_accepts_flag("-std=c++0x" _QTGSTREAMER_HAVE_CXX0X_SUPPORT)
82         if (_QTGSTREAMER_HAVE_CXX0X_SUPPORT)
83             set(QTGSTREAMER_FLAGS "-std=c++0x")
84         endif()
85     endif()
86 endif()
87
88 mark_as_advanced(QTGSTREAMER_LIBRARY QTGSTREAMER_INCLUDE_DIR)