]> Creatis software - crea.git/blob - cmake/CREAMacro_FindAndUseQt.cmake
Fixes:
[crea.git] / cmake / CREAMacro_FindAndUseQt.cmake
1 # ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
4 #                        pour la Santé)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and 
10 #  abiding by the rules of distribution of free software. You can  use, 
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
12 #  license as circulated by CEA, CNRS and INRIA at the following URL 
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability. 
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */ 
25
26
27 IF(WIN32)
28         STRING(REGEX REPLACE "\\\\" "/" QT_DIR "$ENV{QTDIR}")
29         SET(QT_USE_FILE ${CMAKE_ROOT}/Modules/UseQt4.cmake)
30         SET(QT_INCLUDE_DIR "${QT_DIR}/include")
31         SET(QT_QT_INCLUDE_DIR "${QT_INCLUDE_DIR}/Qt")
32         SET(QT_QT3SUPPORT_INCLUDE_DIR "${QT_INCLUDE_DIR}/Qt3Support")
33         SET(QT_QTASSISTANT_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtAssistant")
34         SET(QT_QTCORE_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtCore")
35         SET(QT_QTDESIGNER_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtDesigner")
36         SET(QT_QTDESIGNERCOMPONENTS_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtDesigner")
37         SET(QT_QTDBUS_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtDBus")
38         SET(QT_QTGUI_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtGui")
39         SET(QT_QTMOTIF_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtMotif")
40         SET(QT_QTNETWORK_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtNetwork")
41         SET(QT_QTNSPLUGIN_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtNsPlugin")
42         SET(QT_QTOPENGL_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtOpenGL")
43         SET(QT_QTSQL_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtSql")
44         SET(QT_QTXML_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtXml")
45         SET(QT_QTSCRIPT_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtScript")
46         SET(QT_QTASSISTANTCLIENT_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtAssistant")
47         SET(QT_QTWEBKIT_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtHelp")
48         SET(QT_QTHELP_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtWebKit")
49         SET(QT_QTXMLPATTERNS_INCLUDE_DIR "${QT_INCLUDE_DIR}/QtXmlPatterns")
50         SET(QT_PHONON_INCLUDE_DIR "${QT_INCLUDE_DIR}/phonon")           
51         SET(QT_FOUND "YES" )
52         SET(QT_DEFINITIONS -DQT_DLL)
53         #            True if QtCore was found.
54         SET(QT_QTCORE_FOUND "YES" )
55         #  QT_QTGUI_FOUND           True if QtGui was found.
56         SET(QT_QTGUI_FOUND "YES" )
57         #  QT_QT3SUPPORT_FOUND      True if Qt3Support was found.
58         SET(QT_QT3SUPPORT_FOUND "YES" )
59         #  QT_QTASSISTANT_FOUND     True if QtAssistant was found.
60         SET(QT_QTASSISTANT_FOUND "YES" )
61         #  QT_QTDBUS_FOUND          True if QtDBus was found.
62         SET(QT_QTDBUS_FOUND "YES" )
63         #  QT_QTDESIGNER_FOUND      True if QtDesigner was found.
64         SET(QT_QTDESIGNER_FOUND "YES" )
65         #  QT_QTDESIGNERCOMPONENTS  True if QtDesignerComponents was found.
66         SET(QT_QTDESIGNERCOMPONENTS "YES" )
67         #  QT_QTMOTIF_FOUND         True if QtMotif was found.
68         SET(QT_QTMOTIF_FOUND "YES" )
69         #  QT_QTNETWORK_FOUND       True if QtNetwork was found.
70         SET(QT_QTNETWORK_FOUND "YES" )
71         #  QT_QTNSPLUGIN_FOUND      True if QtNsPlugin was found.
72         SET(QT_QTNSPLUGIN_FOUND "YES" )
73         #  QT_QTOPENGL_FOUND        True if QtOpenGL was found.
74         SET(QT_QTOPENGL_FOUND "YES" )
75         #  QT_QTSQL_FOUND           True if QtSql was found.
76         SET(QT_QTSQL_FOUND "YES" )
77         #  QT_QTXML_FOUND           True if QtXml was found.
78         SET(QT_QTXML_FOUND "YES" )
79         #  QT_QTSVG_FOUND           True if QtSvg was found.
80         SET(QT_QTSVG_FOUND "YES" )
81         #  QT_QTSCRIPT_FOUND        True if QtScript was found.
82         SET(QT_QTSCRIPT_FOUND "YES" )
83         #  QT_QTTEST_FOUND          True if QtTest was found.
84         SET(QT_QTTEST_FOUND "YES" )
85         #  QT_QTUITOOLS_FOUND       True if QtUiTools was found.
86         SET(QT_QTUITOOLS_FOUND "YES" )
87         #  QT_QTASSISTANTCLIENT_FOUND  True if QtAssistantClient was found.
88         SET(QT_QTASSISTANTCLIENT_FOUND "YES" )
89         #  QT_QTHELP_FOUND          True if QtHelp was found.
90         SET(QT_QTHELP_FOUND "YES" )
91         #  QT_QTWEBKIT_FOUND        True if QtWebKit was found.
92         SET(QT_QTWEBKIT_FOUND "YES" )
93         #  QT_QTXMLPATTERNS_FOUND   True if QtXmlPatterns was found.
94         SET(QT_QTXMLPATTERNS_FOUND "YES" )
95         #  QT_PHONON_FOUND          True if phonon was found.
96         SET(QT_PHONON_FOUND "YES" )
97
98         SET(QT_MKSPECS_DIR "${QT_DIR}/mkspecs") 
99         SET(QT_INCLUDES ${QT_QT_INCLUDE_DIR} ${QT_MKSPECS_DIR}/default ${QT_INCLUDE_DIR} )      
100         SET(QT_LIBRARY_DIR "${QT_DIR}/lib")                     
101         
102         SET(QT_MOC_EXECUTABLE "${QT_DIR}/bin/moc.exe")
103         SET(QT_WRAP_CPP "YES")
104         SET(QT_UIC_EXECUTABLE "${QT_DIR}/bin/uic.exe")
105         SET(QT_WRAP_UI "YES")
106         
107         #SET(QT_UIC3_EXECUTABLE "${QT_DIR}/bin/uic3.exe")
108         #SET(QT_RCC_EXECUTABLE "${QT_DIR}/bin/rcc.exe")
109         #SET(QT_LUPDATE_EXECUTABLE "${QT_DIR}/bin/lupdate.exe")
110         #SET(QT_LRELEASE_EXECUTABLE "${QT_DIR}/bin/lrelease.exe")
111         
112         #SET(QT_DBUSCPP2XML_EXECUTABLE "${QT_DIR}/bin/moc.exe")
113         #SET(QT_DBUSXML2CPP_EXECUTABLE "${QT_DIR}/bin/moc.exe")
114         
115         
116         SET(QT_FOUND "YES" )
117                 
118         MACRO (QT4_EXTRACT_OPTIONS _qt4_files _qt4_options)
119                 SET(${_qt4_files})
120                 SET(${_qt4_options})
121                 SET(_QT4_DOING_OPTIONS FALSE)
122                 FOREACH(_currentArg ${ARGN})
123                   IF ("${_currentArg}" STREQUAL "OPTIONS")
124                         SET(_QT4_DOING_OPTIONS TRUE)
125                   ELSE ("${_currentArg}" STREQUAL "OPTIONS")
126                         IF(_QT4_DOING_OPTIONS) 
127                           LIST(APPEND ${_qt4_options} "${_currentArg}")
128                         ELSE(_QT4_DOING_OPTIONS)
129                           LIST(APPEND ${_qt4_files} "${_currentArg}")
130                         ENDIF(_QT4_DOING_OPTIONS)
131                   ENDIF ("${_currentArg}" STREQUAL "OPTIONS")
132                 ENDFOREACH(_currentArg) 
133   ENDMACRO (QT4_EXTRACT_OPTIONS)
134   
135   # macro used to create the names of output files preserving relative dirs
136   MACRO (QT4_MAKE_OUTPUT_FILE infile prefix ext outfile )
137     STRING(LENGTH ${CMAKE_CURRENT_BINARY_DIR} _binlength)
138     STRING(LENGTH ${infile} _infileLength)
139     SET(_checkinfile ${CMAKE_CURRENT_SOURCE_DIR})
140     IF(_infileLength GREATER _binlength)
141       STRING(SUBSTRING "${infile}" 0 ${_binlength} _checkinfile)
142     ENDIF(_infileLength GREATER _binlength)
143     IF(CMAKE_CURRENT_BINARY_DIR MATCHES "${_checkinfile}")
144       FILE(RELATIVE_PATH rel ${CMAKE_CURRENT_BINARY_DIR} ${infile})
145     ELSE(CMAKE_CURRENT_BINARY_DIR MATCHES "${_checkinfile}")
146       FILE(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile})
147     ENDIF(CMAKE_CURRENT_BINARY_DIR MATCHES "${_checkinfile}")
148     SET(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${rel}")
149     STRING(REPLACE ".." "__" _outfile ${_outfile})
150     GET_FILENAME_COMPONENT(outpath ${_outfile} PATH)
151     GET_FILENAME_COMPONENT(_outfile ${_outfile} NAME_WE)
152     FILE(MAKE_DIRECTORY ${outpath})
153     SET(${outfile} ${outpath}/${prefix}${_outfile}.${ext})
154   ENDMACRO (QT4_MAKE_OUTPUT_FILE )
155
156   MACRO (QT4_GET_MOC_FLAGS _moc_flags)
157      SET(${_moc_flags})
158      GET_DIRECTORY_PROPERTY(_inc_DIRS INCLUDE_DIRECTORIES)
159
160      FOREACH(_current ${_inc_DIRS})
161         SET(${_moc_flags} ${${_moc_flags}} "-I${_current}")
162      ENDFOREACH(_current ${_inc_DIRS})
163      
164      GET_DIRECTORY_PROPERTY(_defines COMPILE_DEFINITIONS)
165      FOREACH(_current ${_defines})
166         SET(${_moc_flags} ${${_moc_flags}} "-D${_current}")
167      ENDFOREACH(_current ${_defines})
168
169      IF(Q_WS_WIN)
170        SET(${_moc_flags} ${${_moc_flags}} -DWIN32)
171      ENDIF(Q_WS_WIN)
172
173   ENDMACRO(QT4_GET_MOC_FLAGS)
174
175   # helper macro to set up a moc rule
176   MACRO (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options)
177     # For Windows, create a parameters file to work around command line length limit
178     IF (WIN32)
179       # Pass the parameters in a file.  Set the working directory to
180       # be that containing the parameters file and reference it by
181       # just the file name.  This is necessary because the moc tool on
182       # MinGW builds does not seem to handle spaces in the path to the
183       # file given with the @ syntax.
184       GET_FILENAME_COMPONENT(_moc_outfile_name "${outfile}" NAME)
185       GET_FILENAME_COMPONENT(_moc_outfile_dir "${outfile}" PATH)
186       IF(_moc_outfile_dir)
187         SET(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir})
188       ENDIF(_moc_outfile_dir)
189       SET (_moc_parameters_file ${outfile}_parameters)
190       SET (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}")
191       FILE (REMOVE ${_moc_parameters_file})
192       FOREACH(arg ${_moc_parameters})
193         FILE (APPEND ${_moc_parameters_file} "${arg}\n")
194       ENDFOREACH(arg)
195       ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
196                          COMMAND ${QT_MOC_EXECUTABLE} @${_moc_outfile_name}_parameters
197                          DEPENDS ${infile}
198                          ${_moc_working_dir}
199                          VERBATIM)
200     ELSE (WIN32)     
201       ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
202                          COMMAND ${QT_MOC_EXECUTABLE}
203                          ARGS ${moc_flags} ${moc_options} -o ${outfile} ${infile}
204                          DEPENDS ${infile})     
205     ENDIF (WIN32)
206   ENDMACRO (QT4_CREATE_MOC_COMMAND)
207
208   
209   MACRO (QT4_GENERATE_MOC infile outfile )
210      QT4_GET_MOC_FLAGS(moc_flags)
211      GET_FILENAME_COMPONENT(abs_infile ${infile} ABSOLUTE)
212      QT4_CREATE_MOC_COMMAND(${abs_infile} ${outfile} "${moc_flags}" "")
213      SET_SOURCE_FILES_PROPERTIES(${outfile} PROPERTIES SKIP_AUTOMOC TRUE)  # dont run automoc on this file
214   ENDMACRO (QT4_GENERATE_MOC)
215
216
217   # QT4_WRAP_CPP(outfiles inputfile ... )
218
219   MACRO (QT4_WRAP_CPP outfiles )
220     # get include dirs
221     QT4_GET_MOC_FLAGS(moc_flags)
222     QT4_EXTRACT_OPTIONS(moc_files moc_options ${ARGN})
223
224     FOREACH (it ${moc_files})
225       GET_FILENAME_COMPONENT(it ${it} ABSOLUTE)
226       QT4_MAKE_OUTPUT_FILE(${it} moc_ cxx outfile)
227       QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags}" "${moc_options}")
228       SET(${outfiles} ${${outfiles}} ${outfile})
229     ENDFOREACH(it)
230
231   ENDMACRO (QT4_WRAP_CPP)
232
233
234   # QT4_WRAP_UI(outfiles inputfile ... )
235
236   MACRO (QT4_WRAP_UI outfiles )
237     QT4_EXTRACT_OPTIONS(ui_files ui_options ${ARGN})
238
239     FOREACH (it ${ui_files})
240       GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
241       GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
242       SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.h)
243       ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
244         COMMAND ${QT_UIC_EXECUTABLE}
245         ARGS ${ui_options} -o ${outfile} ${infile}
246         MAIN_DEPENDENCY ${infile})
247       SET(${outfiles} ${${outfiles}} ${outfile})
248     ENDFOREACH (it)
249
250   ENDMACRO (QT4_WRAP_UI)
251
252
253   # QT4_ADD_RESOURCES(outfiles inputfile ... )
254
255   MACRO (QT4_ADD_RESOURCES outfiles )
256     QT4_EXTRACT_OPTIONS(rcc_files rcc_options ${ARGN})
257
258     FOREACH (it ${rcc_files})
259       GET_FILENAME_COMPONENT(outfilename ${it} NAME_WE)
260       GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
261       GET_FILENAME_COMPONENT(rc_path ${infile} PATH)
262       SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cxx)
263       #  parse file for dependencies 
264       #  all files are absolute paths or relative to the location of the qrc file
265       FILE(READ "${infile}" _RC_FILE_CONTENTS)
266       STRING(REGEX MATCHALL "<file[^<]+" _RC_FILES "${_RC_FILE_CONTENTS}")
267       SET(_RC_DEPENDS)
268       FOREACH(_RC_FILE ${_RC_FILES})
269         STRING(REGEX REPLACE "^<file[^>]*>" "" _RC_FILE "${_RC_FILE}")
270         STRING(REGEX MATCH "^/|([A-Za-z]:/)" _ABS_PATH_INDICATOR "${_RC_FILE}")
271         IF(NOT _ABS_PATH_INDICATOR)
272           SET(_RC_FILE "${rc_path}/${_RC_FILE}")
273         ENDIF(NOT _ABS_PATH_INDICATOR)
274         SET(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}")
275       ENDFOREACH(_RC_FILE)
276       ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
277         COMMAND ${QT_RCC_EXECUTABLE}
278         ARGS ${rcc_options} -name ${outfilename} -o ${outfile} ${infile}
279         MAIN_DEPENDENCY ${infile}
280         DEPENDS ${_RC_DEPENDS})
281       SET(${outfiles} ${${outfiles}} ${outfile})
282     ENDFOREACH (it)
283
284   ENDMACRO (QT4_ADD_RESOURCES)
285
286   MACRO(QT4_ADD_DBUS_INTERFACE _sources _interface _basename)
287     GET_FILENAME_COMPONENT(_infile ${_interface} ABSOLUTE)
288     SET(_header ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h)
289     SET(_impl   ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp)
290     SET(_moc    ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc)
291   
292     ADD_CUSTOM_COMMAND(OUTPUT ${_impl} ${_header}
293         COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} -m -p ${_basename} ${_infile}
294         DEPENDS ${_infile})
295   
296     SET_SOURCE_FILES_PROPERTIES(${_impl} PROPERTIES SKIP_AUTOMOC TRUE)
297     
298     QT4_GENERATE_MOC(${_header} ${_moc})
299   
300     SET(${_sources} ${${_sources}} ${_impl} ${_header} ${_moc})
301     MACRO_ADD_FILE_DEPENDENCIES(${_impl} ${_moc})
302   
303   ENDMACRO(QT4_ADD_DBUS_INTERFACE)
304   
305   
306   MACRO(QT4_ADD_DBUS_INTERFACES _sources)
307      FOREACH (_current_FILE ${ARGN})
308         GET_FILENAME_COMPONENT(_infile ${_current_FILE} ABSOLUTE)
309         # get the part before the ".xml" suffix
310         STRING(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2" _basename ${_current_FILE})
311         STRING(TOLOWER ${_basename} _basename)
312         QT4_ADD_DBUS_INTERFACE(${_sources} ${_infile} ${_basename}interface)
313      ENDFOREACH (_current_FILE)
314   ENDMACRO(QT4_ADD_DBUS_INTERFACES)
315   
316   
317   MACRO(QT4_GENERATE_DBUS_INTERFACE _header) # _customName )
318     SET(_customName "${ARGV1}")
319     GET_FILENAME_COMPONENT(_in_file ${_header} ABSOLUTE)
320     GET_FILENAME_COMPONENT(_basename ${_header} NAME_WE)
321     
322     IF (_customName)
323       SET(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName})
324     ELSE (_customName)
325       SET(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml)
326     ENDIF (_customName)
327   
328     ADD_CUSTOM_COMMAND(OUTPUT ${_target}
329         COMMAND ${QT_DBUSCPP2XML_EXECUTABLE} ${_in_file} > ${_target}
330         DEPENDS ${_in_file}
331     )
332   ENDMACRO(QT4_GENERATE_DBUS_INTERFACE)
333   
334   
335   MACRO(QT4_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename )
336     GET_FILENAME_COMPONENT(_infile ${_xml_file} ABSOLUTE)
337     
338     SET(_optionalBasename "${ARGV4}")
339     IF (_optionalBasename)
340        SET(_basename ${_optionalBasename} )
341     ELSE (_optionalBasename)
342        STRING(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile})
343        STRING(TOLOWER ${_basename} _basename)
344     ENDIF (_optionalBasename)
345
346     SET(_optionalClassName "${ARGV5}")
347     SET(_header ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h)
348     SET(_impl   ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp)
349     SET(_moc    ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc)
350
351     IF(_optionalClassName)
352        ADD_CUSTOM_COMMAND(OUTPUT ${_impl} ${_header}
353           COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -c ${_optionalClassName} -i ${_include} -l ${_parentClass} ${_infile}
354           DEPENDS ${_infile}
355         )
356     ELSE(_optionalClassName)
357        ADD_CUSTOM_COMMAND(OUTPUT ${_impl} ${_header}
358           COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -i ${_include} -l ${_parentClass} ${_infile}
359           DEPENDS ${_infile}
360         )
361     ENDIF(_optionalClassName)
362
363     QT4_GENERATE_MOC(${_header} ${_moc})
364     SET_SOURCE_FILES_PROPERTIES(${_impl} PROPERTIES SKIP_AUTOMOC TRUE)
365     MACRO_ADD_FILE_DEPENDENCIES(${_impl} ${_moc})
366
367     SET(${_sources} ${${_sources}} ${_impl} ${_header} ${_moc})
368   ENDMACRO(QT4_ADD_DBUS_ADAPTOR)
369
370    MACRO(QT4_AUTOMOC)
371       QT4_GET_MOC_FLAGS(_moc_INCS)
372
373       SET(_matching_FILES )
374       FOREACH (_current_FILE ${ARGN})
375
376          GET_FILENAME_COMPONENT(_abs_FILE ${_current_FILE} ABSOLUTE)
377          # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
378          # This is required to make uic work correctly:
379          # we need to add generated .cpp files to the sources (to compile them),
380          # but we cannot let automoc handle them, as the .cpp files don't exist yet when
381          # cmake is run for the very first time on them -> however the .cpp files might
382          # exist at a later run. at that time we need to skip them, so that we don't add two
383          # different rules for the same moc file
384          GET_SOURCE_FILE_PROPERTY(_skip ${_abs_FILE} SKIP_AUTOMOC)
385
386          IF ( NOT _skip AND EXISTS ${_abs_FILE} )
387
388             FILE(READ ${_abs_FILE} _contents)
389
390             GET_FILENAME_COMPONENT(_abs_PATH ${_abs_FILE} PATH)
391
392             STRING(REGEX MATCHALL "#include +[^ ]+\\.moc[\">]" _match "${_contents}")
393             IF(_match)
394                FOREACH (_current_MOC_INC ${_match})
395                   STRING(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
396                   GET_FILENAME_COMPONENT(_basename ${_current_MOC} NAME_WE)
397                   SET(_header ${_abs_PATH}/${_basename}.h)
398                   SET(_moc    ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
399                   QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "")
400                   MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
401                ENDFOREACH (_current_MOC_INC)
402             ENDIF(_match)
403          ENDIF ( NOT _skip AND EXISTS ${_abs_FILE} )
404       ENDFOREACH (_current_FILE)
405    ENDMACRO(QT4_AUTOMOC)
406
407    MACRO(QT4_CREATE_TRANSLATION _qm_files)
408       QT4_EXTRACT_OPTIONS(_lupdate_files _lupdate_options ${ARGN})
409       MESSAGE("lupdate_files ${_lupdate_files}")
410       MESSAGE("lupdate_options ${_lupdate_options}")
411       SET(_my_sources)
412       SET(_my_tsfiles)
413       FOREACH (_file ${_lupdate_files})
414          GET_FILENAME_COMPONENT(_ext ${_file} EXT)
415          GET_FILENAME_COMPONENT(_abs_FILE ${_file} ABSOLUTE)
416          IF(_ext MATCHES "ts")
417            LIST(APPEND _my_tsfiles ${_abs_FILE})
418          ELSE(_ext MATCHES "ts")
419            LIST(APPEND _my_sources ${_abs_FILE})
420          ENDIF(_ext MATCHES "ts")
421       ENDFOREACH(_file)
422       FOREACH(_ts_file ${_my_tsfiles})
423         ADD_CUSTOM_COMMAND(OUTPUT ${_ts_file}
424            COMMAND ${QT_LUPDATE_EXECUTABLE}
425            ARGS ${_lupdate_options} ${_my_sources} -ts ${_ts_file}
426            DEPENDS ${_my_sources})
427       ENDFOREACH(_ts_file)
428       QT4_ADD_TRANSLATION(${_qm_files} ${_my_tsfiles})
429    ENDMACRO(QT4_CREATE_TRANSLATION)
430
431    MACRO(QT4_ADD_TRANSLATION _qm_files)
432       FOREACH (_current_FILE ${ARGN})
433          GET_FILENAME_COMPONENT(_abs_FILE ${_current_FILE} ABSOLUTE)
434          GET_FILENAME_COMPONENT(qm ${_abs_FILE} NAME_WE)
435          SET(qm "${CMAKE_CURRENT_BINARY_DIR}/${qm}.qm")
436
437          ADD_CUSTOM_COMMAND(OUTPUT ${qm}
438             COMMAND ${QT_LRELEASE_EXECUTABLE}
439             ARGS ${_abs_FILE} -qm ${qm}
440             DEPENDS ${_abs_FILE}
441          )
442          SET(${_qm_files} ${${_qm_files}} ${qm})
443       ENDFOREACH (_current_FILE)
444    ENDMACRO(QT4_ADD_TRANSLATION)
445    
446    
447    # Set QT_QTCORE_LIBRARY by searching for a lib with "QtCore."  as part of the filename
448   FIND_LIBRARY(QT_QTCORE_LIBRARY_RELEASE NAMES QtCore QtCore4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH )
449   FIND_LIBRARY(QT_QTCORE_LIBRARY_DEBUG NAMES QtCore_debug QtCored QtCored4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
450
451   # Set QT_QT3SUPPORT_LIBRARY
452   FIND_LIBRARY(QT_QT3SUPPORT_LIBRARY_RELEASE NAMES Qt3Support Qt3Support4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
453   FIND_LIBRARY(QT_QT3SUPPORT_LIBRARY_DEBUG   NAMES Qt3Support_debug Qt3Supportd Qt3Supportd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
454
455   # Set QT_QTGUI_LIBRARY
456   FIND_LIBRARY(QT_QTGUI_LIBRARY_RELEASE NAMES QtGui QtGui4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
457   FIND_LIBRARY(QT_QTGUI_LIBRARY_DEBUG   NAMES QtGui_debug QtGuid QtGuid4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
458
459   # Set QT_QTMOTIF_LIBRARY
460   IF(Q_WS_X11)
461     FIND_LIBRARY(QT_QTMOTIF_LIBRARY_RELEASE NAMES QtMotif PATHS ${QT_LIBRARY_DIR}       NO_DEFAULT_PATH)
462     FIND_LIBRARY(QT_QTMOTIF_LIBRARY_DEBUG   NAMES QtMotif_debug PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
463   ENDIF(Q_WS_X11)
464
465   # Set QT_QTNETWORK_LIBRARY
466   FIND_LIBRARY(QT_QTNETWORK_LIBRARY_RELEASE NAMES QtNetwork QtNetwork4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
467   FIND_LIBRARY(QT_QTNETWORK_LIBRARY_DEBUG   NAMES QtNetwork_debug QtNetworkd QtNetworkd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
468
469   # Set QT_QTNSPLUGIN_LIBRARY
470   FIND_LIBRARY(QT_QTNSPLUGIN_LIBRARY_RELEASE NAMES QtNsPlugin PATHS ${QT_LIBRARY_DIR}       NO_DEFAULT_PATH)
471   FIND_LIBRARY(QT_QTNSPLUGIN_LIBRARY_DEBUG   NAMES QtNsPlugin_debug PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
472
473   # Set QT_QTOPENGL_LIBRARY
474   FIND_LIBRARY(QT_QTOPENGL_LIBRARY_RELEASE NAMES QtOpenGL QtOpenGL4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
475   FIND_LIBRARY(QT_QTOPENGL_LIBRARY_DEBUG   NAMES QtOpenGL_debug QtOpenGLd QtOpenGLd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
476
477   # Set QT_QTSQL_LIBRARY
478   FIND_LIBRARY(QT_QTSQL_LIBRARY_RELEASE NAMES QtSql QtSql4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
479   FIND_LIBRARY(QT_QTSQL_LIBRARY_DEBUG   NAMES QtSql_debug QtSqld QtSqld4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
480
481   # Set QT_QTXML_LIBRARY
482   FIND_LIBRARY(QT_QTXML_LIBRARY_RELEASE NAMES QtXml QtXml4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
483   FIND_LIBRARY(QT_QTXML_LIBRARY_DEBUG   NAMES QtXml_debug QtXmld QtXmld4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
484
485   # Set QT_QTSVG_LIBRARY
486   FIND_LIBRARY(QT_QTSVG_LIBRARY_RELEASE NAMES QtSvg QtSvg4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
487   FIND_LIBRARY(QT_QTSVG_LIBRARY_DEBUG   NAMES QtSvg_debug QtSvgd QtSvgd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
488
489   # Set QT_QTUITOOLS_LIBRARY
490   FIND_LIBRARY(QT_QTUITOOLS_LIBRARY_RELEASE NAMES QtUiTools QtUiTools4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
491   FIND_LIBRARY(QT_QTUITOOLS_LIBRARY_DEBUG   NAMES QtUiTools_debug QtUiToolsd QtUiToolsd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
492
493   # Set QT_QTTEST_LIBRARY
494   FIND_LIBRARY(QT_QTTEST_LIBRARY_RELEASE NAMES QtTest QtTest4 PATHS ${QT_LIBRARY_DIR}                      NO_DEFAULT_PATH)
495   FIND_LIBRARY(QT_QTTEST_LIBRARY_DEBUG   NAMES QtTest_debug QtTestd QtTestd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
496
497   # Set QT_QTDBUS_LIBRARY
498   # This was introduced with Qt 4.2, where also the naming scheme for debug libs was changed
499   # So does any of the debug lib names listed here actually exist ?
500   FIND_LIBRARY(QT_QTDBUS_LIBRARY_RELEASE NAMES QtDBus QtDBus4 PATHS ${QT_LIBRARY_DIR}                       NO_DEFAULT_PATH)
501   FIND_LIBRARY(QT_QTDBUS_LIBRARY_DEBUG   NAMES QtDBus_debug QtDBusd QtDBusd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
502
503   # Set QT_QTSCRIPT_LIBRARY
504   FIND_LIBRARY(QT_QTSCRIPT_LIBRARY_RELEASE NAMES QtScript QtScript4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
505   FIND_LIBRARY(QT_QTSCRIPT_LIBRARY_DEBUG   NAMES QtScript_debug QtScriptd QtScriptd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
506    
507   # Set QT_QTASSISTANTCLIENT_LIBRARY
508   FIND_LIBRARY(QT_QTASSISTANTCLIENT_LIBRARY_RELEASE NAMES QtAssistantClient QtAssistantClient4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
509   FIND_LIBRARY(QT_QTASSISTANTCLIENT_LIBRARY_DEBUG   NAMES QtAssistantClient_debug QtAssistantClientd QtAssistantClientd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
510
511   # Set QT_QTHELP_LIBRARY
512   FIND_LIBRARY(QT_QTHELP_LIBRARY_RELEASE NAMES QtHelp QtHelp4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
513   FIND_LIBRARY(QT_QTHELP_LIBRARY_DEBUG   NAMES QtHelp_debug QtHelpd QtHelpd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
514   FIND_LIBRARY(QT_QTCLUCENE_LIBRARY_RELEASE NAMES QtCLucene QtCLucene4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
515   FIND_LIBRARY(QT_QTCLUCENE_LIBRARY_DEBUG   NAMES QtCLucene_debug QtCLucened QtCLucened4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
516    
517    # Set QT_QTWEBKIT_LIBRARY
518   FIND_LIBRARY(QT_QTWEBKIT_LIBRARY_RELEASE NAMES QtWebKit QtWebKit4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
519   FIND_LIBRARY(QT_QTWEBKIT_LIBRARY_DEBUG   NAMES QtWebKit_debug QtWebKitd QtWebKitd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
520
521   # Set QT_QTXMLPATTERNS_LIBRARY
522   FIND_LIBRARY(QT_QTXMLPATTERNS_LIBRARY_RELEASE NAMES QtXmlPatterns QtXmlPatterns4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
523   FIND_LIBRARY(QT_QTXMLPATTERNS_LIBRARY_DEBUG   NAMES QtXmlPatterns_debug QtXmlPatternsd QtXmlPatternsd4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
524   
525   # Set QT_PHONON_LIBRARY
526   FIND_LIBRARY(QT_PHONON_LIBRARY_RELEASE NAMES phonon phonon4 PATHS ${QT_LIBRARY_DIR}        NO_DEFAULT_PATH)
527   FIND_LIBRARY(QT_PHONON_LIBRARY_DEBUG   NAMES phonon_debug phonond phonond4 PATHS ${QT_LIBRARY_DIR} NO_DEFAULT_PATH)
528   
529    MACRO (_QT4_ADJUST_LIB_VARS basename)
530     IF (QT_${basename}_LIBRARY_RELEASE OR QT_${basename}_LIBRARY_DEBUG)
531
532       # if only the release version was found, set the debug variable also to the release version
533       IF (QT_${basename}_LIBRARY_RELEASE AND NOT QT_${basename}_LIBRARY_DEBUG)
534         SET(QT_${basename}_LIBRARY_DEBUG ${QT_${basename}_LIBRARY_RELEASE})
535         SET(QT_${basename}_LIBRARY       ${QT_${basename}_LIBRARY_RELEASE})
536         SET(QT_${basename}_LIBRARIES     ${QT_${basename}_LIBRARY_RELEASE})
537       ENDIF (QT_${basename}_LIBRARY_RELEASE AND NOT QT_${basename}_LIBRARY_DEBUG)
538
539       # if only the debug version was found, set the release variable also to the debug version
540       IF (QT_${basename}_LIBRARY_DEBUG AND NOT QT_${basename}_LIBRARY_RELEASE)
541         SET(QT_${basename}_LIBRARY_RELEASE ${QT_${basename}_LIBRARY_DEBUG})
542         SET(QT_${basename}_LIBRARY         ${QT_${basename}_LIBRARY_DEBUG})
543         SET(QT_${basename}_LIBRARIES       ${QT_${basename}_LIBRARY_DEBUG})
544       ENDIF (QT_${basename}_LIBRARY_DEBUG AND NOT QT_${basename}_LIBRARY_RELEASE)
545
546       IF (QT_${basename}_LIBRARY_DEBUG AND QT_${basename}_LIBRARY_RELEASE)
547         # if the generator supports configuration types then set
548         # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
549         IF (CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
550           SET(QT_${basename}_LIBRARY       optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG})
551         ELSE(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
552           # if there are no configuration types and CMAKE_BUILD_TYPE has no value
553           # then just use the release libraries
554           SET(QT_${basename}_LIBRARY       ${QT_${basename}_LIBRARY_RELEASE} )
555         ENDIF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
556         SET(QT_${basename}_LIBRARIES       optimized ${QT_${basename}_LIBRARY_RELEASE} debug ${QT_${basename}_LIBRARY_DEBUG})
557       ENDIF (QT_${basename}_LIBRARY_DEBUG AND QT_${basename}_LIBRARY_RELEASE)
558
559       SET(QT_${basename}_LIBRARY ${QT_${basename}_LIBRARY} CACHE FILEPATH "The Qt ${basename} library")
560
561       IF (QT_${basename}_LIBRARY)
562         SET(QT_${basename}_FOUND 1)
563       ENDIF (QT_${basename}_LIBRARY)
564
565     ENDIF (QT_${basename}_LIBRARY_RELEASE OR QT_${basename}_LIBRARY_DEBUG)
566
567     IF (QT_${basename}_INCLUDE_DIR)
568       #add the include directory to QT_INCLUDES
569       SET(QT_INCLUDES "${QT_${basename}_INCLUDE_DIR}" ${QT_INCLUDES})
570     ENDIF (QT_${basename}_INCLUDE_DIR)
571
572     # Make variables changeble to the advanced user
573     MARK_AS_ADVANCED(QT_${basename}_LIBRARY QT_${basename}_LIBRARY_RELEASE QT_${basename}_LIBRARY_DEBUG QT_${basename}_INCLUDE_DIR)
574   ENDMACRO (_QT4_ADJUST_LIB_VARS)
575   # Set QT_xyz_LIBRARY variable and add 
576   # library include path to QT_INCLUDES
577   _QT4_ADJUST_LIB_VARS(QTCORE)
578   _QT4_ADJUST_LIB_VARS(QTGUI)
579   _QT4_ADJUST_LIB_VARS(QT3SUPPORT)
580   _QT4_ADJUST_LIB_VARS(QTASSISTANT)
581   _QT4_ADJUST_LIB_VARS(QTDESIGNER)
582   _QT4_ADJUST_LIB_VARS(QTDESIGNERCOMPONENTS)
583   _QT4_ADJUST_LIB_VARS(QTNETWORK)
584   _QT4_ADJUST_LIB_VARS(QTNSPLUGIN)
585   _QT4_ADJUST_LIB_VARS(QTOPENGL)
586   _QT4_ADJUST_LIB_VARS(QTSQL)
587   _QT4_ADJUST_LIB_VARS(QTXML)
588   _QT4_ADJUST_LIB_VARS(QTSVG)
589   _QT4_ADJUST_LIB_VARS(QTSCRIPT)
590   _QT4_ADJUST_LIB_VARS(QTUITOOLS)
591   _QT4_ADJUST_LIB_VARS(QTTEST)
592   _QT4_ADJUST_LIB_VARS(QTDBUS)
593   _QT4_ADJUST_LIB_VARS(QTASSISTANTCLIENT)
594   _QT4_ADJUST_LIB_VARS(QTHELP)
595   _QT4_ADJUST_LIB_VARS(QTWEBKIT)
596   _QT4_ADJUST_LIB_VARS(QTXMLPATTERNS)
597   _QT4_ADJUST_LIB_VARS(PHONON)
598   _QT4_ADJUST_LIB_VARS(QTCLUCENE)
599 ELSEIF(NOT WIN32)
600         FIND_PACKAGE(Qt4 REQUIRED)              
601 ENDIF(WIN32)