Qt4Macros.cmake 18.1 KB
Newer Older
1 2 3 4 5 6
#.rst:
# Qt4Macros
# ---------
#
#
#
7 8 9 10 11 12 13 14 15 16 17 18
# This file is included by FindQt4.cmake, don't include it directly.

#=============================================================================
# Copyright 2005-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
19
# (To distribute this file outside of CMake, substitute the full
20 21 22 23 24 25 26 27 28 29
#  License text for the above reference.)


######################################
#
#       Macros for building Qt files
#
######################################


30
macro (QT4_EXTRACT_OPTIONS _qt4_files _qt4_options _qt4_target)
31 32 33
  set(${_qt4_files})
  set(${_qt4_options})
  set(_QT4_DOING_OPTIONS FALSE)
34
  set(_QT4_DOING_TARGET FALSE)
35
  foreach(_currentArg ${ARGN})
36
    if ("x${_currentArg}" STREQUAL "xOPTIONS")
37
      set(_QT4_DOING_OPTIONS TRUE)
38 39
    elseif ("x${_currentArg}" STREQUAL "xTARGET")
      set(_QT4_DOING_TARGET TRUE)
40
    else ()
41 42 43
      if(_QT4_DOING_TARGET)
        set(${_qt4_target} "${_currentArg}")
      elseif(_QT4_DOING_OPTIONS)
44
        list(APPEND ${_qt4_options} "${_currentArg}")
45
      else()
46
        list(APPEND ${_qt4_files} "${_currentArg}")
47 48 49 50
      endif()
    endif ()
  endforeach()
endmacro ()
51 52 53


# macro used to create the names of output files preserving relative dirs
54 55 56 57 58 59 60 61
macro (QT4_MAKE_OUTPUT_FILE infile prefix ext outfile )
  string(LENGTH ${CMAKE_CURRENT_BINARY_DIR} _binlength)
  string(LENGTH ${infile} _infileLength)
  set(_checkinfile ${CMAKE_CURRENT_SOURCE_DIR})
  if(_infileLength GREATER _binlength)
    string(SUBSTRING "${infile}" 0 ${_binlength} _checkinfile)
    if(_checkinfile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
      file(RELATIVE_PATH rel ${CMAKE_CURRENT_BINARY_DIR} ${infile})
62
    else()
63
      file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile})
64 65
    endif()
  else()
66
    file(RELATIVE_PATH rel ${CMAKE_CURRENT_SOURCE_DIR} ${infile})
67
  endif()
68 69
  if(WIN32 AND rel MATCHES "^([a-zA-Z]):(.*)$") # absolute path
    set(rel "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}")
70
  endif()
71 72 73 74 75 76
  set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${rel}")
  string(REPLACE ".." "__" _outfile ${_outfile})
  get_filename_component(outpath ${_outfile} PATH)
  get_filename_component(_outfile ${_outfile} NAME_WE)
  file(MAKE_DIRECTORY ${outpath})
  set(${outfile} ${outpath}/${prefix}${_outfile}.${ext})
77
endmacro ()
78 79 80 81 82 83 84 85 86 87


macro (QT4_GET_MOC_FLAGS _moc_flags)
  set(${_moc_flags})
  get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)

  foreach(_current ${_inc_DIRS})
    if("${_current}" MATCHES "\\.framework/?$")
      string(REGEX REPLACE "/[^/]+\\.framework" "" framework_path "${_current}")
      set(${_moc_flags} ${${_moc_flags}} "-F${framework_path}")
88
    else()
89
      set(${_moc_flags} ${${_moc_flags}} "-I${_current}")
90 91
    endif()
  endforeach()
92 93 94 95

  get_directory_property(_defines COMPILE_DEFINITIONS)
  foreach(_current ${_defines})
    set(${_moc_flags} ${${_moc_flags}} "-D${_current}")
96
  endforeach()
97 98 99

  if(Q_WS_WIN)
    set(${_moc_flags} ${${_moc_flags}} -DWIN32)
100
  endif()
101

102
endmacro()
103 104 105


