93332697336544535915cdfebf8e5972b481561f
[quassel.git] / cmake / modules / FindPhonon.cmake
1 # Find libphonon
2 # Once done this will define
3 #
4 #  PHONON_FOUND    - system has Phonon Library
5 #  PHONON_INCLUDES - the Phonon include directory
6 #  PHONON_LIBS     - link these to use Phonon
7 #  PHONON_VERSION  - the version of the Phonon Library
8
9 # Copyright (c) 2008, Matthias Kretz <kretz@kde.org>
10 #
11 # Redistribution and use is allowed according to the terms of the BSD license.
12 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
13
14 macro(_phonon_find_version)
15    file(READ "${PHONON_INCLUDE_DIR}/phonon/phononnamespace.h" _phonon_header LIMIT 5000 OFFSET 1000)
16    string(REGEX MATCH "define PHONON_VERSION_STR \"(4\\.[0-9]+\\.[0-9a-z]+)\"" _phonon_version_match "${_phonon_header}")
17    set(PHONON_VERSION "${CMAKE_MATCH_1}")
18    message(STATUS "Phonon Version: ${PHONON_VERSION}")
19 endmacro(_phonon_find_version)
20
21 if(PHONON_FOUND)
22    # Already found, nothing more to do except figuring out the version
23    _phonon_find_version()
24 else(PHONON_FOUND)
25    if(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
26       set(PHONON_FIND_QUIETLY TRUE)
27    endif(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
28
29    # As discussed on kde-buildsystem: first look at CMAKE_PREFIX_PATH, then at the suggested PATHS (kde4 install dir)
30    find_library(PHONON_LIBRARY NAMES phonon PATHS ${KDE4_LIB_INSTALL_DIR} ${QT_LIBRARY_DIR} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
31    # then at the default system locations (CMAKE_SYSTEM_PREFIX_PATH, i.e. /usr etc.)
32    find_library(PHONON_LIBRARY NAMES phonon)
33
34    find_path(PHONON_INCLUDE_DIR NAMES phonon/phonon_export.h PATHS ${KDE4_INCLUDE_INSTALL_DIR} ${QT_INCLUDE_DIR} ${INCLUDE_INSTALL_DIR} NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
35    find_path(PHONON_INCLUDE_DIR NAMES phonon/phonon_export.h)
36
37    if(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
38       set(PHONON_LIBS ${phonon_LIB_DEPENDS} ${PHONON_LIBRARY})
39       set(PHONON_INCLUDES ${PHONON_INCLUDE_DIR}/KDE ${PHONON_INCLUDE_DIR})
40       set(PHONON_FOUND TRUE)
41       _phonon_find_version()
42    else(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
43       set(PHONON_FOUND FALSE)
44    endif(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
45
46    if(PHONON_FOUND)
47       if(NOT PHONON_FIND_QUIETLY)
48          message(STATUS "Found Phonon: ${PHONON_LIBRARY}")
49          message(STATUS "Found Phonon Includes: ${PHONON_INCLUDES}")
50       endif(NOT PHONON_FIND_QUIETLY)
51    else(PHONON_FOUND)
52       if(Phonon_FIND_REQUIRED)
53          if(NOT PHONON_INCLUDE_DIR)
54             message(STATUS "Phonon includes NOT found!")
55          endif(NOT PHONON_INCLUDE_DIR)
56          if(NOT PHONON_LIBRARY)
57             message(STATUS "Phonon library NOT found!")
58          endif(NOT PHONON_LIBRARY)
59          message(FATAL_ERROR "Phonon library or includes NOT found!")
60       else(Phonon_FIND_REQUIRED)
61          message(STATUS "Unable to find Phonon")
62       endif(Phonon_FIND_REQUIRED)
63    endif(PHONON_FOUND)
64
65
66    mark_as_advanced(PHONON_INCLUDE_DIR PHONON_LIBRARY PHONON_INCLUDES)
67 endif(PHONON_FOUND)