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