# helper macro to set up a moc rule
106
function (QT4_CREATE_MOC_COMMAND infile outfile moc_flags moc_options moc_target)
107
  # For Windows, create a parameters file to work around command line length limit
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
  # Pass the parameters in a file.  Set the working directory to
  # be that containing the parameters file and reference it by
  # just the file name.  This is necessary because the moc tool on
  # MinGW builds does not seem to handle spaces in the path to the
  # file given with the @ syntax.
  get_filename_component(_moc_outfile_name "${outfile}" NAME)
  get_filename_component(_moc_outfile_dir "${outfile}" PATH)
  if(_moc_outfile_dir)
    set(_moc_working_dir WORKING_DIRECTORY ${_moc_outfile_dir})
  endif()
  set (_moc_parameters_file ${outfile}_parameters)
  set (_moc_parameters ${moc_flags} ${moc_options} -o "${outfile}" "${infile}")
  string (REPLACE ";" "\n" _moc_parameters "${_moc_parameters}")

  if(moc_target)
123
    set (_moc_parameters_file ${_moc_parameters_file}$<$<BOOL:$<CONFIGURATION>>:_$<CONFIGURATION>>)
124 125
    set(targetincludes "$<TARGET_PROPERTY:${moc_target},INCLUDE_DIRECTORIES>")
    set(targetdefines "$<TARGET_PROPERTY:${moc_target},COMPILE_DEFINITIONS>")
126 127 128 129 130 131

    set(targetincludes "$<$<BOOL:${targetincludes}>:-I$<JOIN:${targetincludes},\n-I>\n>")
    set(targetdefines "$<$<BOOL:${targetdefines}>:-D$<JOIN:${targetdefines},\n-D>\n>")

    file (GENERATE
      OUTPUT ${_moc_parameters_file}
132
      CONTENT "${targetdefines}${targetincludes}${_moc_parameters}\n"
133 134 135 136 137
    )

    set(targetincludes)
    set(targetdefines)
  else()
138 139 140
    set(CMAKE_CONFIGURABLE_FILE_CONTENT "${_moc_parameters}")
    configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
                   "${_moc_parameters_file}" @ONLY)
141 142 143 144
  endif()

  set(_moc_extra_parameters_file @${_moc_parameters_file})
  add_custom_command(OUTPUT ${outfile}
145
                      COMMAND Qt4::moc ${_moc_extra_parameters_file}
146
                      DEPENDS ${infile} ${_moc_parameters_file}
147 148
                      ${_moc_working_dir}
                      VERBATIM)
149
endfunction ()
150 151


152
macro (QT4_GENERATE_MOC infile outfile )
153 154
# get include dirs and flags
   QT4_GET_MOC_FLAGS(moc_flags)
155 156 157 158
   get_filename_component(abs_infile ${infile} ABSOLUTE)
   set(_outfile "${outfile}")
   if(NOT IS_ABSOLUTE "${outfile}")
     set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
159
   endif()
160

161
   if (${ARGC} GREATER 3 AND "x${ARGV2}" STREQUAL "xTARGET")
162 163 164
      set(moc_target ${ARGV3})
   endif()
   QT4_CREATE_MOC_COMMAND(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}")
165
   set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE)  # dont run automoc on this file
166
endmacro ()
167 168 169 170


# QT4_WRAP_CPP(outfiles inputfile ... )

171
macro (QT4_WRAP_CPP outfiles )
172 173
  # get include dirs
  QT4_GET_MOC_FLAGS(moc_flags)
174
  QT4_EXTRACT_OPTIONS(moc_files moc_options moc_target ${ARGN})
175

176 177
  foreach (it ${moc_files})
    get_filename_component(it ${it} ABSOLUTE)
178
    QT4_MAKE_OUTPUT_FILE(${it} moc_ cxx outfile)
179
    QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags}" "${moc_options}" "${moc_target}")
180
    set(${outfiles} ${${outfiles}} ${outfile})
181
  endforeach()
182

183
endmacro ()
184 185 186 187


# QT4_WRAP_UI(outfiles inputfile ... )

188
macro (QT4_WRAP_UI outfiles )
189
  QT4_EXTRACT_OPTIONS(ui_files ui_options ui_target ${ARGN})
190

191 192 193 194 195
  foreach (it ${ui_files})
    get_filename_component(outfile ${it} NAME_WE)
    get_filename_component(infile ${it} ABSOLUTE)
    set(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.h)
    add_custom_command(OUTPUT ${outfile}
196
      COMMAND Qt4::uic
197
      ARGS ${ui_options} -o ${outfile} ${infile}
198
      MAIN_DEPENDENCY ${infile} VERBATIM)
199
    set(${outfiles} ${${outfiles}} ${outfile})
200
  endforeach ()
201

202
endmacro ()
203 204 205 206


# QT4_ADD_RESOURCES(outfiles inputfile ... )

207
macro (QT4_ADD_RESOURCES outfiles )
208
  QT4_EXTRACT_OPTIONS(rcc_files rcc_options rcc_target ${ARGN})
