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