Qt4Macros.cmake 18 KB

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