209

210 211 212 213 214
  foreach (it ${rcc_files})
    get_filename_component(outfilename ${it} NAME_WE)
    get_filename_component(infile ${it} ABSOLUTE)
    get_filename_component(rc_path ${infile} PATH)
    set(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cxx)
215

216 217
    set(_RC_DEPENDS)
    if(EXISTS "${infile}")
218 219
      #  parse file for dependencies
      #  all files are absolute paths or relative to the location of the qrc file
220
      file(READ "${infile}" _RC_FILE_CONTENTS)
221 222 223
      string(REGEX MATCHALL "<file[^<]+" _RC_FILES "${_RC_FILE_CONTENTS}")
      foreach(_RC_FILE ${_RC_FILES})
        string(REGEX REPLACE "^<file[^>]*>" "" _RC_FILE "${_RC_FILE}")
224 225
        if(NOT IS_ABSOLUTE "${_RC_FILE}")
          set(_RC_FILE "${rc_path}/${_RC_FILE}")
226
        endif()
227
        set(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}")
228
      endforeach()
229
      unset(_RC_FILES)
230
      unset(_RC_FILE_CONTENTS)
231 232 233 234
      # Since this cmake macro is doing the dependency scanning for these files,
      # let's make a configured file and add it as a dependency so cmake is run
      # again when dependencies need to be recomputed.
      QT4_MAKE_OUTPUT_FILE("${infile}" "" "qrc.depends" out_depends)
235
      configure_file("${infile}" "${out_depends}" COPYONLY)
236
    else()
237 238
      # The .qrc file does not exist (yet). Let's add a dependency and hope
      # that it will be generated later
239
      set(out_depends)
240
    endif()
241

242
    add_custom_command(OUTPUT ${outfile}
243
      COMMAND Qt4::rcc
244 245
      ARGS ${rcc_options} -name ${outfilename} -o ${outfile} ${infile}
      MAIN_DEPENDENCY ${infile}
246
      DEPENDS ${_RC_DEPENDS} "${out_depends}" VERBATIM)
247
    set(${outfiles} ${${outfiles}} ${outfile})
248
  endforeach ()
249

250
endmacro ()
251 252


253 254 255 256 257
macro(QT4_ADD_DBUS_INTERFACE _sources _interface _basename)
  get_filename_component(_infile ${_interface} ABSOLUTE)
  set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
  set(_impl   "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
  set(_moc    "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
258

259 260 261
  get_source_file_property(_nonamespace ${_interface} NO_NAMESPACE)
  if(_nonamespace)
    set(_params -N -m)
262
  else()
263
    set(_params -m)
264
  endif()
265

266 267 268
  get_source_file_property(_classname ${_interface} CLASSNAME)
  if(_classname)
    set(_params ${_params} -c ${_classname})
269
  endif()
270

271 272 273
  get_source_file_property(_include ${_interface} INCLUDE)
  if(_include)
    set(_params ${_params} -i ${_include})
274
  endif()
275

276
  add_custom_command(OUTPUT "${_impl}" "${_header}"
277
      COMMAND Qt4::qdbusxml2cpp ${_params} -p ${_basename} ${_infile}
278
      DEPENDS ${_infile} VERBATIM)
279

280
  set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
281

282
  QT4_GENERATE_MOC("${_header}" "${_moc}")
283

284
  list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
285
  MACRO_ADD_FILE_DEPENDENCIES("${_impl}" "${_moc}")
286

287
endmacro()
288 289


290 291 292 293
macro(QT4_ADD_DBUS_INTERFACES _sources)
  foreach (_current_FILE ${ARGN})
    get_filename_component(_infile ${_current_FILE} ABSOLUTE)
    get_filename_component(_basename ${_current_FILE} NAME)
294
    # get the part before the ".xml" suffix
295 296
    string(TOLOWER ${_basename} _basename)
    string(REGEX REPLACE "(.*\\.)?([^\\.]+)\\.xml" "\\2" _basename ${_basename})
297
    QT4_ADD_DBUS_INTERFACE(${_sources} ${_infile} ${_basename}interface)
298 299
  endforeach ()
endmacro()
300 301


302
macro(QT4_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options )
303
  QT4_EXTRACT_OPTIONS(_customName _qt4_dbus_options _qt4_dbus_target ${ARGN})
304

305 306
  get_filename_component(_in_file ${_header} ABSOLUTE)
  get_filename_component(_basename ${_header} NAME_WE)
307

308
  if (_customName)
309 310 311 312 313
    if (IS_ABSOLUTE ${_customName})
      get_filename_component(_containingDir ${_customName} PATH)
      if (NOT EXISTS ${_containingDir})
        file(MAKE_DIRECTORY "${_containingDir}")
      endif()
314
      set(_target ${_customName})
315
    else()
316
      set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName})
