1# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4#[=======================================================================[.rst:
5FindKDE4
6--------
7
8
9
10Find KDE4 and provide all necessary variables and macros to compile
11software for it.  It looks for KDE 4 in the following directories in
12the given order:
13
14::
15
16  CMAKE_INSTALL_PREFIX
17  KDEDIRS
18  /opt/kde4
19
20
21
22Please look in ``FindKDE4Internal.cmake`` and ``KDE4Macros.cmake`` for more
23information.  They are installed with the KDE 4 libraries in
24$KDEDIRS/share/apps/cmake/modules/.
25
26Author: Alexander Neundorf <[email protected]>
27#]=======================================================================]
28
29# If Qt3 has already been found, fail.
30if(QT_QT_LIBRARY)
31  if(KDE4_FIND_REQUIRED)
32    message( FATAL_ERROR "KDE4/Qt4 and Qt3 cannot be used together in one project.")
33  else()
34    if(NOT KDE4_FIND_QUIETLY)
35      message( STATUS    "KDE4/Qt4 and Qt3 cannot be used together in one project.")
36    endif()
37    return()
38  endif()
39endif()
40
41file(TO_CMAKE_PATH "$ENV{KDEDIRS}" _KDEDIRS)
42
43# when cross compiling, searching kde4-config in order to run it later on
44# doesn't make a lot of sense. We'll have to do something about this.
45# Searching always in the target environment ? Then we get at least the correct one,
46# still it can't be used to run it. Alex
47
48# For KDE4 kde-config has been renamed to kde4-config
49find_program(KDE4_KDECONFIG_EXECUTABLE NAMES kde4-config
50   # the suffix must be used since KDEDIRS can be a list of directories which don't have bin/ appended
51   PATH_SUFFIXES bin
52   HINTS
53   ${CMAKE_INSTALL_PREFIX}
54   ${_KDEDIRS}
55   /opt/kde4
56   ONLY_CMAKE_FIND_ROOT_PATH
57   )
58
59if (NOT KDE4_KDECONFIG_EXECUTABLE)
60  if (KDE4_FIND_REQUIRED)
61    message(FATAL_ERROR "ERROR: Could not find KDE4 kde4-config")
62  endif ()
63endif ()
64
65
66# when cross compiling, KDE4_DATA_DIR may be already preset
67if(NOT KDE4_DATA_DIR)
68  if(CMAKE_CROSSCOMPILING)
69    # when cross compiling, don't run kde4-config but use its location as install dir
70    get_filename_component(KDE4_DATA_DIR "${KDE4_KDECONFIG_EXECUTABLE}" PATH)
71    get_filename_component(KDE4_DATA_DIR "${KDE4_DATA_DIR}" PATH)
72  else()
73    # then ask kde4-config for the kde data dirs
74
75    if(KDE4_KDECONFIG_EXECUTABLE)
76      execute_process(COMMAND "${KDE4_KDECONFIG_EXECUTABLE}" --path data OUTPUT_VARIABLE _data_DIR ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
77      file(TO_CMAKE_PATH "${_data_DIR}" _data_DIR)
78      # then check the data dirs for FindKDE4Internal.cmake
79      find_path(KDE4_DATA_DIR cmake/modules/FindKDE4Internal.cmake HINTS ${_data_DIR})
80    endif()
81  endif()
82endif()
83
84# if it has been found...
85if (KDE4_DATA_DIR)
86
87  set(CMAKE_MODULE_PATH  ${CMAKE_MODULE_PATH} ${KDE4_DATA_DIR}/cmake/modules)
88
89  if (KDE4_FIND_QUIETLY)
90    set(_quiet QUIET)
91  endif ()
92
93  if (KDE4_FIND_REQUIRED)
94    set(_req REQUIRED)
95  endif ()
96
97  # use FindKDE4Internal.cmake to do the rest
98  find_package(KDE4Internal ${_req} ${_quiet} NO_POLICY_SCOPE)
99else ()
100  if (KDE4_FIND_REQUIRED)
101    message(FATAL_ERROR "ERROR: cmake/modules/FindKDE4Internal.cmake not found in ${_data_DIR}")
102  endif ()
103endif ()
104