ab0a86c8d934675a892e80ddee9e0cdf46d9959a
[quassel.git] / 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    set(_phonon_namespace_header_file "${PHONON_INCLUDE_DIR}/phonon/phononnamespace.h")
16    if (APPLE AND EXISTS "${PHONON_INCLUDE_DIR}/Headers/phononnamespace.h")
17       set(_phonon_namespace_header_file "${PHONON_INCLUDE_DIR}/Headers/phononnamespace.h")
18    endif (APPLE AND EXISTS "${PHONON_INCLUDE_DIR}/Headers/phononnamespace.h")
19    file(READ ${_phonon_namespace_header_file} _phonon_header LIMIT 5000 OFFSET 1000)
20    string(REGEX MATCH "define PHONON_VERSION_STR \"(4\\.[0-9]+\\.[0-9a-z]+)\"" _phonon_version_match "${_phonon_header}")
21    set(PHONON_VERSION "${CMAKE_MATCH_1}")
22    message(STATUS "Phonon Version: ${PHONON_VERSION}")
23 endmacro(_phonon_find_version)
24
25 if(PHONON_FOUND)
26    # Already found, nothing more to do except figuring out the version
27    _phonon_find_version()
28 else(PHONON_FOUND)
29    if(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
30       set(PHONON_FIND_QUIETLY TRUE)
31    endif(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
32
33    find_library(PHONON_LIBRARY_RELEASE NAMES phonon phonon4 HINTS ${KDE4_LIB_INSTALL_DIR} ${QT_LIBRARY_DIR})
34    find_library(PHONON_LIBRARY_DEBUG NAMES phonond phonond4 HINTS ${KDE4_LIB_INSTALL_DIR} ${QT_LIBRARY_DIR})
35
36    # if the release- as well as the debug-version of the library have been found:
37    IF (PHONON_LIBRARY_DEBUG AND PHONON_LIBRARY_RELEASE)
38      # if the generator supports configuration types then set
39      # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
40      IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
41        SET(PHONON_LIBRARY       optimized ${PHONON_LIBRARY_RELEASE} debug ${PHONON_LIBRARY_DEBUG})
42      ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
43        # if there are no configuration types and CMAKE_BUILD_TYPE has no value
44        # then just use the release libraries
45        SET(PHONON_LIBRARY       ${PHONON_LIBRARY_RELEASE} )
46      ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
47    ELSE(PHONON_LIBRARY_DEBUG AND PHONON_LIBRARY_RELEASE)
48      IF (PHONON_LIBRARY_RELEASE)
49        SET(PHONON_LIBRARY ${PHONON_LIBRARY_RELEASE})
50      ENDIF (PHONON_LIBRARY_RELEASE)
51    ENDIF (PHONON_LIBRARY_DEBUG AND PHONON_LIBRARY_RELEASE)
52
53    find_path(PHONON_INCLUDE_DIR NAMES phonon/phonon_export.h HINTS ${KDE4_INCLUDE_INSTALL_DIR} ${QT_INCLUDE_DIR} ${INCLUDE_INSTALL_DIR} ${QT_LIBRARY_DIR})
54
55    if(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
56       set(PHONON_LIBS ${phonon_LIB_DEPENDS} ${PHONON_LIBRARY})
57       set(PHONON_INCLUDES ${PHONON_INCLUDE_DIR}/KDE ${PHONON_INCLUDE_DIR})
58       set(PHONON_FOUND TRUE)
59       _phonon_find_version()
60    else(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
61       set(PHONON_FOUND FALSE)
62    endif(PHONON_INCLUDE_DIR AND PHONON_LIBRARY)
63
64    include(FindPackageHandleStandardArgs)
65    find_package_handle_standard_args(Phonon  DEFAULT_MSG  PHONON_INCLUDE_DIR PHONON_LIBRARY)
66
67    mark_as_advanced(PHONON_INCLUDE_DIR PHONON_LIBRARY)
68 endif(PHONON_FOUND)