317
    endif()
318
  else ()
319
    set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml)
320
  endif ()
321

322
  add_custom_command(OUTPUT ${_target}
323
      COMMAND Qt4::qdbuscpp2xml ${_qt4_dbus_options} ${_in_file} -o ${_target}
324
      DEPENDS ${_in_file} VERBATIM
325
  )
326
endmacro()
327 328


329 330
macro(QT4_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName)
  get_filename_component(_infile ${_xml_file} ABSOLUTE)
331

332 333 334 335
  unset(_optionalBasename)
  if(${ARGC} GREATER 4)
    set(_optionalBasename "${ARGV4}")
  endif()
336 337
  if (_optionalBasename)
    set(_basename ${_optionalBasename} )
338
  else ()
339 340
    string(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile})
    string(TOLOWER ${_basename} _basename)
341
  endif ()
342

343 344 345 346
  unset(_optionalClassName)
  if(${ARGC} GREATER 5)
    set(_optionalClassName "${ARGV5}")
  endif()
347 348 349
  set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
  set(_impl   "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
  set(_moc    "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
350

351 352
  if(_optionalClassName)
    add_custom_command(OUTPUT "${_impl}" "${_header}"
353
       COMMAND Qt4::qdbusxml2cpp -m -a ${_basename} -c ${_optionalClassName} -i ${_include} -l ${_parentClass} ${_infile}
354
       DEPENDS ${_infile} VERBATIM
355
    )
356
  else()
357
    add_custom_command(OUTPUT "${_impl}" "${_header}"
358
       COMMAND Qt4::qdbusxml2cpp -m -a ${_basename} -i ${_include} -l ${_parentClass} ${_infile}
359
       DEPENDS ${_infile} VERBATIM
360
     )
361
  endif()
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
  list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
368
endmacro()
369 370


371
macro(QT4_AUTOMOC)
372
  if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.11)
373
    message(DEPRECATION "The qt4_automoc macro is obsolete. Use the CMAKE_AUTOMOC feature instead.")
374
  endif()
375 376
  QT4_GET_MOC_FLAGS(_moc_INCS)

377 378
  set(_matching_FILES )
  foreach (_current_FILE ${ARGN})
379

380
    get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
381 382 383 384 385 386 387
    # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
    # This is required to make uic work correctly:
    # we need to add generated .cpp files to the sources (to compile them),
    # but we cannot let automoc handle them, as the .cpp files don't exist yet when
    # cmake is run for the very first time on them -> however the .cpp files might
    # exist at a later run. at that time we need to skip them, so that we don't add two
    # different rules for the same moc file
388
    get_source_file_property(_skip ${_abs_FILE} SKIP_AUTOMOC)
389

390
    if ( NOT _skip AND EXISTS ${_abs_FILE} )
391

392
      file(READ ${_abs_FILE} _contents)
393

394
      get_filename_component(_abs_PATH ${_abs_FILE} PATH)
395

396 397 398 399
      string(REGEX MATCHALL "# *include +[^ ]+\\.moc[\">]" _match "${_contents}")
      if(_match)
        foreach (_current_MOC_INC ${_match})
          string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
400

401 402 403
          get_filename_component(_basename ${_current_MOC} NAME_WE)
          if(EXISTS ${_abs_PATH}/${_basename}.hpp)
            set(_header ${_abs_PATH}/${_basename}.hpp)
404
          else()
405
            set(_header ${_abs_PATH}/${_basename}.h)
406
          endif()
407
          set(_moc    ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
408
          QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "" "")
409
          MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
410 411 412 413 414
        endforeach ()
      endif()
    endif ()
  endforeach ()
endmacro()
415 416


417
macro(QT4_CREATE_TRANSLATION _qm_files)
418
   QT4_EXTRACT_OPTIONS(_lupdate_files _lupdate_options _lupdate_target ${ARGN})
419 420 421 422 423 424 425 426 427
   set(_my_sources)
   set(_my_dirs)
   set(_my_tsfiles)
   set(_ts_pro)
   foreach (_file ${_lupdate_files})
     get_filename_component(_ext ${_file} EXT)
     get_filename_component(_abs_FILE ${_file} ABSOLUTE)
     if(_ext MATCHES "ts")
       list(APPEND _my_tsfiles ${_abs_FILE})
428
     else()
429 430
       if(NOT _ext)
         list(APPEND _my_dirs ${_abs_FILE})
431
       else()
432
         list(APPEND _my_sources ${_abs_FILE})
433 434 435
       endif()
     endif()
   endforeach()
436 437
   foreach(_ts_file ${_my_tsfiles})
     if(_my_sources)
438 439
       # make a .pro file to call lupdate on, so we don't make our commands too
       # long for some systems
440 441 442 443
       get_filename_component(_ts_name ${_ts_file} NAME_WE)
       set(_ts_pro ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_ts_name}_lupdate.pro)
       set(_pro_srcs)
       foreach(_pro_src ${_my_sources})
