Imported Upstream version 3.11.2
[platform/upstream/cmake.git] / Modules / Qt4Macros.cmake
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4 #.rst:
5 # Qt4Macros
6 # ---------
7 #
8 #
9 #
10 # This file is included by FindQt4.cmake, don't include it directly.
11
12 ######################################
13 #
14 #       Macros for building Qt files
15 #
16 ######################################
17
18
19 macro (QT4_EXTRACT_OPTIONS _qt4_files _qt4_options _qt4_target)
20   set(${_qt4_files})
21   set(${_qt4_options})
22   set(_QT4_DOING_OPTIONS FALSE)
23   set(_QT4_DOING_TARGET FALSE)
24   foreach(_currentArg ${ARGN})
25     if ("x${_currentArg}" STREQUAL "xOPTIONS")
26       set(_QT4_DOING_OPTIONS TRUE)
27     elseif ("x${_currentArg}" STREQUAL "xTARGET")
28       set(_QT4_DOING_TARGET TRUE)
29     else ()
30       if(_QT4_DOING_TARGET)
31         set(${_qt4_target} "${_currentArg}")
32       elseif(_QT4_DOING_OPTIONS)
33         list(APPEND ${_qt4_options} "${_currentArg}")
34       else()
35         list(APPEND ${_qt4_files} "${_currentArg}")
36       endif()
37     endif ()
38   endforeach()
39 endmacro ()
40
41
42 # macro used to create the names of output files preserving relative dirs
43 macro (QT4_MAKE_OUTPUT_FILE infile prefix ext outfile )
44   string(LENGTH ${CMAKE_CURRENT_BINARY_DIR} _binlength)
45   string(LENGTH ${infile} _infileLength)
46   set(_checkinfile ${CMAKE_CURRENT_SOURCE_DIR})
47   if(_infileLength GREATER _binlength)
48     string(SUBSTRING "${infile}" 0 ${_binlength} _checkinfile)
49     if(_checkinfile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
50       file(RELATIVE_PATH rel ${CMAKE_CURRENT_BINARY_DIR} ${infile})
51     else()
52       file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile})
53     endif()
54   else()
55     file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile})
56   endif()
57   if(WIN32 AND rel MATCHES "^([a-zA-Z]):(.*)$") # absolute path
58     set(rel "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}")
59   endif()
60   set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${rel}")
61   string(REPLACE ".." "__" _outfile ${_outfile})
62   get_filename_component(outpath ${_outfile} PATH)
63   get_filename_component(_outfile ${_outfile} NAME_WE)
64   file(MAKE_DIRECTORY ${outpath})
65   set(${outfile} ${outpath}/${prefix}${_outfile}.${ext})
66 endmacro ()
67
68
69 macro (QT4_GET_MOC_FLAGS _moc_flags)
70   set(${_moc_flags})
71   get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)
72
73   foreach(_current ${_inc_DIRS})
74     if("${_current}" MATCHES "\\.framework/?$")
75       string(REGEX REPLACE "/[^/]+\\.framework" "" framework_path "${_current}")
76       set(${_moc_flags} ${${_moc_flags}} "-F${framework_path}")
77     else()
78       set(${_moc_flags} ${${_moc_flags}} "-I${_current}")
79     endif()
80   endforeach()
81
82   get_directory_property(_defines COMPILE_DEFINITIONS)
83   foreach(_current ${_defines})
84     set(${_moc_flags} ${${_moc_flags}} "-D${_current}")
85   endforeach()
86
87   if(Q_WS_WIN)
88     set(${_moc_flags} ${${_moc_flags}} -DWIN32)
89   endif()
90
91 endmacro()
92
93
94 # helper macro to set up a moc rule
95 function (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options moc_target)
96   # For Windows, create a parameters file to work around command line length limit
97   # Pass the parameters in a file.  Set the working directory to
98   # be that containing the parameters file and reference it by
99   # just the file name.  This is necessary because the moc tool on
100   # MinGW builds does not seem to handle spaces in the path to the
101   # file given with the @ syntax.
102   get_filename_component(_moc_outfile_name "${outfile}" NAME)
103   get_filename_component(_moc_outfile_dir "${outfile}" PATH)
104   if(_moc_outfile_dir)
105     set(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir})
106   endif()
107   set (_moc_parameters_file ${outfile}_parameters)
108   set (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}")
109   string (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}")
110
111   if(moc_target)
112     set (_moc_parameters_file ${_moc_parameters_file}$<$<BOOL:$<CONFIGURATION>>:_$<CONFIGURATION>>)
113     set(targetincludes "$<TARGET_PROPERTY:${moc_target},INCLUDE_DIRECTORIES>")
114     set(targetdefines "$<TARGET_PROPERTY:${moc_target},COMPILE_DEFINITIONS>")
115
116     set(targetincludes "$<$<BOOL:${targetincludes}>:-I$<JOIN:${targetincludes},\n-I>\n>")
117     set(targetdefines "$<$<BOOL:${targetdefines}>:-D$<JOIN:${targetdefines},\n-D>\n>")
118
119     file (GENERATE
120       OUTPUT ${_moc_parameters_file}
121       CONTENT "${targetdefines}${targetincludes}${_moc_parameters}\n"
122     )
123
124     set(targetincludes)
125     set(targetdefines)
126   else()
127     set(CMAKE_CONFIGURABLE_FILE_CONTENT "${_moc_parameters}")
128     configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
129                    "${_moc_parameters_file}" @ONLY)
130   endif()
131
132   set(_moc_extra_parameters_file @${_moc_parameters_file})
133   add_custom_command(OUTPUT ${outfile}
134                       COMMAND Qt4::moc ${_moc_extra_parameters_file}
135                       DEPENDS ${infile} ${_moc_parameters_file}
136                       ${_moc_working_dir}
137                       VERBATIM)
138 endfunction ()
139
140
141 macro (QT4_GENERATE_MOC infile outfile )
142 # get include dirs and flags
143    QT4_GET_MOC_FLAGS(moc_flags)
144    get_filename_component(abs_infile ${infile} ABSOLUTE)
145    set(_outfile "${outfile}")
146    if(NOT IS_ABSOLUTE "${outfile}")
147      set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
148    endif()
149
150    if (${ARGC} GREATER 3 AND "x${ARGV2}" STREQUAL "xTARGET")
151       set(moc_target ${ARGV3})
152    endif()
153    QT4_CREATE_MOC_COMMAND(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}")
154    set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOMOC TRUE)  # don't run automoc on this file
155    set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOUIC TRUE)  # don't run autouic on this file
156 endmacro ()
157
158
159 # QT4_WRAP_CPP(outfiles inputfile ... )
160
161 macro (QT4_WRAP_CPP outfiles )
162   # get include dirs
163   QT4_GET_MOC_FLAGS(moc_flags)
164   QT4_EXTRACT_OPTIONS(moc_files moc_options moc_target ${ARGN})
165
166   foreach (it ${moc_files})
167     get_filename_component(it ${it} ABSOLUTE)
168     QT4_MAKE_OUTPUT_FILE(${it} moc_ cxx outfile)
169     QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags}" "${moc_options}" "${moc_target}")
170     set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOMOC TRUE)  # don't run automoc on this file
171     set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOUIC TRUE)  # don't run autouic on this file
172     set(${outfiles} ${${outfiles}} ${outfile})
173   endforeach()
174
175 endmacro ()
176
177
178 # QT4_WRAP_UI(outfiles inputfile ... )
179
180 macro (QT4_WRAP_UI outfiles )
181   QT4_EXTRACT_OPTIONS(ui_files ui_options ui_target ${ARGN})
182
183   foreach (it ${ui_files})
184     get_filename_component(outfile ${it} NAME_WE)
185     get_filename_component(infile ${it} ABSOLUTE)
186     set(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.h)
187     add_custom_command(OUTPUT ${outfile}
188       COMMAND Qt4::uic
189       ARGS ${ui_options} -o ${outfile} ${infile}
190       MAIN_DEPENDENCY ${infile} VERBATIM)
191     set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOMOC TRUE)  # don't run automoc on this file
192     set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOUIC TRUE)  # don't run autouic on this file
193     set(${outfiles} ${${outfiles}} ${outfile})
194   endforeach ()
195
196 endmacro ()
197
198
199 # QT4_ADD_RESOURCES(outfiles inputfile ... )
200
201 macro (QT4_ADD_RESOURCES outfiles )
202   QT4_EXTRACT_OPTIONS(rcc_files rcc_options rcc_target ${ARGN})
203
204   foreach (it ${rcc_files})
205     get_filename_component(outfilename ${it} NAME_WE)
206     get_filename_component(infile ${it} ABSOLUTE)
207     get_filename_component(rc_path ${infile} PATH)
208     set(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cxx)
209
210     set(_RC_DEPENDS)
211     if(EXISTS "${infile}")
212       #  parse file for dependencies
213       #  all files are absolute paths or relative to the location of the qrc file
214       file(READ "${infile}" _RC_FILE_CONTENTS)
215       string(REGEX MATCHALL "<file[^<]+" _RC_FILES "${_RC_FILE_CONTENTS}")
216       foreach(_RC_FILE ${_RC_FILES})
217         string(REGEX REPLACE "^<file[^>]*>" "" _RC_FILE "${_RC_FILE}")
218         if(NOT IS_ABSOLUTE "${_RC_FILE}")
219           set(_RC_FILE "${rc_path}/${_RC_FILE}")
220         endif()
221         set(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}")
222       endforeach()
223       unset(_RC_FILES)
224       unset(_RC_FILE_CONTENTS)
225       # Since this cmake macro is doing the dependency scanning for these files,
226       # let's make a configured file and add it as a dependency so cmake is run
227       # again when dependencies need to be recomputed.
228       QT4_MAKE_OUTPUT_FILE("${infile}" "" "qrc.depends" out_depends)
229       configure_file("${infile}" "${out_depends}" COPYONLY)
230     else()
231       # The .qrc file does not exist (yet). Let's add a dependency and hope
232       # that it will be generated later
233       set(out_depends)
234     endif()
235
236     add_custom_command(OUTPUT ${outfile}
237       COMMAND Qt4::rcc
238       ARGS ${rcc_options} -name ${outfilename} -o ${outfile} ${infile}
239       MAIN_DEPENDENCY ${infile}
240       DEPENDS ${_RC_DEPENDS} "${out_depends}" VERBATIM)
241     set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOMOC TRUE)  # don't run automoc on this file
242     set_property(SOURCE ${outfile} PROPERTY SKIP_AUTOUIC TRUE)  # don't run autouic on this file
243     set(${outfiles} ${${outfiles}} ${outfile})
244   endforeach ()
245
246 endmacro ()
247
248
249 macro(QT4_ADD_DBUS_INTERFACE _sources _interface _basename)
250   get_filename_component(_infile ${_interface} ABSOLUTE)
251   set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
252   set(_impl   "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
253   set(_moc    "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
254
255   get_property(_nonamespace SOURCE ${_interface} PROPERTY NO_NAMESPACE)
256   if(_nonamespace)
257     set(_params -N -m)
258   else()
259     set(_params -m)
260   endif()
261
262   get_property(_classname SOURCE ${_interface} PROPERTY CLASSNAME)
263   if(_classname)
264     set(_params ${_params} -c ${_classname})
265   endif()
266
267   get_property(_include SOURCE ${_interface} PROPERTY INCLUDE)
268   if(_include)
269     set(_params ${_params} -i ${_include})
270   endif()
271
272   add_custom_command(OUTPUT "${_impl}" "${_header}"
273       COMMAND Qt4::qdbusxml2cpp ${_params} -p ${_basename} ${_infile}
274       DEPENDS ${_infile} VERBATIM)
275
276   set_property(SOURCE ${_impl} PROPERTY SKIP_AUTOMOC TRUE)  # don't run automoc on this file
277   set_property(SOURCE ${_impl} PROPERTY SKIP_AUTOUIC TRUE)  # don't run autouic on this file
278
279   QT4_GENERATE_MOC("${_header}" "${_moc}")
280
281   list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
282   MACRO_ADD_FILE_DEPENDENCIES("${_impl}" "${_moc}")
283
284 endmacro()
285
286
287 macro(QT4_ADD_DBUS_INTERFACES _sources)
288   foreach (_current_FILE ${ARGN})
289     get_filename_component(_infile ${_current_FILE} ABSOLUTE)
290     get_filename_component(_basename ${_current_FILE} NAME)
291     # get the part before the ".xml" suffix
292     string(TOLOWER ${_basename} _basename)
293     string(REGEX REPLACE "(.*\\.)?([^\\.]+)\\.xml" "\\2" _basename ${_basename})
294     QT4_ADD_DBUS_INTERFACE(${_sources} ${_infile} ${_basename}interface)
295   endforeach ()
296 endmacro()
297
298
299 macro(QT4_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options )
300   QT4_EXTRACT_OPTIONS(_customName _qt4_dbus_options _qt4_dbus_target ${ARGN})
301
302   get_filename_component(_in_file ${_header} ABSOLUTE)
303   get_filename_component(_basename ${_header} NAME_WE)
304
305   if (_customName)
306     if (IS_ABSOLUTE ${_customName})
307       get_filename_component(_containingDir ${_customName} PATH)
308       if (NOT EXISTS ${_containingDir})
309         file(MAKE_DIRECTORY "${_containingDir}")
310       endif()
311       set(_target ${_customName})
312     else()
313       set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName})
314     endif()
315   else ()
316     set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml)
317   endif ()
318
319   add_custom_command(OUTPUT ${_target}
320       COMMAND Qt4::qdbuscpp2xml ${_qt4_dbus_options} ${_in_file} -o ${_target}
321       DEPENDS ${_in_file} VERBATIM
322   )
323 endmacro()
324
325
326 macro(QT4_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName)
327   get_filename_component(_infile ${_xml_file} ABSOLUTE)
328
329   unset(_optionalBasename)
330   if(${ARGC} GREATER 4)
331     set(_optionalBasename "${ARGV4}")
332   endif()
333   if (_optionalBasename)
334     set(_basename ${_optionalBasename} )
335   else ()
336     string(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile})
337     string(TOLOWER ${_basename} _basename)
338   endif ()
339
340   unset(_optionalClassName)
341   if(${ARGC} GREATER 5)
342     set(_optionalClassName "${ARGV5}")
343   endif()
344   set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
345   set(_impl   "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
346   set(_moc    "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
347
348   if(_optionalClassName)
349     add_custom_command(OUTPUT "${_impl}" "${_header}"
350        COMMAND Qt4::qdbusxml2cpp -m -a ${_basename} -c ${_optionalClassName} -i ${_include} -l ${_parentClass} ${_infile}
351        DEPENDS ${_infile} VERBATIM
352     )
353   else()
354     add_custom_command(OUTPUT "${_impl}" "${_header}"
355        COMMAND Qt4::qdbusxml2cpp -m -a ${_basename} -i ${_include} -l ${_parentClass} ${_infile}
356        DEPENDS ${_infile} VERBATIM
357      )
358   endif()
359
360   QT4_GENERATE_MOC("${_header}" "${_moc}")
361   set_property(SOURCE ${_impl} PROPERTY SKIP_AUTOMOC TRUE)  # don't run automoc on this file
362   set_property(SOURCE ${_impl} PROPERTY SKIP_AUTOUIC TRUE)  # don't run autouic on this file
363   MACRO_ADD_FILE_DEPENDENCIES("${_impl}" "${_moc}")
364
365   list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
366 endmacro()
367
368
369 macro(QT4_AUTOMOC)
370   if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.11)
371     message(DEPRECATION "The qt4_automoc macro is obsolete. Use the CMAKE_AUTOMOC feature instead.")
372   endif()
373   QT4_GET_MOC_FLAGS(_moc_INCS)
374
375   set(_matching_FILES )
376   foreach (_current_FILE ${ARGN})
377
378     get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
379     # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
380     # This is required to make uic work correctly:
381     # we need to add generated .cpp files to the sources (to compile them),
382     # but we cannot let automoc handle them, as the .cpp files don't exist yet when
383     # cmake is run for the very first time on them -> however the .cpp files might
384     # exist at a later run. at that time we need to skip them, so that we don't add two
385     # different rules for the same moc file
386     get_property(_skip SOURCE ${_abs_FILE} PROPERTY SKIP_AUTOMOC)
387
388     if ( NOT _skip AND EXISTS ${_abs_FILE} )
389
390       file(READ ${_abs_FILE} _contents)
391
392       get_filename_component(_abs_PATH ${_abs_FILE} PATH)
393
394       string(REGEX MATCHALL "# *include +[^ ]+\\.moc[\">]" _match "${_contents}")
395       if(_match)
396         foreach (_current_MOC_INC ${_match})
397           string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
398
399           get_filename_component(_basename ${_current_MOC} NAME_WE)
400           if(EXISTS ${_abs_PATH}/${_basename}.hpp)
401             set(_header ${_abs_PATH}/${_basename}.hpp)
402           else()
403             set(_header ${_abs_PATH}/${_basename}.h)
404           endif()
405           set(_moc    ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
406           QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "" "")
407           MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
408         endforeach ()
409       endif()
410     endif ()
411   endforeach ()
412 endmacro()
413
414
415 macro(QT4_CREATE_TRANSLATION _qm_files)
416    QT4_EXTRACT_OPTIONS(_lupdate_files _lupdate_options _lupdate_target ${ARGN})
417    set(_my_sources)
418    set(_my_dirs)
419    set(_my_tsfiles)
420    set(_ts_pro)
421    foreach (_file ${_lupdate_files})
422      get_filename_component(_ext ${_file} EXT)
423      get_filename_component(_abs_FILE ${_file} ABSOLUTE)
424      if(_ext MATCHES "ts")
425        list(APPEND _my_tsfiles ${_abs_FILE})
426      else()
427        if(NOT _ext)
428          list(APPEND _my_dirs ${_abs_FILE})
429        else()
430          list(APPEND _my_sources ${_abs_FILE})
431        endif()
432      endif()
433    endforeach()
434    foreach(_ts_file ${_my_tsfiles})
435      if(_my_sources)
436        # make a .pro file to call lupdate on, so we don't make our commands too
437        # long for some systems
438        get_filename_component(_ts_name ${_ts_file} NAME_WE)
439        set(_ts_pro ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_ts_name}_lupdate.pro)
440        set(_pro_srcs)
441        foreach(_pro_src ${_my_sources})
442          string(APPEND _pro_srcs " \\\n  \"${_pro_src}\"")
443        endforeach()
444        set(_pro_includes)
445        get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)
446        list(REMOVE_DUPLICATES _inc_DIRS)
447        foreach(_pro_include ${_inc_DIRS})
448          get_filename_component(_abs_include "${_pro_include}" ABSOLUTE)
449          string(APPEND _pro_includes " \\\n  \"${_abs_include}\"")
450        endforeach()
451        file(GENERATE OUTPUT ${_ts_pro} CONTENT "SOURCES =${_pro_srcs}\nINCLUDEPATH =${_pro_includes}\n")
452      endif()
453      add_custom_command(OUTPUT ${_ts_file}
454         COMMAND Qt4::lupdate
455         ARGS ${_lupdate_options} ${_ts_pro} ${_my_dirs} -ts ${_ts_file}
456         DEPENDS ${_my_sources} ${_ts_pro} VERBATIM)
457    endforeach()
458    QT4_ADD_TRANSLATION(${_qm_files} ${_my_tsfiles})
459 endmacro()
460
461
462 macro(QT4_ADD_TRANSLATION _qm_files)
463   foreach (_current_FILE ${ARGN})
464     get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
465     get_filename_component(qm ${_abs_FILE} NAME_WE)
466     get_property(output_location SOURCE ${_abs_FILE} PROPERTY OUTPUT_LOCATION)
467     if(output_location)
468       file(MAKE_DIRECTORY "${output_location}")
469       set(qm "${output_location}/${qm}.qm")
470     else()
471       set(qm "${CMAKE_CURRENT_BINARY_DIR}/${qm}.qm")
472     endif()
473
474     add_custom_command(OUTPUT ${qm}
475        COMMAND Qt4::lrelease
476        ARGS ${_abs_FILE} -qm ${qm}
477        DEPENDS ${_abs_FILE} VERBATIM
478     )
479     set(${_qm_files} ${${_qm_files}} ${qm})
480   endforeach ()
481 endmacro()
482
483 function(qt4_use_modules _target _link_type)
484   if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.11)
485     message(DEPRECATION "The qt4_use_modules function is obsolete. Use target_link_libraries with IMPORTED targets instead.")
486   endif()
487   if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE")
488     set(modules ${ARGN})
489     set(link_type ${_link_type})
490   else()
491     set(modules ${_link_type} ${ARGN})
492   endif()
493   foreach(_module ${modules})
494     string(TOUPPER ${_module} _ucmodule)
495     set(_targetPrefix QT_QT${_ucmodule})
496     if (_ucmodule STREQUAL QAXCONTAINER OR _ucmodule STREQUAL QAXSERVER)
497       if (NOT QT_Q${_ucmodule}_FOUND)
498         message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
499       endif()
500       set(_targetPrefix QT_Q${_ucmodule})
501     else()
502       if (NOT QT_QT${_ucmodule}_FOUND)
503         message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
504       endif()
505       if ("${_ucmodule}" STREQUAL "MAIN")
506         message(FATAL_ERROR "Can not use \"${_module}\" module with qt4_use_modules.")
507       endif()
508     endif()
509     target_link_libraries(${_target} ${link_type} ${${_targetPrefix}_LIBRARIES})
510     set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${${_targetPrefix}_INCLUDE_DIR} ${QT_HEADERS_DIR} ${QT_MKSPECS_DIR}/default)
511     set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS ${${_targetPrefix}_COMPILE_DEFINITIONS})
512   endforeach()
513 endfunction()