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