444
         set(_pro_srcs "${_pro_srcs} \\\n  \"${_pro_src}\"")
445
       endforeach()
446 447
       set(_pro_includes)
       get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)
448
       list(REMOVE_DUPLICATES _inc_DIRS)
449 450
       foreach(_pro_include ${_inc_DIRS})
         get_filename_component(_abs_include "${_pro_include}" ABSOLUTE)
451
         set(_pro_includes "${_pro_includes} \\\n  \"${_abs_include}\"")
452
       endforeach()
453
       file(WRITE ${_ts_pro} "SOURCES =${_pro_srcs}\nINCLUDEPATH =${_pro_includes}\n")
454
     endif()
455
     add_custom_command(OUTPUT ${_ts_file}
456
        COMMAND Qt4::lupdate
457
        ARGS ${_lupdate_options} ${_ts_pro} ${_my_dirs} -ts ${_ts_file}
458
        DEPENDS ${_my_sources} ${_ts_pro} VERBATIM)
459
   endforeach()
460
   QT4_ADD_TRANSLATION(${_qm_files} ${_my_tsfiles})
461
endmacro()
462 463 464 465 466 467 468 469 470 471


macro(QT4_ADD_TRANSLATION _qm_files)
  foreach (_current_FILE ${ARGN})
    get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
    get_filename_component(qm ${_abs_FILE} NAME_WE)
    get_source_file_property(output_location ${_abs_FILE} OUTPUT_LOCATION)
    if(output_location)
      file(MAKE_DIRECTORY "${output_location}")
      set(qm "${output_location}/${qm}.qm")
472
    else()
473
      set(qm "${CMAKE_CURRENT_BINARY_DIR}/${qm}.qm")
474
    endif()
475 476

    add_custom_command(OUTPUT ${qm}
477
       COMMAND Qt4::lrelease
478
       ARGS ${_abs_FILE} -qm ${qm}
479
       DEPENDS ${_abs_FILE} VERBATIM
480
    )
481
    set(${_qm_files} ${${_qm_files}} ${qm})
482 483
  endforeach ()
endmacro()
484 485

function(qt4_use_modules _target _link_type)
486
  if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.11)
487
    message(DEPRECATION "The qt4_use_modules function is obsolete. Use target_link_libraries with IMPORTED targets instead.")
488
  endif()
489 490 491 492 493 494 495 496
  if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE")
    set(modules ${ARGN})
    set(link_type ${_link_type})
  else()
    set(modules ${_link_type} ${ARGN})
  endif()
  foreach(_module ${modules})
    string(TOUPPER ${_module} _ucmodule)
497 498 499 500 501 502 503 504 505 506 507 508 509
    set(_targetPrefix QT_QT${_ucmodule})
    if (_ucmodule STREQUAL QAXCONTAINER OR _ucmodule STREQUAL QAXSERVER)
      if (NOT QT_Q${_ucmodule}_FOUND)
        message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
      endif()
      set(_targetPrefix QT_Q${_ucmodule})
    else()
      if (NOT QT_QT${_ucmodule}_FOUND)
        message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
      endif()
      if ("${_ucmodule}" STREQUAL "MAIN")
        message(FATAL_ERROR "Can not use \"${_module}\" module with qt4_use_modules.")
      endif()
510
    endif()
511 512 513
    target_link_libraries(${_target} ${link_type} ${${_targetPrefix}_LIBRARIES})
    set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${${_targetPrefix}_INCLUDE_DIR} ${QT_HEADERS_DIR} ${QT_MKSPECS_DIR}/default)
    set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS ${${_targetPrefix}_COMPILE_DEFINITIONS})
514 515
  endforeach()
endfunction()