Minor fixes to the build scripts for MSVC debug builds, and added debug library suppo...
[quassel.git] / cmake / modules / FindQt4.cmake
1 # - Find QT 4
2 # This module can be used to find Qt4.
3 # The most important issue is that the Qt4 qmake is available via the system path.
4 # This qmake is then used to detect basically everything else.
5 # This module defines a number of key variables and macros. 
6 # The variable QT_USE_FILE is set which is the path to a CMake file that can be included 
7 # to compile Qt 4 applications and libraries.  It sets up the compilation
8 # environment for include directories, preprocessor defines and populates a
9 # QT_LIBRARIES variable.
10 #
11 # Typical usage could be something like:
12 #   find_package(Qt4 4.4.3 COMPONENTS QtCore QtGui QtXml REQUIRED )
13 #   include(${QT_USE_FILE})
14 #   add_executable(myexe main.cpp)
15 #   target_link_libraries(myexe ${QT_LIBRARIES})
16 #
17 # The minimum required version can be specified using the standard find_package()-syntax
18 # (see example above). 
19 # For compatibility with older versions of FindQt4.cmake it is also possible to
20 # set the variable QT_MIN_VERSION to the minimum required version of Qt4 before the 
21 # find_package(Qt4) command. 
22 # If both are used, the version used in the find_package() command overrides the
23 # one from QT_MIN_VERSION.
24 #
25 # When using the components argument, QT_USE_QT* variables are automatically set
26 # for the QT_USE_FILE to pick up.  If one wishes to manually set them, the
27 # available ones to set include:
28 #                    QT_DONT_USE_QTCORE
29 #                    QT_DONT_USE_QTGUI
30 #                    QT_USE_QT3SUPPORT
31 #                    QT_USE_QTASSISTANT
32 #                    QT_USE_QAXCONTAINER
33 #                    QT_USE_QAXSERVER
34 #                    QT_USE_QTDESIGNER
35 #                    QT_USE_QTMOTIF
36 #                    QT_USE_QTMAIN
37 #                    QT_USE_QTMULTIMEDIA
38 #                    QT_USE_QTNETWORK
39 #                    QT_USE_QTNSPLUGIN
40 #                    QT_USE_QTOPENGL
41 #                    QT_USE_QTSQL
42 #                    QT_USE_QTXML
43 #                    QT_USE_QTSVG
44 #                    QT_USE_QTTEST
45 #                    QT_USE_QTUITOOLS
46 #                    QT_USE_QTDBUS
47 #                    QT_USE_QTSCRIPT
48 #                    QT_USE_QTASSISTANTCLIENT
49 #                    QT_USE_QTHELP
50 #                    QT_USE_QTWEBKIT
51 #                    QT_USE_QTXMLPATTERNS
52 #                    QT_USE_PHONON
53 #                    QT_USE_QTSCRIPTTOOLS
54 #                    QT_USE_QTDECLARATIVE
55 #
56 #  QT_USE_IMPORTED_TARGETS 
57 #        If this variable is set to TRUE, FindQt4.cmake will create imported
58 #        library targets for the various Qt libraries and set the 
59 #        library variables like QT_QTCORE_LIBRARY to point at these imported
60 #        targets instead of the library file on disk. This provides much better 
61 #        handling of the release and debug versions of the Qt libraries and is 
62 #       also always backwards compatible, except for the case that dependencies
63 #       of libraries are exported, these will then also list the names of the 
64 #       imported targets as dependency and not the file location on disk. This
65 #       is much more flexible, but requires that FindQt4.cmake is executed before
66 #       such an exported dependency file is processed.
67 #
68 # There are also some files that need processing by some Qt tools such as moc
69 # and uic.  Listed below are macros that may be used to process those files.
70 #  
71 #  macro QT4_WRAP_CPP(outfiles inputfile ... OPTIONS ...)
72 #        create moc code from a list of files containing Qt class with
73 #        the Q_OBJECT declaration.  Per-direcotry preprocessor definitions 
74 #        are also added.  Options may be given to moc, such as those found
75 #        when executing "moc -help".  
76 #
77 #  macro QT4_WRAP_UI(outfiles inputfile ... OPTIONS ...)
78 #        create code from a list of Qt designer ui files.
79 #        Options may be given to uic, such as those found
80 #        when executing "uic -help"
81 #
82 #  macro QT4_ADD_RESOURCES(outfiles inputfile ... OPTIONS ...)
83 #        create code from a list of Qt resource files.
84 #        Options may be given to rcc, such as those found
85 #        when executing "rcc -help"
86 #
87 #  macro QT4_GENERATE_MOC(inputfile outputfile )
88 #        creates a rule to run moc on infile and create outfile.
89 #        Use this if for some reason QT4_WRAP_CPP() isn't appropriate, e.g.
90 #        because you need a custom filename for the moc file or something similar.
91 #
92 #  macro QT4_AUTOMOC(sourcefile1 sourcefile2 ... )
93 #        This macro is still experimental.
94 #        It can be used to have moc automatically handled.
95 #        So if you have the files foo.h and foo.cpp, and in foo.h a 
96 #        a class uses the Q_OBJECT macro, moc has to run on it. If you don't
97 #        want to use QT4_WRAP_CPP() (which is reliable and mature), you can insert
98 #        #include "foo.moc"
99 #        in foo.cpp and then give foo.cpp as argument to QT4_AUTOMOC(). This will the
100 #        scan all listed files at cmake-time for such included moc files and if it finds
101 #        them cause a rule to be generated to run moc at build time on the 
102 #        accompanying header file foo.h.
103 #        If a source file has the SKIP_AUTOMOC property set it will be ignored by this macro.
104 #
105 #  macro QT4_ADD_DBUS_INTERFACE(outfiles interface basename)
106 #        create a the interface header and implementation files with the 
107 #        given basename from the given interface xml file and add it to 
108 #        the list of sources.
109 #        To disable generating a namespace header, set the source file property 
110 #        NO_NAMESPACE to TRUE on the interface file.
111 #        To include a header in the interface header, set the source file property
112 #        INCLUDE to the name of the header.
113 #        To specify a class name to use, set the source file property CLASSNAME
114 #        to the name of the class.
115 #
116 #  macro QT4_ADD_DBUS_INTERFACES(outfiles inputfile ... )
117 #        create the interface header and implementation files 
118 #        for all listed interface xml files
119 #        the name will be automatically determined from the name of the xml file
120 #        To disable generating namespace headers, set the source file property 
121 #        NO_NAMESPACE to TRUE for these inputfiles.
122 #        To include a header in the interface header, set the source file property
123 #        INCLUDE to the name of the header.
124 #        To specify a class name to use, set the source file property CLASSNAME
125 #        to the name of the class.
126 #
127 #  macro QT4_ADD_DBUS_ADAPTOR(outfiles xmlfile parentheader parentclassname [basename] [classname])
128 #        create a dbus adaptor (header and implementation file) from the xml file
129 #        describing the interface, and add it to the list of sources. The adaptor
130 #        forwards the calls to a parent class, defined in parentheader and named
131 #        parentclassname. The name of the generated files will be
132 #        <basename>adaptor.{cpp,h} where basename defaults to the basename of the xml file.
133 #        If <classname> is provided, then it will be used as the classname of the
134 #        adaptor itself.
135 #
136 #  macro QT4_GENERATE_DBUS_INTERFACE( header [interfacename] OPTIONS ...)
137 #        generate the xml interface file from the given header.
138 #        If the optional argument interfacename is omitted, the name of the 
139 #        interface file is constructed from the basename of the header with
140 #        the suffix .xml appended.
141 #        Options may be given to qdbuscpp2xml, such as those found when executing "qdbuscpp2xml --help"
142 #
143 #  macro QT4_CREATE_TRANSLATION( qm_files directories ... sources ... 
144 #                                ts_files ... OPTIONS ...)
145 #        out: qm_files
146 #        in:  directories sources ts_files
147 #        options: flags to pass to lupdate, such as -extensions to specify
148 #        extensions for a directory scan.
149 #        generates commands to create .ts (vie lupdate) and .qm
150 #        (via lrelease) - files from directories and/or sources. The ts files are 
151 #        created and/or updated in the source tree (unless given with full paths).
152 #        The qm files are generated in the build tree.
153 #        Updating the translations can be done by adding the qm_files
154 #        to the source list of your library/executable, so they are
155 #        always updated, or by adding a custom target to control when
156 #        they get updated/generated.
157 #
158 #  macro QT4_ADD_TRANSLATION( qm_files ts_files ... )
159 #        out: qm_files
160 #        in:  ts_files
161 #        generates commands to create .qm from .ts - files. The generated
162 #        filenames can be found in qm_files. The ts_files
163 #        must exists and are not updated in any way.
164 #
165 #
166 #  Below is a detailed list of variables that FindQt4.cmake sets.
167 #  QT_FOUND         If false, don't try to use Qt.
168 #  QT4_FOUND        If false, don't try to use Qt 4.
169 #
170 #  QT_VERSION_MAJOR The major version of Qt found.
171 #  QT_VERSION_MINOR The minor version of Qt found.
172 #  QT_VERSION_PATCH The patch version of Qt found.
173 #
174 #  QT_EDITION               Set to the edition of Qt (i.e. DesktopLight)
175 #  QT_EDITION_DESKTOPLIGHT  True if QT_EDITION == DesktopLight
176 #  QT_QTCORE_FOUND          True if QtCore was found.
177 #  QT_QTGUI_FOUND           True if QtGui was found.
178 #  QT_QT3SUPPORT_FOUND      True if Qt3Support was found.
179 #  QT_QTASSISTANT_FOUND     True if QtAssistant was found.
180 #  QT_QTASSISTANTCLIENT_FOUND  True if QtAssistantClient was found.
181 #  QT_QAXCONTAINER_FOUND    True if QAxContainer was found (Windows only).
182 #  QT_QAXSERVER_FOUND       True if QAxServer was found (Windows only).
183 #  QT_QTDBUS_FOUND          True if QtDBus was found.
184 #  QT_QTDESIGNER_FOUND      True if QtDesigner was found.
185 #  QT_QTDESIGNERCOMPONENTS  True if QtDesignerComponents was found.
186 #  QT_QTHELP_FOUND          True if QtHelp was found.
187 #  QT_QTMOTIF_FOUND         True if QtMotif was found.
188 #  QT_QTMULTIMEDIA_FOUND    True if QtMultimedia was found (since Qt 4.6.0).
189 #  QT_QTNETWORK_FOUND       True if QtNetwork was found.
190 #  QT_QTNSPLUGIN_FOUND      True if QtNsPlugin was found.
191 #  QT_QTOPENGL_FOUND        True if QtOpenGL was found.
192 #  QT_QTSQL_FOUND           True if QtSql was found.
193 #  QT_QTSVG_FOUND           True if QtSvg was found.
194 #  QT_QTSCRIPT_FOUND        True if QtScript was found.
195 #  QT_QTSCRIPTTOOLS_FOUND   True if QtScriptTools was found.
196 #  QT_QTTEST_FOUND          True if QtTest was found.
197 #  QT_QTUITOOLS_FOUND       True if QtUiTools was found.
198 #  QT_QTWEBKIT_FOUND        True if QtWebKit was found.
199 #  QT_QTXML_FOUND           True if QtXml was found.
200 #  QT_QTXMLPATTERNS_FOUND   True if QtXmlPatterns was found.
201 #  QT_PHONON_FOUND          True if phonon was found.
202 #  QT_QTDECLARATIVE_FOUND   True if QtDeclarative was found.
203 #
204 #  QT_MAC_USE_COCOA    For Mac OS X, its whether Cocoa or Carbon is used.
205 #                      In general, this should not be used, but its useful
206 #                      when having platform specific code.
207 #
208 #  QT_DEFINITIONS   Definitions to use when compiling code that uses Qt.
209 #                   You do not need to use this if you include QT_USE_FILE.
210 #                   The QT_USE_FILE will also define QT_DEBUG and QT_NO_DEBUG
211 #                   to fit your current build type.  Those are not contained
212 #                   in QT_DEFINITIONS.
213 #                  
214 #  QT_INCLUDES      List of paths to all include directories of 
215 #                   Qt4 QT_INCLUDE_DIR and QT_QTCORE_INCLUDE_DIR are
216 #                   always in this variable even if NOTFOUND,
217 #                   all other INCLUDE_DIRS are
218 #                   only added if they are found.
219 #                   You do not need to use this if you include QT_USE_FILE.
220 #   
221 #
222 #  Include directories for the Qt modules are listed here.
223 #  You do not need to use these variables if you include QT_USE_FILE.
224 #
225 #  QT_INCLUDE_DIR              Path to "include" of Qt4
226 #  QT_QT_INCLUDE_DIR           Path to "include/Qt" 
227 #  QT_QT3SUPPORT_INCLUDE_DIR   Path to "include/Qt3Support" 
228 #  QT_QTASSISTANT_INCLUDE_DIR  Path to "include/QtAssistant" 
229 #  QT_QTASSISTANTCLIENT_INCLUDE_DIR       Path to "include/QtAssistant"
230 #  QT_QAXCONTAINER_INCLUDE_DIR Path to "include/ActiveQt" (Windows only)
231 #  QT_QAXSERVER_INCLUDE_DIR    Path to "include/ActiveQt" (Windows only)
232 #  QT_QTCORE_INCLUDE_DIR       Path to "include/QtCore"         
233 #  QT_QTDBUS_INCLUDE_DIR       Path to "include/QtDBus" 
234 #  QT_QTDESIGNER_INCLUDE_DIR   Path to "include/QtDesigner" 
235 #  QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR   Path to "include/QtDesigner"
236 #  QT_QTGUI_INCLUDE_DIR        Path to "include/QtGui" 
237 #  QT_QTHELP_INCLUDE_DIR       Path to "include/QtHelp"
238 #  QT_QTMOTIF_INCLUDE_DIR      Path to "include/QtMotif" 
239 #  QT_QTMULTIMEDIA_INCLUDE_DIR Path to "include/QtMultimedia" 
240 #  QT_QTNETWORK_INCLUDE_DIR    Path to "include/QtNetwork" 
241 #  QT_QTNSPLUGIN_INCLUDE_DIR   Path to "include/QtNsPlugin" 
242 #  QT_QTOPENGL_INCLUDE_DIR     Path to "include/QtOpenGL" 
243 #  QT_QTSCRIPT_INCLUDE_DIR     Path to "include/QtScript"
244 #  QT_QTSQL_INCLUDE_DIR        Path to "include/QtSql" 
245 #  QT_QTSVG_INCLUDE_DIR        Path to "include/QtSvg"
246 #  QT_QTTEST_INCLUDE_DIR       Path to "include/QtTest"
247 #  QT_QTWEBKIT_INCLUDE_DIR     Path to "include/QtWebKit"
248 #  QT_QTXML_INCLUDE_DIR        Path to "include/QtXml" 
249 #  QT_QTXMLPATTERNS_INCLUDE_DIR  Path to "include/QtXmlPatterns"
250 #  QT_PHONON_INCLUDE_DIR       Path to "include/phonon"
251 #  QT_QTSCRIPTTOOLS_INCLUDE_DIR       Path to "include/QtScriptTools"
252 #  QT_QTDECLARATIVE_INCLUDE_DIR       Path to "include/QtDeclarative"
253 #
254 #  QT_BINARY_DIR               Path to "bin" of Qt4
255 #  QT_LIBRARY_DIR              Path to "lib" of Qt4
256 #  QT_PLUGINS_DIR              Path to "plugins" for Qt4
257 #  QT_TRANSLATIONS_DIR         Path to "translations" of Qt4
258 #  QT_DOC_DIR                  Path to "doc" of Qt4
259 #  QT_MKSPECS_DIR              Path to "mkspecs" of Qt4
260 #
261 #
262 # For every library of Qt, a QT_QTFOO_LIBRARY variable is defined, with the full path to the library.
263 #
264 # So there are the following variables:
265 # The Qt3Support library:     QT_QT3SUPPORT_LIBRARY
266 #
267 # The QtAssistant library:    QT_QTASSISTANT_LIBRARY
268 #
269 # The QtAssistantClient library:  QT_QTASSISTANTCLIENT_LIBRARY
270 #
271 # The QAxServer library:      QT_QAXSERVER_LIBRARY
272 #
273 # The QAxContainer library:   QT_QAXCONTAINER_LIBRARY
274 #
275 # The QtCore library:         QT_QTCORE_LIBRARY
276 #
277 # The QtDBus library:         QT_QTDBUS_LIBRARY
278 #
279 # The QtDesigner library:     QT_QTDESIGNER_LIBRARY
280 #
281 # The QtDesignerComponents library:     QT_QTDESIGNERCOMPONENTS_LIBRARY
282 #
283 # The QtGui library:          QT_QTGUI_LIBRARY
284 #
285 # The QtHelp library:         QT_QTHELP_LIBRARY
286 #
287 # The QtMotif library:        QT_QTMOTIF_LIBRARY
288 #
289 # The QtMultimedia library:   QT_QTMULTIMEDIA_LIBRARY
290 #
291 # The QtNetwork library:      QT_QTNETWORK_LIBRARY
292 #
293 # The QtNsPLugin library:     QT_QTNSPLUGIN_LIBRARY
294 #
295 # The QtOpenGL library:       QT_QTOPENGL_LIBRARY
296 #
297 # The QtScript library:       QT_QTSCRIPT_LIBRARY
298 #
299 # The QtScriptTools library:      QT_QTSCRIPTTOOLS_LIBRARY
300 #
301 # The QtSql library:          QT_QTSQL_LIBRARY
302 #
303 # The QtSvg library:          QT_QTSVG_LIBRARY
304 #
305 # The QtTest library:         QT_QTTEST_LIBRARY
306 #
307 # The QtUiTools library:      QT_QTUITOOLS_LIBRARY
308 #
309 # The QtWebKit library:       QT_QTWEBKIT_LIBRARY
310 #
311 # The QtXml library:          QT_QTXML_LIBRARY
312 #
313 # The QtXmlPatterns library:  QT_QTXMLPATTERNS_LIBRARY
314 #
315 # The qtmain library for Windows QT_QTMAIN_LIBRARY
316 #
317 # The Phonon library:             QT_PHONON_LIBRARY
318 #  
319 # The QtDeclarative library:             QT_QTDECLARATIVE_LIBRARY
320 #
321 # also defined, but NOT for general use are
322 #  QT_MOC_EXECUTABLE                   Where to find the moc tool.
323 #  QT_UIC_EXECUTABLE                   Where to find the uic tool.
324 #  QT_UIC3_EXECUTABLE                  Where to find the uic3 tool.
325 #  QT_RCC_EXECUTABLE                   Where to find the rcc tool
326 #  QT_DBUSCPP2XML_EXECUTABLE           Where to find the qdbuscpp2xml tool.
327 #  QT_DBUSXML2CPP_EXECUTABLE           Where to find the qdbusxml2cpp tool.
328 #  QT_LUPDATE_EXECUTABLE               Where to find the lupdate tool.
329 #  QT_LRELEASE_EXECUTABLE              Where to find the lrelease tool.
330 #  QT_LCONVERT_EXECUTABLE              Where to find the lconvert tool.
331 #  QT_QCOLLECTIONGENERATOR_EXECUTABLE  Where to find the qcollectiongenerator tool.
332 #  QT_DESIGNER_EXECUTABLE              Where to find the Qt designer tool.
333 #  QT_LINGUIST_EXECUTABLE              Where to find the Qt linguist tool.
334 #  
335 #
336 # These are around for backwards compatibility 
337 # they will be set
338 #  QT_WRAP_CPP  Set true if QT_MOC_EXECUTABLE is found
339 #  QT_WRAP_UI   Set true if QT_UIC_EXECUTABLE is found
340 #  
341 # These variables do _NOT_ have any effect anymore (compared to FindQt.cmake)
342 #  QT_MT_REQUIRED         Qt4 is now always multithreaded
343 #  
344 # These variables are set to "" Because Qt structure changed 
345 # (They make no sense in Qt4)
346 #  QT_QT_LIBRARY        Qt-Library is now split
347
348 # Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
349 # See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
350
351 # Use FIND_PACKAGE( Qt4 COMPONENTS ... ) to enable modules
352 IF( Qt4_FIND_COMPONENTS )
353   FOREACH( component ${Qt4_FIND_COMPONENTS} )
354     STRING( TOUPPER ${component} _COMPONENT )
355     SET( QT_USE_${_COMPONENT} 1 )
356   ENDFOREACH( component )
357   
358   # To make sure we don't use QtCore or QtGui when not in COMPONENTS
359   IF(NOT QT_USE_QTCORE)
360     SET( QT_DONT_USE_QTCORE 1 )
361   ENDIF(NOT QT_USE_QTCORE)
362   
363   IF(NOT QT_USE_QTGUI)
364     SET( QT_DONT_USE_QTGUI 1 )
365   ENDIF(NOT QT_USE_QTGUI)
366
367 ENDIF( Qt4_FIND_COMPONENTS )
368
369 # If Qt3 has already been found, fail.
370 IF(QT_QT_LIBRARY)
371   IF(Qt4_FIND_REQUIRED)
372     MESSAGE( FATAL_ERROR "Qt3 and Qt4 cannot be used together in one project.  If switching to Qt4, the CMakeCache.txt needs to be cleaned.")
373   ELSE(Qt4_FIND_REQUIRED)
374     IF(NOT Qt4_FIND_QUIETLY)
375       MESSAGE( STATUS    "Qt3 and Qt4 cannot be used together in one project.  If switching to Qt4, the CMakeCache.txt needs to be cleaned.")
376     ENDIF(NOT Qt4_FIND_QUIETLY)
377     RETURN()
378   ENDIF(Qt4_FIND_REQUIRED)
379 ENDIF(QT_QT_LIBRARY)
380
381
382 IF (QT4_QMAKE_FOUND  AND  Qt4::QtCore)
383    # Check already done in this cmake run, nothing more to do
384    RETURN()
385 ENDIF (QT4_QMAKE_FOUND  AND  Qt4::QtCore)
386
387 # check that QT_NO_DEBUG is defined for release configurations
388 MACRO(QT_CHECK_FLAG_EXISTS FLAG VAR DOC)
389   IF(NOT ${VAR} MATCHES "${FLAG}")
390     SET(${VAR} "${${VAR}} ${FLAG}" 
391       CACHE STRING "Flags used by the compiler during ${DOC} builds." FORCE)
392   ENDIF(NOT ${VAR} MATCHES "${FLAG}")
393 ENDMACRO(QT_CHECK_FLAG_EXISTS FLAG VAR)
394
395 QT_CHECK_FLAG_EXISTS(-DQT_NO_DEBUG CMAKE_CXX_FLAGS_RELWITHDEBINFO "Release with Debug Info")
396 QT_CHECK_FLAG_EXISTS(-DQT_NO_DEBUG CMAKE_CXX_FLAGS_RELEASE "release")
397 QT_CHECK_FLAG_EXISTS(-DQT_NO_DEBUG CMAKE_CXX_FLAGS_MINSIZEREL "release minsize")
398
399 INCLUDE(MacroPushRequiredVars)
400 INCLUDE(CheckSymbolExists)
401 INCLUDE(MacroAddFileDependencies)
402
403 SET(QT_USE_FILE ${CMAKE_ROOT}/Modules/UseQt4.cmake)
404
405 SET( QT_DEFINITIONS "")
406
407 SET(QT4_INSTALLED_VERSION_TOO_OLD FALSE)
408
409 #  macro for asking qmake to process pro files
410 MACRO(QT_QUERY_QMAKE outvar invar)
411   IF(QT_QMAKE_EXECUTABLE)
412     FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmpQmake/tmp.pro
413          "message(CMAKE_MESSAGE<$$${invar}>)")
414
415     # Invoke qmake with the tmp.pro program to get the desired
416     # information.  Use the same variable for both stdout and stderr
417     # to make sure we get the output on all platforms.
418     EXECUTE_PROCESS(COMMAND ${QT_QMAKE_EXECUTABLE}
419       WORKING_DIRECTORY  
420       ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmpQmake
421       OUTPUT_VARIABLE _qmake_query_output
422       RESULT_VARIABLE _qmake_result
423       ERROR_VARIABLE _qmake_query_output )
424
425     FILE(REMOVE_RECURSE 
426          "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmpQmake")
427
428     IF(_qmake_result)
429       MESSAGE(WARNING " querying qmake for ${invar}.  qmake reported:\n${_qmake_query_output}")
430     ELSE(_qmake_result)
431       STRING(REGEX REPLACE ".*CMAKE_MESSAGE<([^>]*).*" "\\1" ${outvar} "${_qmake_query_output}")
432     ENDIF(_qmake_result)
433
434   ENDIF(QT_QMAKE_EXECUTABLE)
435 ENDMACRO(QT_QUERY_QMAKE)
436
437 GET_FILENAME_COMPONENT(qt_install_version "[HKEY_CURRENT_USER\\Software\\trolltech\\Versions;DefaultQtVersion]" NAME)
438 # check for qmake
439 # Debian uses qmake-qt4
440 # macports' Qt uses qmake-mac
441 FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake qmake4 qmake-qt4 qmake-mac PATHS
442   "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/bin"
443   "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/bin"
444   "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\${qt_install_version};InstallDir]/bin"
445   $ENV{QTDIR}/bin
446   DOC "The qmake executable for the Qt installation to use"
447 )
448
449 IF (QT_QMAKE_EXECUTABLE)
450
451   IF(QT_QMAKE_EXECUTABLE_LAST)
452     STRING(COMPARE NOTEQUAL "${QT_QMAKE_EXECUTABLE_LAST}" "${QT_QMAKE_EXECUTABLE}" QT_QMAKE_CHANGED)
453   ENDIF(QT_QMAKE_EXECUTABLE_LAST)
454
455   SET(QT_QMAKE_EXECUTABLE_LAST "${QT_QMAKE_EXECUTABLE}" CACHE INTERNAL "" FORCE)
456
457   SET(QT4_QMAKE_FOUND FALSE)
458   
459   EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} ARGS "-query QT_VERSION" OUTPUT_VARIABLE QTVERSION)
460
461   # check for qt3 qmake and then try and find qmake4 or qmake-qt4 in the path
462   IF("${QTVERSION}" MATCHES "Unknown")
463     SET(QT_QMAKE_EXECUTABLE NOTFOUND CACHE FILEPATH "" FORCE)
464     FIND_PROGRAM(QT_QMAKE_EXECUTABLE NAMES qmake4 qmake-qt4 PATHS
465       "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\4.0.0;InstallDir]/bin"
466       "[HKEY_CURRENT_USER\\Software\\Trolltech\\Versions\\4.0.0;InstallDir]/bin"
467       $ENV{QTDIR}/bin
468       DOC "The qmake executable for the Qt installation to use"
469       )
470     IF(QT_QMAKE_EXECUTABLE)
471       EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE} 
472         ARGS "-query QT_VERSION" OUTPUT_VARIABLE QTVERSION)
473     ENDIF(QT_QMAKE_EXECUTABLE)
474   ENDIF("${QTVERSION}" MATCHES "Unknown")
475
476   # check that we found the Qt4 qmake, Qt3 qmake output won't match here
477   STRING(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" qt_version_tmp "${QTVERSION}")
478   IF (qt_version_tmp)
479
480     # we need at least version 4.0.0
481     IF (NOT QT_MIN_VERSION)
482       SET(QT_MIN_VERSION "4.0.0")
483     ENDIF (NOT QT_MIN_VERSION)
484
485     #now parse the parts of the user given version string into variables
486     STRING(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" req_qt_major_vers "${QT_MIN_VERSION}")
487     IF (NOT req_qt_major_vers)
488       MESSAGE( FATAL_ERROR "Invalid Qt version string given: \"${QT_MIN_VERSION}\", expected e.g. \"4.0.1\"")
489     ENDIF (NOT req_qt_major_vers)
490
491     # now parse the parts of the user given version string into variables
492     STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" req_qt_major_vers "${QT_MIN_VERSION}")
493     STRING(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" req_qt_minor_vers "${QT_MIN_VERSION}")
494     STRING(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" req_qt_patch_vers "${QT_MIN_VERSION}")
495
496     # Suppport finding at least a particular version, for instance FIND_PACKAGE( Qt4 4.4.3 )
497     # This implementation is a hack to avoid duplicating code and make sure we stay
498     # source-compatible with CMake 2.6.x
499     IF( Qt4_FIND_VERSION )
500       SET( QT_MIN_VERSION ${Qt4_FIND_VERSION} )
501       SET( req_qt_major_vers ${Qt4_FIND_VERSION_MAJOR} )
502       SET( req_qt_minor_vers ${Qt4_FIND_VERSION_MINOR} )
503       SET( req_qt_patch_vers ${Qt4_FIND_VERSION_PATCH} )
504     ENDIF( Qt4_FIND_VERSION )
505
506     IF (NOT req_qt_major_vers EQUAL 4)
507       MESSAGE( FATAL_ERROR "Invalid Qt version string given: \"${QT_MIN_VERSION}\", major version 4 is required, e.g. \"4.0.1\"")
508     ENDIF (NOT req_qt_major_vers EQUAL 4)
509
510     # and now the version string given by qmake
511     STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" QT_VERSION_MAJOR "${QTVERSION}")
512     STRING(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+.*" "\\1" QT_VERSION_MINOR "${QTVERSION}")
513     STRING(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" QT_VERSION_PATCH "${QTVERSION}")
514
515     # compute an overall version number which can be compared at once
516     MATH(EXPR req_vers "${req_qt_major_vers}*10000 + ${req_qt_minor_vers}*100 + ${req_qt_patch_vers}")
517     MATH(EXPR found_vers "${QT_VERSION_MAJOR}*10000 + ${QT_VERSION_MINOR}*100 + ${QT_VERSION_PATCH}")
518
519     # Support finding *exactly* a particular version, for instance FIND_PACKAGE( Qt4 4.4.3 EXACT )
520     IF( Qt4_FIND_VERSION_EXACT )
521       IF(found_vers EQUAL req_vers)
522         SET( QT4_QMAKE_FOUND TRUE )
523       ELSE(found_vers EQUAL req_vers)
524         SET( QT4_QMAKE_FOUND FALSE )
525         IF (found_vers LESS req_vers)
526           SET(QT4_INSTALLED_VERSION_TOO_OLD TRUE)
527         ELSE (found_vers LESS req_vers)
528           SET(QT4_INSTALLED_VERSION_TOO_NEW TRUE)
529         ENDIF (found_vers LESS req_vers)
530       ENDIF(found_vers EQUAL req_vers)
531     ELSE( Qt4_FIND_VERSION_EXACT )
532       IF (found_vers LESS req_vers)
533         SET(QT4_QMAKE_FOUND FALSE)
534         SET(QT4_INSTALLED_VERSION_TOO_OLD TRUE)
535       ELSE (found_vers LESS req_vers)
536         SET(QT4_QMAKE_FOUND TRUE)
537       ENDIF (found_vers LESS req_vers)
538     ENDIF( Qt4_FIND_VERSION_EXACT )
539   ENDIF (qt_version_tmp)
540
541 ENDIF (QT_QMAKE_EXECUTABLE)
542
543 IF (QT4_QMAKE_FOUND)
544
545   if (WIN32)
546     # get qt install dir 
547     get_filename_component(_DIR ${QT_QMAKE_EXECUTABLE} PATH )
548     get_filename_component(QT_INSTALL_DIR ${_DIR} PATH )
549   endif (WIN32)
550
551   # ask qmake for the library dir
552   # Set QT_LIBRARY_DIR
553   IF (NOT QT_LIBRARY_DIR OR QT_QMAKE_CHANGED)
554     EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE}
555       ARGS "-query QT_INSTALL_LIBS"
556       OUTPUT_VARIABLE QT_LIBRARY_DIR_TMP )
557     # make sure we have / and not \ as qmake gives on windows
558     FILE(TO_CMAKE_PATH "${QT_LIBRARY_DIR_TMP}" QT_LIBRARY_DIR_TMP)
559     IF(EXISTS "${QT_LIBRARY_DIR_TMP}")
560       SET(QT_LIBRARY_DIR ${QT_LIBRARY_DIR_TMP} CACHE PATH "Qt library dir" FORCE)
561     ELSE(EXISTS "${QT_LIBRARY_DIR_TMP}")
562       MESSAGE("Warning: QT_QMAKE_EXECUTABLE reported QT_INSTALL_LIBS as ${QT_LIBRARY_DIR_TMP}")
563       MESSAGE("Warning: ${QT_LIBRARY_DIR_TMP} does NOT exist, Qt must NOT be installed correctly.")
564     ENDIF(EXISTS "${QT_LIBRARY_DIR_TMP}")
565   ENDIF(NOT QT_LIBRARY_DIR OR QT_QMAKE_CHANGED)
566   
567   IF (APPLE)
568     IF (EXISTS ${QT_LIBRARY_DIR}/QtCore.framework)
569       SET(QT_USE_FRAMEWORKS ON
570         CACHE BOOL "Set to ON if Qt build uses frameworks." FORCE)
571     ELSE (EXISTS ${QT_LIBRARY_DIR}/QtCore.framework)
572       SET(QT_USE_FRAMEWORKS OFF
573         CACHE BOOL "Set to ON if Qt build uses frameworks." FORCE)
574     ENDIF (EXISTS ${QT_LIBRARY_DIR}/QtCore.framework)
575     
576     MARK_AS_ADVANCED(QT_USE_FRAMEWORKS)
577   ENDIF (APPLE)
578   
579   # ask qmake for the binary dir
580   IF (QT_LIBRARY_DIR AND NOT QT_BINARY_DIR  OR  QT_QMAKE_CHANGED)
581      EXEC_PROGRAM(${QT_QMAKE_EXECUTABLE}
582        ARGS "-query QT_INSTALL_BINS"
583        OUTPUT_VARIABLE qt_bins )
584      # make sure we have / and not \ as qmake gives on windows
585      FILE(TO_CMAKE_PATH "${qt_bins}" qt_bins)
586      SET(QT_BINARY_DIR ${qt_bins} CACHE INTERNAL "" FORCE)
587   ENDIF (QT_LIBRARY_DIR AND NOT QT_BINARY_DIR  OR  QT_QMAKE_CHANGED)
588
589   # ask qmake for the include dir
590   IF (QT_LIBRARY_DIR AND NOT QT_HEADERS_DIR  OR  QT_QMAKE_CHANGED)
591       EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE}
592         ARGS "-query QT_INSTALL_HEADERS" 
593         OUTPUT_VARIABLE qt_headers ) 
594       # make sure we have / and not \ as qmake gives on windows
595       FILE(TO_CMAKE_PATH "${qt_headers}" qt_headers)
596       SET(QT_HEADERS_DIR ${qt_headers} CACHE INTERNAL "" FORCE)
597   ENDIF (QT_LIBRARY_DIR AND NOT QT_HEADERS_DIR  OR  QT_QMAKE_CHANGED)
598
599
600   # ask qmake for the documentation directory
601   IF (QT_LIBRARY_DIR AND NOT QT_DOC_DIR  OR  QT_QMAKE_CHANGED)
602     EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE}
603       ARGS "-query QT_INSTALL_DOCS"
604       OUTPUT_VARIABLE qt_doc_dir )
605     # make sure we have / and not \ as qmake gives on windows
606     FILE(TO_CMAKE_PATH "${qt_doc_dir}" qt_doc_dir)
607     SET(QT_DOC_DIR ${qt_doc_dir} CACHE PATH "The location of the Qt docs" FORCE)
608   ENDIF (QT_LIBRARY_DIR AND NOT QT_DOC_DIR  OR  QT_QMAKE_CHANGED)
609
610   # ask qmake for the mkspecs directory
611   IF (QT_LIBRARY_DIR AND NOT QT_MKSPECS_DIR  OR  QT_QMAKE_CHANGED)
612     EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE}
613       ARGS "-query QMAKE_MKSPECS"
614       OUTPUT_VARIABLE qt_mkspecs_dirs )
615     # do not replace : on windows as it might be a drive letter
616     # and windows should already use ; as a separator
617     IF(UNIX)
618       STRING(REPLACE ":" ";" qt_mkspecs_dirs "${qt_mkspecs_dirs}")
619     ENDIF(UNIX)
620     SET(QT_MKSPECS_DIR NOTFOUND)
621     FIND_PATH(QT_MKSPECS_DIR qconfig.pri PATHS ${qt_mkspecs_dirs}
622       DOC "The location of the Qt mkspecs containing qconfig.pri"
623       NO_DEFAULT_PATH )
624   ENDIF (QT_LIBRARY_DIR AND NOT QT_MKSPECS_DIR  OR  QT_QMAKE_CHANGED)
625
626   # ask qmake for the plugins directory
627   IF (QT_LIBRARY_DIR AND NOT QT_PLUGINS_DIR  OR  QT_QMAKE_CHANGED)
628     EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE}
629       ARGS "-query QT_INSTALL_PLUGINS"
630       OUTPUT_VARIABLE qt_plugins_dir )
631     # make sure we have / and not \ as qmake gives on windows
632     FILE(TO_CMAKE_PATH "${qt_plugins_dir}" qt_plugins_dir)
633     SET(QT_PLUGINS_DIR ${qt_plugins_dir} CACHE PATH "The location of the Qt plugins" FORCE)
634   ENDIF (QT_LIBRARY_DIR AND NOT QT_PLUGINS_DIR  OR  QT_QMAKE_CHANGED)
635
636   # ask qmake for the translations directory
637   IF (QT_LIBRARY_DIR AND NOT QT_TRANSLATIONS_DIR  OR  QT_QMAKE_CHANGED)
638     EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE}
639       ARGS "-query QT_INSTALL_TRANSLATIONS"
640       OUTPUT_VARIABLE qt_translations_dir )
641     # make sure we have / and not \ as qmake gives on windows
642     FILE(TO_CMAKE_PATH "${qt_translations_dir}" qt_translations_dir)
643     SET(QT_TRANSLATIONS_DIR ${qt_translations_dir} CACHE PATH "The location of the Qt translations" FORCE)
644   ENDIF (QT_LIBRARY_DIR AND NOT QT_TRANSLATIONS_DIR  OR  QT_QMAKE_CHANGED)
645
646   # Make variables changeble to the advanced user
647   MARK_AS_ADVANCED( QT_LIBRARY_DIR QT_DOC_DIR QT_MKSPECS_DIR
648                     QT_PLUGINS_DIR QT_TRANSLATIONS_DIR)
649
650
651   #############################################
652   #
653   # Find out what window system we're using
654   #
655   #############################################
656   # Save required includes and required_flags variables
657   MACRO_PUSH_REQUIRED_VARS()
658   # Add QT_INCLUDE_DIR to CMAKE_REQUIRED_INCLUDES
659   SET(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${QT_HEADERS_DIR}")
660   # On Mac OS X when Qt has framework support, also add the framework path
661   IF( QT_USE_FRAMEWORKS )
662     SET(CMAKE_REQUIRED_FLAGS "-F${QT_LIBRARY_DIR} ")
663   ENDIF( QT_USE_FRAMEWORKS )
664   # Check for Window system symbols (note: only one should end up being set)
665   CHECK_SYMBOL_EXISTS(Q_WS_X11 "QtCore/qglobal.h" Q_WS_X11)
666   CHECK_SYMBOL_EXISTS(Q_WS_WIN "QtCore/qglobal.h" Q_WS_WIN)
667   CHECK_SYMBOL_EXISTS(Q_WS_QWS "QtCore/qglobal.h" Q_WS_QWS)
668   CHECK_SYMBOL_EXISTS(Q_WS_MAC "QtCore/qglobal.h" Q_WS_MAC)
669   IF(Q_WS_MAC)
670     IF(QT_QMAKE_CHANGED)
671       UNSET(QT_MAC_USE_COCOA CACHE)
672     ENDIF(QT_QMAKE_CHANGED)
673     CHECK_SYMBOL_EXISTS(QT_MAC_USE_COCOA "QtCore/qconfig.h" QT_MAC_USE_COCOA)
674   ENDIF(Q_WS_MAC)
675
676   IF (QT_QTCOPY_REQUIRED)
677      CHECK_SYMBOL_EXISTS(QT_IS_QTCOPY "QtCore/qglobal.h" QT_KDE_QT_COPY)
678      IF (NOT QT_IS_QTCOPY)
679         MESSAGE(FATAL_ERROR "qt-copy is required, but hasn't been found")
680      ENDIF (NOT QT_IS_QTCOPY)
681   ENDIF (QT_QTCOPY_REQUIRED)
682
683   # Restore CMAKE_REQUIRED_INCLUDES+CMAKE_REQUIRED_FLAGS variables
684   MACRO_POP_REQUIRED_VARS()
685   #
686   #############################################
687
688
689
690   ########################################
691   #
692   #       Setting the INCLUDE-Variables
693   #
694   ########################################
695
696   SET(QT_MODULES QtCore QtGui Qt3Support QtSvg QtScript QtTest QtUiTools 
697                  QtHelp QtWebKit QtXmlPatterns QtNetwork QtMultimedia
698                  QtNsPlugin QtOpenGL QtSql QtXml QtDesigner QtDBus QtScriptTools
699                  QtDeclarative)
700   
701   IF(Q_WS_X11)
702     SET(QT_MODULES ${QT_MODULES} QtMotif)
703   ENDIF(Q_WS_X11)
704
705   IF(QT_QMAKE_CHANGED)
706     FOREACH(QT_MODULE ${QT_MODULES})
707       STRING(TOUPPER ${QT_MODULE} _upper_qt_module)
708       SET(QT_${_upper_qt_module}_INCLUDE_DIR NOTFOUND)
709       SET(QT_${_upper_qt_module}_LIBRARY_RELEASE NOTFOUND)
710       SET(QT_${_upper_qt_module}_LIBRARY_DEBUG NOTFOUND)
711     ENDFOREACH(QT_MODULE)
712     SET(QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR NOTFOUND)
713     SET(QT_QTDESIGNERCOMPONENTS_LIBRARY_RELEASE NOTFOUND)
714     SET(QT_QTDESIGNERCOMPONENTS_LIBRARY_DEBUG NOTFOUND)
715     SET(QT_QTASSISTANTCLIENT_INCLUDE_DIR NOTFOUND)
716     SET(QT_QTASSISTANTCLIENT_LIBRARY_RELEASE NOTFOUND)
717     SET(QT_QTASSISTANTCLIENT_LIBRARY_DEBUG NOTFOUND)
718     SET(QT_QTASSISTANT_INCLUDE_DIR NOTFOUND)
719     SET(QT_QTASSISTANT_LIBRARY_RELEASE NOTFOUND)
720     SET(QT_QTASSISTANT_LIBRARY_DEBUG NOTFOUND)
721     SET(QT_QTCLUCENE_LIBRARY_RELEASE NOTFOUND)
722     SET(QT_QTCLUCENE_LIBRARY_DEBUG NOTFOUND)
723     SET(QT_QAXCONTAINER_INCLUDE_DIR NOTFOUND)
724     SET(QT_QAXCONTAINER_LIBRARY_RELEASE NOTFOUND)
725     SET(QT_QAXCONTAINER_LIBRARY_DEBUG NOTFOUND)
726     SET(QT_QAXSERVER_INCLUDE_DIR NOTFOUND)
727     SET(QT_QAXSERVER_LIBRARY_RELEASE NOTFOUND)
728     SET(QT_QAXSERVER_LIBRARY_DEBUG NOTFOUND)
729     IF(WIN32)
730       SET(QT_QTMAIN_LIBRARY_DEBUG NOTFOUND)
731       SET(QT_QTMAIN_LIBRARY_RELEASE NOTFOUND)
732     ENDIF(WIN32)
733     SET(QT_PHONON_INCLUDE_DIR NOTFOUND)
734   ENDIF(QT_QMAKE_CHANGED)
735
736   FOREACH(QT_MODULE ${QT_MODULES})
737     STRING(TOUPPER ${QT_MODULE} _upper_qt_module)
738     FIND_PATH(QT_${_upper_qt_module}_INCLUDE_DIR ${QT_MODULE}
739               PATHS
740               ${QT_HEADERS_DIR}/${QT_MODULE}
741               ${QT_LIBRARY_DIR}/${QT_MODULE}.framework/Headers
742               NO_DEFAULT_PATH
743       )
744   ENDFOREACH(QT_MODULE)
745
746   IF(WIN32)
747     SET(QT_MODULES ${QT_MODULES} QAxContainer QAxServer)
748     # Set QT_AXCONTAINER_INCLUDE_DIR and QT_AXSERVER_INCLUDE_DIR
749     FIND_PATH(QT_QAXCONTAINER_INCLUDE_DIR ActiveQt
750       PATHS
751       ${QT_HEADERS_DIR}/ActiveQt
752       NO_DEFAULT_PATH
753       )
754     FIND_PATH(QT_QAXSERVER_INCLUDE_DIR ActiveQt
755       PATHS
756       ${QT_HEADERS_DIR}/ActiveQt
757       NO_DEFAULT_PATH
758       )
759   ENDIF(WIN32)
760
761   # Set QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR
762   FIND_PATH(QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR QDesignerComponents
763     PATHS
764     ${QT_HEADERS_DIR}/QtDesigner
765     ${QT_LIBRARY_DIR}/QtDesigner.framework/Headers
766     NO_DEFAULT_PATH
767     )
768   
769   # Set QT_QTASSISTANT_INCLUDE_DIR
770   FIND_PATH(QT_QTASSISTANT_INCLUDE_DIR QtAssistant
771     PATHS
772     ${QT_HEADERS_DIR}/QtAssistant
773     ${QT_LIBRARY_DIR}/QtAssistant.framework/Headers
774     NO_DEFAULT_PATH
775     )
776   
777   # Set QT_QTASSISTANTCLIENT_INCLUDE_DIR
778   FIND_PATH(QT_QTASSISTANTCLIENT_INCLUDE_DIR QAssistantClient
779     PATHS
780     ${QT_HEADERS_DIR}/QtAssistant
781     ${QT_LIBRARY_DIR}/QtAssistant.framework/Headers
782     NO_DEFAULT_PATH
783     )
784
785   # Set QT_QT_INCLUDE_DIR
786   FIND_PATH(QT_QT_INCLUDE_DIR qglobal.h
787     PATHS
788     ${QT_HEADERS_DIR}/Qt
789     ${QT_LIBRARY_DIR}/QtCore.framework/Headers
790     NO_DEFAULT_PATH
791     )
792
793   # Set QT_PHONON_INCLUDE_DIR
794   # Qt >= 4.5.3 (or kde-qt-4.5.2 which has the fix too) : Phonon/ClassName is inside include/phonon
795   # With previous versions of Qt, this could not work; upgrade Qt or use a standalone phonon
796   FIND_PATH(QT_PHONON_INCLUDE_DIR Phonon
797     PATHS
798     ${QT_HEADERS_DIR}/phonon
799     NO_DEFAULT_PATH
800     )
801   SET(QT_MODULES ${QT_MODULES} phonon)
802
803   # Set QT_INCLUDE_DIR by removine "/QtCore" in the string ${QT_QTCORE_INCLUDE_DIR}
804   IF( QT_QTCORE_INCLUDE_DIR AND NOT QT_INCLUDE_DIR)
805     IF (QT_USE_FRAMEWORKS)
806       SET(QT_INCLUDE_DIR ${QT_HEADERS_DIR})
807     ELSE (QT_USE_FRAMEWORKS)
808       STRING( REGEX REPLACE "/QtCore$" "" qt4_include_dir ${QT_QTCORE_INCLUDE_DIR})
809       SET( QT_INCLUDE_DIR ${qt4_include_dir} CACHE PATH "")
810     ENDIF (QT_USE_FRAMEWORKS)
811   ENDIF( QT_QTCORE_INCLUDE_DIR AND NOT QT_INCLUDE_DIR)
812
813   IF( NOT QT_INCLUDE_DIR)
814     IF(Qt4_FIND_REQUIRED)
815       MESSAGE( FATAL_ERROR "Could NOT find QtCore header")
816     ENDIF(Qt4_FIND_REQUIRED)
817   ENDIF( NOT QT_INCLUDE_DIR)
818
819   # Make variables changeble to the advanced user
820   MARK_AS_ADVANCED( QT_INCLUDE_DIR QT_QT_INCLUDE_DIR)
821
822   # Set QT_INCLUDES
823   SET( QT_INCLUDES ${QT_QT_INCLUDE_DIR} ${QT_MKSPECS_DIR}/default ${QT_INCLUDE_DIR} )
824
825
826   #######################################
827   #
828   #       Qt configuration
829   #
830   #######################################
831   IF(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri")
832     FILE(READ ${QT_MKSPECS_DIR}/qconfig.pri _qconfig_FILE_contents)
833     STRING(REGEX MATCH "QT_CONFIG[^\n]+" QT_QCONFIG "${_qconfig_FILE_contents}")
834     STRING(REGEX MATCH "CONFIG[^\n]+" QT_CONFIG "${_qconfig_FILE_contents}")
835     STRING(REGEX MATCH "EDITION[^\n]+" QT_EDITION "${_qconfig_FILE_contents}")
836     STRING(REGEX MATCH "QT_LIBINFIX[^\n]+" _qconfig_qt_libinfix "${_qconfig_FILE_contents}")
837     STRING(REGEX REPLACE "QT_LIBINFIX *= *([^\n]*)" "\\1" QT_LIBINFIX "${_qconfig_qt_libinfix}")
838   ENDIF(EXISTS "${QT_MKSPECS_DIR}/qconfig.pri")
839   IF("${QT_EDITION}" MATCHES "DesktopLight")
840     SET(QT_EDITION_DESKTOPLIGHT 1)
841   ENDIF("${QT_EDITION}" MATCHES "DesktopLight")
842
843   ########################################
844   #
845   #       Setting the LIBRARY-Variables
846   #
847   ########################################
848
849   # find the libraries
850   FOREACH(QT_MODULE ${QT_MODULES})
851     STRING(TOUPPER ${QT_MODULE} _upper_qt_module)
852     FIND_LIBRARY(QT_${_upper_qt_module}_LIBRARY_RELEASE 
853                  NAMES ${QT_MODULE}${QT_LIBINFIX} ${QT_MODULE}${QT_LIBINFIX}4
854                  PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH
855         )
856     FIND_LIBRARY(QT_${_upper_qt_module}_LIBRARY_DEBUG 
857                  NAMES ${QT_MODULE}${QT_LIBINFIX}_debug ${QT_MODULE}${QT_LIBINFIX}d ${QT_MODULE}${QT_LIBINFIX}d4
858                  PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH
859         )
860   ENDFOREACH(QT_MODULE)
861
862   # QtUiTools not with other frameworks with binary installation (in /usr/lib)
863   IF(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTUITOOLS_LIBRARY_RELEASE)
864     FIND_LIBRARY(QT_QTUITOOLS_LIBRARY_RELEASE NAMES QtUiTools${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR})
865   ENDIF(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTUITOOLS_LIBRARY_RELEASE)
866
867   IF( NOT QT_QTCORE_LIBRARY_DEBUG AND NOT QT_QTCORE_LIBRARY_RELEASE )
868     
869     # try dropping a hint if trying to use Visual Studio with Qt built by mingw
870     IF(QT_LIBRARY_DIR AND MSVC)
871       IF(EXISTS ${QT_LIBRARY_DIR}/libqtmain.a)
872         MESSAGE( FATAL_ERROR "It appears you're trying to use Visual Studio with Qt built by mingw")
873       ENDIF(EXISTS ${QT_LIBRARY_DIR}/libqtmain.a)
874     ENDIF(QT_LIBRARY_DIR AND MSVC)
875
876     IF(Qt4_FIND_REQUIRED)
877       MESSAGE( FATAL_ERROR "Could NOT find QtCore. Check ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log for more details.")
878     ENDIF(Qt4_FIND_REQUIRED)
879   ENDIF( NOT QT_QTCORE_LIBRARY_DEBUG AND NOT QT_QTCORE_LIBRARY_RELEASE )
880
881   # Set QT_QTDESIGNERCOMPONENTS_LIBRARY
882   FIND_LIBRARY(QT_QTDESIGNERCOMPONENTS_LIBRARY_RELEASE NAMES QtDesignerComponents${QT_LIBINFIX} QtDesignerComponents${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
883   FIND_LIBRARY(QT_QTDESIGNERCOMPONENTS_LIBRARY_DEBUG   NAMES QtDesignerComponents${QT_LIBINFIX}_debug QtDesignerComponents${QT_LIBINFIX}d QtDesignerComponents${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
884
885   # Set QT_QTMAIN_LIBRARY
886   IF(WIN32)
887     FIND_LIBRARY(QT_QTMAIN_LIBRARY_RELEASE NAMES qtmain${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR}
888       NO_DEFAULT_PATH)
889     FIND_LIBRARY(QT_QTMAIN_LIBRARY_DEBUG NAMES qtmain${QT_LIBINFIX}d PATHS ${QT_LIBRARY_DIR}
890       NO_DEFAULT_PATH)
891   ENDIF(WIN32)
892   
893   # Set QT_QTASSISTANTCLIENT_LIBRARY
894   FIND_LIBRARY(QT_QTASSISTANTCLIENT_LIBRARY_RELEASE NAMES QtAssistantClient${QT_LIBINFIX} QtAssistantClient${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
895   FIND_LIBRARY(QT_QTASSISTANTCLIENT_LIBRARY_DEBUG   NAMES QtAssistantClient${QT_LIBINFIX}_debug QtAssistantClient${QT_LIBINFIX}d QtAssistantClient${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
896   
897   # Set QT_QTASSISTANT_LIBRARY
898   FIND_LIBRARY(QT_QTASSISTANT_LIBRARY_RELEASE NAMES QtAssistantClient${QT_LIBINFIX} QtAssistantClient${QT_LIBINFIX}4 QtAssistant${QT_LIBINFIX} QtAssistant${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
899   FIND_LIBRARY(QT_QTASSISTANT_LIBRARY_DEBUG   NAMES QtAssistantClient${QT_LIBINFIX}_debug QtAssistantClient${QT_LIBINFIX}d QtAssistantClient${QT_LIBINFIX}d4 QtAssistant${QT_LIBINFIX}_debug QtAssistant${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
900
901   # Set QT_QTHELP_LIBRARY
902   FIND_LIBRARY(QT_QTCLUCENE_LIBRARY_RELEASE NAMES QtCLucene${QT_LIBINFIX} QtCLucene${QT_LIBINFIX}4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
903   FIND_LIBRARY(QT_QTCLUCENE_LIBRARY_DEBUG   NAMES QtCLucene${QT_LIBINFIX}_debug QtCLucene${QT_LIBINFIX}d QtCLucene${QT_LIBINFIX}d4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
904   # QtCLucene not with other frameworks with binary installation (in /usr/lib)
905   IF(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTCLUCENE_LIBRARY_RELEASE)
906     FIND_LIBRARY(QT_QTCLUCENE_LIBRARY_RELEASE NAMES QtCLucene${QT_LIBINFIX} PATHS ${QT_LIBRARY_DIR})
907   ENDIF(Q_WS_MAC AND QT_QTCORE_LIBRARY_RELEASE AND NOT QT_QTCLUCENE_LIBRARY_RELEASE)
908
909   ############################################
910   #
911   # Check the existence of the libraries.
912   #
913   ############################################
914
915   # On OSX when Qt is found as framework, never use the imported targets for now, since 
916   # in this case the handling of the framework directory currently does not work correctly.
917   IF(QT_USE_FRAMEWORKS)
918     SET(QT_USE_IMPORTED_TARGETS FALSE)
919   ENDIF(QT_USE_FRAMEWORKS)
920
921
922   MACRO (_QT4_ADJUST_LIB_VARS _camelCaseBasename)
923
924     STRING(TOUPPER "${_camelCaseBasename}" basename)
925
926     # The name of the imported targets, i.e. the prefix "Qt4::" must not change,
927     # since it is stored in EXPORT-files as name of a required library. If the name would change
928     # here, this would lead to the imported Qt4-library targets not being resolved by cmake anymore.
929     IF (QT_${basename}_LIBRARY_RELEASE OR QT_${basename}_LIBRARY_DEBUG)
930
931       IF(NOT TARGET Qt4::${_camelCaseBasename})
932         ADD_LIBRARY(Qt4::${_camelCaseBasename} UNKNOWN IMPORTED )
933
934         IF (QT_${basename}_LIBRARY_RELEASE)
935           SET_PROPERTY(TARGET Qt4::${_camelCaseBasename} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
936           SET_PROPERTY(TARGET Qt4::${_camelCaseBasename}        PROPERTY IMPORTED_LOCATION_RELEASE "${QT_${basename}_LIBRARY_RELEASE}" )
937         ENDIF (QT_${basename}_LIBRARY_RELEASE)
938
939         IF (QT_${basename}_LIBRARY_DEBUG)
940           SET_PROPERTY(TARGET Qt4::${_camelCaseBasename} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
941           SET_PROPERTY(TARGET Qt4::${_camelCaseBasename}        PROPERTY IMPORTED_LOCATION_DEBUG "${QT_${basename}_LIBRARY_DEBUG}" )
942         ENDIF (QT_${basename}_LIBRARY_DEBUG)
943       ENDIF(NOT TARGET Qt4::${_camelCaseBasename})
944
945       # If QT_USE_IMPORTED_TARGETS is enabled, the QT_QTFOO_LIBRARY variables are set to point at these
946       # imported targets. This works better in general, and is also in almost all cases fully
947       # backward compatible. The only issue is when a project A which had this enabled then exports its 
948       # libraries via export or EXPORT_LIBRARY_DEPENDENCIES(). In this case the libraries from project
949       # A will depend on the imported Qt targets, and the names of these imported targets will be stored
950       # in the dependency files on disk. This means when a project B then uses project A, these imported
951       # targets must be created again, otherwise e.g. "Qt4__QtCore" will be interpreted as name of a 
952       # library file on disk, and not as a target, and linking will fail:
953       IF(QT_USE_IMPORTED_TARGETS)
954           SET(QT_${basename}_LIBRARY       Qt4::${_camelCaseBasename} )
955           SET(QT_${basename}_LIBRARIES     Qt4::${_camelCaseBasename} )
956       ELSE(QT_USE_IMPORTED_TARGETS)
957
958         # if the release- as well as the debug-version of the library have been found:
959         IF (QT_${basename}_LIBRARY_DEBUG AND QT_${basename}_LIBRARY_RELEASE)
960           # if the generator supports configuration types then set
961           # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
962           IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
963             SET(QT_${basename}_LIBRARY       optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG})
964           ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
965             # if there are no configuration types and CMAKE_BUILD_TYPE has no value
966             # then just use the release libraries
967             SET(QT_${basename}_LIBRARY       ${QT_${basename}_LIBRARY_RELEASE} )
968           ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
969           SET(QT_${basename}_LIBRARIES       optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG})
970         ENDIF (QT_${basename}_LIBRARY_DEBUG AND QT_${basename}_LIBRARY_RELEASE)
971
972         # if only the release version was found, set the debug variable also to the release version
973         IF (QT_${basename}_LIBRARY_RELEASE AND NOT QT_${basename}_LIBRARY_DEBUG)
974           SET(QT_${basename}_LIBRARY_DEBUG ${QT_${basename}_LIBRARY_RELEASE})
975           SET(QT_${basename}_LIBRARY       ${QT_${basename}_LIBRARY_RELEASE})
976           SET(QT_${basename}_LIBRARIES     ${QT_${basename}_LIBRARY_RELEASE})
977         ENDIF (QT_${basename}_LIBRARY_RELEASE AND NOT QT_${basename}_LIBRARY_DEBUG)
978
979         # if only the debug version was found, set the release variable also to the debug version
980         IF (QT_${basename}_LIBRARY_DEBUG AND NOT QT_${basename}_LIBRARY_RELEASE)
981           SET(QT_${basename}_LIBRARY_RELEASE ${QT_${basename}_LIBRARY_DEBUG})
982           SET(QT_${basename}_LIBRARY         ${QT_${basename}_LIBRARY_DEBUG})
983           SET(QT_${basename}_LIBRARIES       ${QT_${basename}_LIBRARY_DEBUG})
984         ENDIF (QT_${basename}_LIBRARY_DEBUG AND NOT QT_${basename}_LIBRARY_RELEASE)
985
986         # put the value in the cache:
987         SET(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY} CACHE STRING "The Qt ${basename} library" FORCE)
988
989       ENDIF(QT_USE_IMPORTED_TARGETS)
990
991 # message(STATUS "QT_${basename}_LIBRARY: ${QT_${basename}_LIBRARY}")
992
993       SET(QT_${basename}_FOUND 1)
994
995     ENDIF (QT_${basename}_LIBRARY_RELEASE OR QT_${basename}_LIBRARY_DEBUG)
996
997     IF (QT_${basename}_INCLUDE_DIR)
998       #add the include directory to QT_INCLUDES
999       SET(QT_INCLUDES "${QT_${basename}_INCLUDE_DIR}" ${QT_INCLUDES})
1000     ENDIF (QT_${basename}_INCLUDE_DIR)
1001
1002     # Make variables changeble to the advanced user
1003     MARK_AS_ADVANCED(QT_${basename}_LIBRARY QT_${basename}_LIBRARY_RELEASE QT_${basename}_LIBRARY_DEBUG QT_${basename}_INCLUDE_DIR)
1004   ENDMACRO (_QT4_ADJUST_LIB_VARS)
1005
1006
1007   # Set QT_xyz_LIBRARY variable and add 
1008   # library include path to QT_INCLUDES
1009   _QT4_ADJUST_LIB_VARS(QtCore)
1010   _QT4_ADJUST_LIB_VARS(QtGui)
1011   _QT4_ADJUST_LIB_VARS(Qt3Support)
1012   _QT4_ADJUST_LIB_VARS(QtAssistant)
1013   _QT4_ADJUST_LIB_VARS(QtAssistantClient)
1014   _QT4_ADJUST_LIB_VARS(QtCLucene)
1015   _QT4_ADJUST_LIB_VARS(QtDBus)
1016   _QT4_ADJUST_LIB_VARS(QtDeclarative)
1017   _QT4_ADJUST_LIB_VARS(QtDesigner)
1018   _QT4_ADJUST_LIB_VARS(QtDesignerComponents)
1019   _QT4_ADJUST_LIB_VARS(QtHelp)
1020   _QT4_ADJUST_LIB_VARS(QtMultimedia)
1021   _QT4_ADJUST_LIB_VARS(QtNetwork)
1022   _QT4_ADJUST_LIB_VARS(QtNsPlugin)
1023   _QT4_ADJUST_LIB_VARS(QtOpenGL)
1024   _QT4_ADJUST_LIB_VARS(QtScript)
1025   _QT4_ADJUST_LIB_VARS(QtScriptTools)
1026   _QT4_ADJUST_LIB_VARS(QtSql)
1027   _QT4_ADJUST_LIB_VARS(QtSvg)
1028   _QT4_ADJUST_LIB_VARS(QtTest)
1029   _QT4_ADJUST_LIB_VARS(QtUiTools)
1030   _QT4_ADJUST_LIB_VARS(QtWebKit)
1031   _QT4_ADJUST_LIB_VARS(QtXml)
1032   _QT4_ADJUST_LIB_VARS(QtXmlPatterns)
1033   _QT4_ADJUST_LIB_VARS(phonon)
1034
1035   # platform dependent libraries
1036   IF(Q_WS_X11)
1037     _QT4_ADJUST_LIB_VARS(QtMotif)
1038   ENDIF(Q_WS_X11)
1039   IF(WIN32)
1040     _QT4_ADJUST_LIB_VARS(qtmain)
1041     _QT4_ADJUST_LIB_VARS(QAxServer)
1042     _QT4_ADJUST_LIB_VARS(QAxContainer)
1043   ENDIF(WIN32)
1044
1045   # If Qt is installed as a framework, we need to add QT_QTCORE_LIBRARY here (which
1046   # is the framework directory in that case), since this will make the cmake include_directories()
1047   # command recognize that we need the framework flag with the respective directory (-F)
1048   IF(QT_USE_FRAMEWORKS)
1049     SET(QT_INCLUDES       ${QT_INCLUDES} ${QT_QTCORE_LIBRARY} )
1050     SET(QT_INCLUDE_DIR ${QT_INCLUDE_DIR} ${QT_QTCORE_LIBRARY} )
1051   ENDIF(QT_USE_FRAMEWORKS)
1052
1053
1054
1055   #######################################
1056   #
1057   #       Check the executables of Qt 
1058   #          ( moc, uic, rcc )
1059   #
1060   #######################################
1061
1062
1063   IF(QT_QMAKE_CHANGED)
1064     SET(QT_UIC_EXECUTABLE NOTFOUND)
1065     SET(QT_MOC_EXECUTABLE NOTFOUND)
1066     SET(QT_UIC3_EXECUTABLE NOTFOUND)
1067     SET(QT_RCC_EXECUTABLE NOTFOUND)
1068     SET(QT_DBUSCPP2XML_EXECUTABLE NOTFOUND)
1069     SET(QT_DBUSXML2CPP_EXECUTABLE NOTFOUND)
1070     SET(QT_LUPDATE_EXECUTABLE NOTFOUND)
1071     SET(QT_LRELEASE_EXECUTABLE NOTFOUND)
1072     SET(QT_LCONVERT_EXECUTABLE NOTFOUND)
1073     SET(QT_QCOLLECTIONGENERATOR_EXECUTABLE NOTFOUND)
1074     SET(QT_DESIGNER_EXECUTABLE NOTFOUND)
1075     SET(QT_LINGUIST_EXECUTABLE NOTFOUND)
1076   ENDIF(QT_QMAKE_CHANGED)
1077   
1078   FIND_PROGRAM(QT_MOC_EXECUTABLE
1079     NAMES moc-qt4 moc
1080     PATHS ${QT_BINARY_DIR}
1081     NO_DEFAULT_PATH
1082     )
1083
1084   FIND_PROGRAM(QT_UIC_EXECUTABLE
1085     NAMES uic-qt4 uic
1086     PATHS ${QT_BINARY_DIR}
1087     NO_DEFAULT_PATH
1088     )
1089
1090   FIND_PROGRAM(QT_UIC3_EXECUTABLE
1091     NAMES uic3
1092     PATHS ${QT_BINARY_DIR}
1093     NO_DEFAULT_PATH
1094     )
1095
1096   FIND_PROGRAM(QT_RCC_EXECUTABLE 
1097     NAMES rcc
1098     PATHS ${QT_BINARY_DIR}
1099     NO_DEFAULT_PATH
1100     )
1101
1102   FIND_PROGRAM(QT_DBUSCPP2XML_EXECUTABLE 
1103     NAMES qdbuscpp2xml
1104     PATHS ${QT_BINARY_DIR}
1105     NO_DEFAULT_PATH
1106     )
1107
1108   FIND_PROGRAM(QT_DBUSXML2CPP_EXECUTABLE 
1109     NAMES qdbusxml2cpp
1110     PATHS ${QT_BINARY_DIR}
1111     NO_DEFAULT_PATH
1112     )
1113
1114   FIND_PROGRAM(QT_LUPDATE_EXECUTABLE
1115     NAMES lupdate-qt4 lupdate
1116     PATHS ${QT_BINARY_DIR}
1117     NO_DEFAULT_PATH
1118     )
1119
1120   FIND_PROGRAM(QT_LRELEASE_EXECUTABLE
1121     NAMES lrelease-qt4 lrelease
1122     PATHS ${QT_BINARY_DIR}
1123     NO_DEFAULT_PATH
1124     )
1125
1126   FIND_PROGRAM(QT_LCONVERT_EXECUTABLE
1127     NAMES lconvert-qt4 lconvert
1128     PATHS ${QT_BINARY_DIR}
1129     NO_DEFAULT_PATH
1130     )
1131
1132   FIND_PROGRAM(QT_QCOLLECTIONGENERATOR_EXECUTABLE
1133     NAMES qcollectiongenerator-qt4 qcollectiongenerator
1134     PATHS ${QT_BINARY_DIR}
1135     NO_DEFAULT_PATH
1136     )
1137
1138   FIND_PROGRAM(QT_DESIGNER_EXECUTABLE
1139     NAMES designer-qt4 designer
1140     PATHS ${QT_BINARY_DIR}
1141     NO_DEFAULT_PATH
1142     )
1143
1144   FIND_PROGRAM(QT_LINGUIST_EXECUTABLE
1145     NAMES linguist-qt4 linguist
1146     PATHS ${QT_BINARY_DIR}
1147     NO_DEFAULT_PATH
1148     )
1149
1150   IF (QT_MOC_EXECUTABLE)
1151      SET(QT_WRAP_CPP "YES")
1152   ENDIF (QT_MOC_EXECUTABLE)
1153
1154   IF (QT_UIC_EXECUTABLE)
1155      SET(QT_WRAP_UI "YES")
1156   ENDIF (QT_UIC_EXECUTABLE)
1157
1158
1159
1160   MARK_AS_ADVANCED( QT_UIC_EXECUTABLE QT_UIC3_EXECUTABLE QT_MOC_EXECUTABLE
1161     QT_RCC_EXECUTABLE QT_DBUSXML2CPP_EXECUTABLE QT_DBUSCPP2XML_EXECUTABLE
1162     QT_LUPDATE_EXECUTABLE QT_LRELEASE_EXECUTABLE QT_QCOLLECTIONGENERATOR_EXECUTABLE
1163     QT_DESIGNER_EXECUTABLE QT_LINGUIST_EXECUTABLE)
1164
1165
1166   # get the directory of the current file, used later on in the file
1167   GET_FILENAME_COMPONENT( _qt4_current_dir  "${CMAKE_CURRENT_LIST_FILE}" PATH)
1168
1169   ######################################
1170   #
1171   #       Macros for building Qt files
1172   #
1173   ######################################
1174
1175   INCLUDE("${_qt4_current_dir}/Qt4Macros.cmake")
1176
1177
1178   ######################################
1179   #
1180   #       decide if Qt got found
1181   #
1182   ######################################
1183
1184   # if the includes,libraries,moc,uic and rcc are found then we have it
1185   IF( QT_LIBRARY_DIR AND QT_INCLUDE_DIR AND QT_MOC_EXECUTABLE AND 
1186       QT_UIC_EXECUTABLE AND QT_RCC_EXECUTABLE AND QT_QTCORE_LIBRARY)
1187     SET( QT4_FOUND "YES" )
1188     IF( NOT Qt4_FIND_QUIETLY)
1189       MESSAGE(STATUS "Found Qt-Version ${QTVERSION} (using ${QT_QMAKE_EXECUTABLE})")
1190     ENDIF( NOT Qt4_FIND_QUIETLY)
1191   ELSE( QT_LIBRARY_DIR AND QT_INCLUDE_DIR AND QT_MOC_EXECUTABLE AND
1192         QT_UIC_EXECUTABLE AND QT_RCC_EXECUTABLE AND QT_QTCORE_LIBRARY)
1193     SET( QT4_FOUND "NO")
1194     SET(QT_QMAKE_EXECUTABLE "${QT_QMAKE_EXECUTABLE}-NOTFOUND" CACHE FILEPATH "Invalid qmake found" FORCE)
1195     IF( Qt4_FIND_REQUIRED)
1196       IF ( NOT QT_LIBRARY_DIR )
1197         MESSAGE(STATUS "Qt libraries NOT found!")
1198       ENDIF(NOT QT_LIBRARY_DIR )
1199       IF ( NOT QT_INCLUDE_DIR )
1200         MESSAGE(STATUS "Qt includes NOT found!")
1201       ENDIF( NOT QT_INCLUDE_DIR )
1202       IF ( NOT QT_MOC_EXECUTABLE )
1203         MESSAGE(STATUS "Qt's moc NOT found!")
1204       ENDIF( NOT QT_MOC_EXECUTABLE )
1205       IF ( NOT QT_UIC_EXECUTABLE )
1206         MESSAGE(STATUS "Qt's uic NOT found!")
1207       ENDIF( NOT QT_UIC_EXECUTABLE )
1208       IF ( NOT QT_RCC_EXECUTABLE )
1209         MESSAGE(STATUS "Qt's rcc NOT found!")
1210       ENDIF( NOT QT_RCC_EXECUTABLE )
1211       MESSAGE( FATAL_ERROR "Qt libraries, includes, moc, uic or/and rcc NOT found!")
1212     ENDIF( Qt4_FIND_REQUIRED)
1213   ENDIF( QT_LIBRARY_DIR AND QT_INCLUDE_DIR AND QT_MOC_EXECUTABLE AND 
1214          QT_UIC_EXECUTABLE AND  QT_RCC_EXECUTABLE AND QT_QTCORE_LIBRARY)
1215   
1216   SET(QT_FOUND ${QT4_FOUND})
1217
1218
1219   ###############################################
1220   #
1221   #       configuration/system dependent settings  
1222   #
1223   ###############################################
1224
1225   INCLUDE("${_qt4_current_dir}/Qt4ConfigDependentSettings.cmake")
1226
1227
1228   #######################################
1229   #
1230   #       compatibility settings 
1231   #
1232   #######################################
1233   # Backwards compatibility for CMake1.4 and 1.2
1234   SET (QT_MOC_EXE ${QT_MOC_EXECUTABLE} )
1235   SET (QT_UIC_EXE ${QT_UIC_EXECUTABLE} )
1236
1237   SET( QT_QT_LIBRARY "")
1238
1239 ELSE(QT4_QMAKE_FOUND)
1240    
1241    SET(QT_QMAKE_EXECUTABLE "${QT_QMAKE_EXECUTABLE}-NOTFOUND" CACHE FILEPATH "Invalid qmake found" FORCE)
1242    
1243    # The code below is overly complex to make sure we do not break compatibility with CMake 2.6.x
1244    # For CMake 2.8, it should be simplified by getting rid of QT4_INSTALLED_VERSION_TOO_OLD and 
1245    # QT4_INSTALLED_VERSION_TOO_NEW
1246    IF(Qt4_FIND_REQUIRED)
1247       IF(QT4_INSTALLED_VERSION_TOO_OLD)
1248     IF( Qt4_FIND_VERSION_EXACT )
1249       MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too old, version ${QT_MIN_VERSION} is required")
1250     ELSE( Qt4_FIND_VERSION_EXACT )
1251       MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too old, at least version ${QT_MIN_VERSION} is required")
1252     ENDIF( Qt4_FIND_VERSION_EXACT )
1253       ELSE(QT4_INSTALLED_VERSION_TOO_OLD)
1254       IF( Qt4_FIND_VERSION_EXACT AND QT4_INSTALLED_VERSION_TOO_NEW )
1255       MESSAGE(FATAL_ERROR "The installed Qt version ${QTVERSION} is too new, version ${QT_MIN_VERSION} is required")
1256     ELSE( Qt4_FIND_VERSION_EXACT AND QT4_INSTALLED_VERSION_TOO_NEW )
1257       MESSAGE( FATAL_ERROR "Qt qmake not found!")
1258     ENDIF( Qt4_FIND_VERSION_EXACT AND QT4_INSTALLED_VERSION_TOO_NEW )
1259       ENDIF(QT4_INSTALLED_VERSION_TOO_OLD)
1260    ELSE(Qt4_FIND_REQUIRED)
1261       IF(QT4_INSTALLED_VERSION_TOO_OLD AND NOT Qt4_FIND_QUIETLY)
1262          MESSAGE(STATUS "The installed Qt version ${QTVERSION} is too old, at least version ${QT_MIN_VERSION} is required")
1263       ENDIF(QT4_INSTALLED_VERSION_TOO_OLD AND NOT Qt4_FIND_QUIETLY)
1264    ENDIF(Qt4_FIND_REQUIRED)
1265  
1266 ENDIF (QT4_QMAKE_FOUND)
1267