Qt4Macros.cmake 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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 (_moc_parameters_file ${_moc_parameters_file}$<$<BOOL:$<CONFIGURATION>>:_$<CONFIGURATION>>)
  108. set(targetincludes "$<TARGET_PROPERTY:${moc_target},INCLUDE_DIRECTORIES>")
  109. set(targetdefines "$<TARGET_PROPERTY:${moc_target},COMPILE_DEFINITIONS>")
  110. set(targetincludes "$<$<BOOL:${targetincludes}>:-I$<JOIN:${targetincludes},\n-I>\n>")
  111. set(targetdefines "$<$<BOOL:${targetdefines}>:-D$<JOIN:${targetdefines},\n-D>\n>")
  112. file (GENERATE
  113. OUTPUT ${_moc_parameters_file}
  114. CONTENT "${targetdefines}${targetincludes}${_moc_parameters}\n"
  115. )
  116. set(targetincludes)
  117. set(targetdefines)
  118. else()
  119. file(WRITE ${_moc_parameters_file} "${_moc_parameters}\n")
  120. endif()
  121. set(_moc_extra_parameters_file @${_moc_parameters_file})
  122. add_custom_command(OUTPUT ${outfile}
  123. COMMAND ${QT_MOC_EXECUTABLE} ${_moc_extra_parameters_file}
  124. DEPENDS ${infile}
  125. ${_moc_working_dir}
  126. VERBATIM)
  127. endmacro ()
  128. macro (QT4_GENERATE_MOC infile outfile )
  129. # get include dirs and flags
  130. QT4_GET_MOC_FLAGS(moc_flags)
  131. get_filename_component(abs_infile ${infile} ABSOLUTE)
  132. set(_outfile "${outfile}")
  133. if(NOT IS_ABSOLUTE "${outfile}")
  134. set(_outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}")
  135. endif()
  136. if ("x${ARGV2}" STREQUAL "xTARGET")
  137. set(moc_target ${ARGV3})
  138. endif()
  139. QT4_CREATE_MOC_COMMAND(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}")
  140. set_source_files_properties(${outfile} PROPERTIES SKIP_AUTOMOC TRUE) # dont run automoc on this file
  141. endmacro ()
  142. # QT4_WRAP_CPP(outfiles inputfile ... )
  143. macro (QT4_WRAP_CPP outfiles )
  144. # get include dirs
  145. QT4_GET_MOC_FLAGS(moc_flags)
  146. QT4_EXTRACT_OPTIONS(moc_files moc_options moc_target ${ARGN})
  147. foreach (it ${moc_files})
  148. get_filename_component(it ${it} ABSOLUTE)
  149. QT4_MAKE_OUTPUT_FILE(${it} moc_ cxx outfile)
  150. QT4_CREATE_MOC_COMMAND(${it} ${outfile} "${moc_flags}" "${moc_options}" "${moc_target}")
  151. set(${outfiles} ${${outfiles}} ${outfile})
  152. endforeach()
  153. endmacro ()
  154. # QT4_WRAP_UI(outfiles inputfile ... )
  155. macro (QT4_WRAP_UI outfiles )
  156. QT4_EXTRACT_OPTIONS(ui_files ui_options ui_target ${ARGN})
  157. foreach (it ${ui_files})
  158. get_filename_component(outfile ${it} NAME_WE)
  159. get_filename_component(infile ${it} ABSOLUTE)
  160. set(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.h)
  161. add_custom_command(OUTPUT ${outfile}
  162. COMMAND ${QT_UIC_EXECUTABLE}
  163. ARGS ${ui_options} -o ${outfile} ${infile}
  164. MAIN_DEPENDENCY ${infile} VERBATIM)
  165. set(${outfiles} ${${outfiles}} ${outfile})
  166. endforeach ()
  167. endmacro ()
  168. # QT4_ADD_RESOURCES(outfiles inputfile ... )
  169. macro (QT4_ADD_RESOURCES outfiles )
  170. QT4_EXTRACT_OPTIONS(rcc_files rcc_options rcc_target ${ARGN})
  171. foreach (it ${rcc_files})
  172. get_filename_component(outfilename ${it} NAME_WE)
  173. get_filename_component(infile ${it} ABSOLUTE)
  174. get_filename_component(rc_path ${infile} PATH)
  175. set(outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${outfilename}.cxx)
  176. set(_RC_DEPENDS)
  177. if(EXISTS "${infile}")
  178. # parse file for dependencies
  179. # all files are absolute paths or relative to the location of the qrc file
  180. file(READ "${infile}" _RC_FILE_CONTENTS)
  181. string(REGEX MATCHALL "<file[^<]+" _RC_FILES "${_RC_FILE_CONTENTS}")
  182. foreach(_RC_FILE ${_RC_FILES})
  183. string(REGEX REPLACE "^<file[^>]*>" "" _RC_FILE "${_RC_FILE}")
  184. if(NOT IS_ABSOLUTE "${_RC_FILE}")
  185. set(_RC_FILE "${rc_path}/${_RC_FILE}")
  186. endif()
  187. set(_RC_DEPENDS ${_RC_DEPENDS} "${_RC_FILE}")
  188. endforeach()
  189. unset(_RC_FILES)
  190. unset(_RC_FILE_CONTENTS)
  191. # Since this cmake macro is doing the dependency scanning for these files,
  192. # let's make a configured file and add it as a dependency so cmake is run
  193. # again when dependencies need to be recomputed.
  194. QT4_MAKE_OUTPUT_FILE("${infile}" "" "qrc.depends" out_depends)
  195. configure_file("${infile}" "${out_depends}" COPY_ONLY)
  196. else()
  197. # The .qrc file does not exist (yet). Let's add a dependency and hope
  198. # that it will be generated later
  199. set(out_depends)
  200. endif()
  201. add_custom_command(OUTPUT ${outfile}
  202. COMMAND ${QT_RCC_EXECUTABLE}
  203. ARGS ${rcc_options} -name ${outfilename} -o ${outfile} ${infile}
  204. MAIN_DEPENDENCY ${infile}
  205. DEPENDS ${_RC_DEPENDS} "${out_depends}" VERBATIM)
  206. set(${outfiles} ${${outfiles}} ${outfile})
  207. endforeach ()
  208. endmacro ()
  209. macro(QT4_ADD_DBUS_INTERFACE _sources _interface _basename)
  210. get_filename_component(_infile ${_interface} ABSOLUTE)
  211. set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
  212. set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
  213. set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
  214. get_source_file_property(_nonamespace ${_interface} NO_NAMESPACE)
  215. if(_nonamespace)
  216. set(_params -N -m)
  217. else()
  218. set(_params -m)
  219. endif()
  220. get_source_file_property(_classname ${_interface} CLASSNAME)
  221. if(_classname)
  222. set(_params ${_params} -c ${_classname})
  223. endif()
  224. get_source_file_property(_include ${_interface} INCLUDE)
  225. if(_include)
  226. set(_params ${_params} -i ${_include})
  227. endif()
  228. add_custom_command(OUTPUT "${_impl}" "${_header}"
  229. COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} ${_params} -p ${_basename} ${_infile}
  230. DEPENDS ${_infile} VERBATIM)
  231. set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
  232. QT4_GENERATE_MOC("${_header}" "${_moc}")
  233. list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
  234. MACRO_ADD_FILE_DEPENDENCIES("${_impl}" "${_moc}")
  235. endmacro()
  236. macro(QT4_ADD_DBUS_INTERFACES _sources)
  237. foreach (_current_FILE ${ARGN})
  238. get_filename_component(_infile ${_current_FILE} ABSOLUTE)
  239. get_filename_component(_basename ${_current_FILE} NAME)
  240. # get the part before the ".xml" suffix
  241. string(TOLOWER ${_basename} _basename)
  242. string(REGEX REPLACE "(.*\\.)?([^\\.]+)\\.xml" "\\2" _basename ${_basename})
  243. QT4_ADD_DBUS_INTERFACE(${_sources} ${_infile} ${_basename}interface)
  244. endforeach ()
  245. endmacro()
  246. macro(QT4_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options )
  247. QT4_EXTRACT_OPTIONS(_customName _qt4_dbus_options _qt4_dbus_target ${ARGN})
  248. get_filename_component(_in_file ${_header} ABSOLUTE)
  249. get_filename_component(_basename ${_header} NAME_WE)
  250. if (_customName)
  251. if (IS_ABSOLUTE ${_customName})
  252. get_filename_component(_containingDir ${_customName} PATH)
  253. if (NOT EXISTS ${_containingDir})
  254. file(MAKE_DIRECTORY "${_containingDir}")
  255. endif()
  256. set(_target ${_customName})
  257. else()
  258. set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName})
  259. endif()
  260. else ()
  261. set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml)
  262. endif ()
  263. add_custom_command(OUTPUT ${_target}
  264. COMMAND ${QT_DBUSCPP2XML_EXECUTABLE} ${_qt4_dbus_options} ${_in_file} -o ${_target}
  265. DEPENDS ${_in_file} VERBATIM
  266. )
  267. endmacro()
  268. macro(QT4_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName)
  269. get_filename_component(_infile ${_xml_file} ABSOLUTE)
  270. set(_optionalBasename "${ARGV4}")
  271. if (_optionalBasename)
  272. set(_basename ${_optionalBasename} )
  273. else ()
  274. string(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile})
  275. string(TOLOWER ${_basename} _basename)
  276. endif ()
  277. set(_optionalClassName "${ARGV5}")
  278. set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
  279. set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
  280. set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
  281. if(_optionalClassName)
  282. add_custom_command(OUTPUT "${_impl}" "${_header}"
  283. COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -c ${_optionalClassName} -i ${_include} -l ${_parentClass} ${_infile}
  284. DEPENDS ${_infile} VERBATIM
  285. )
  286. else()
  287. add_custom_command(OUTPUT "${_impl}" "${_header}"
  288. COMMAND ${QT_DBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -i ${_include} -l ${_parentClass} ${_infile}
  289. DEPENDS ${_infile} VERBATIM
  290. )
  291. endif()
  292. QT4_GENERATE_MOC("${_header}" "${_moc}")
  293. set_source_files_properties("${_impl}" PROPERTIES SKIP_AUTOMOC TRUE)
  294. MACRO_ADD_FILE_DEPENDENCIES("${_impl}" "${_moc}")
  295. list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
  296. endmacro()
  297. macro(QT4_AUTOMOC)
  298. if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.11)
  299. message(DEPRECATION "The qt4_automoc macro is obsolete. Use the CMAKE_AUTOMOC feature instead.")
  300. endif()
  301. QT4_GET_MOC_FLAGS(_moc_INCS)
  302. set(_matching_FILES )
  303. foreach (_current_FILE ${ARGN})
  304. get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
  305. # if "SKIP_AUTOMOC" is set to true, we will not handle this file here.
  306. # This is required to make uic work correctly:
  307. # we need to add generated .cpp files to the sources (to compile them),
  308. # but we cannot let automoc handle them, as the .cpp files don't exist yet when
  309. # cmake is run for the very first time on them -> however the .cpp files might
  310. # exist at a later run. at that time we need to skip them, so that we don't add two
  311. # different rules for the same moc file
  312. get_source_file_property(_skip ${_abs_FILE} SKIP_AUTOMOC)
  313. if ( NOT _skip AND EXISTS ${_abs_FILE} )
  314. file(READ ${_abs_FILE} _contents)
  315. get_filename_component(_abs_PATH ${_abs_FILE} PATH)
  316. string(REGEX MATCHALL "# *include +[^ ]+\\.moc[\">]" _match "${_contents}")
  317. if(_match)
  318. foreach (_current_MOC_INC ${_match})
  319. string(REGEX MATCH "[^ <\"]+\\.moc" _current_MOC "${_current_MOC_INC}")
  320. get_filename_component(_basename ${_current_MOC} NAME_WE)
  321. if(EXISTS ${_abs_PATH}/${_basename}.hpp)
  322. set(_header ${_abs_PATH}/${_basename}.hpp)
  323. else()
  324. set(_header ${_abs_PATH}/${_basename}.h)
  325. endif()
  326. set(_moc ${CMAKE_CURRENT_BINARY_DIR}/${_current_MOC})
  327. QT4_CREATE_MOC_COMMAND(${_header} ${_moc} "${_moc_INCS}" "" "")
  328. MACRO_ADD_FILE_DEPENDENCIES(${_abs_FILE} ${_moc})
  329. endforeach ()
  330. endif()
  331. endif ()
  332. endforeach ()
  333. endmacro()
  334. macro(QT4_CREATE_TRANSLATION _qm_files)
  335. QT4_EXTRACT_OPTIONS(_lupdate_files _lupdate_options _lupdate_target ${ARGN})
  336. set(_my_sources)
  337. set(_my_dirs)
  338. set(_my_tsfiles)
  339. set(_ts_pro)
  340. foreach (_file ${_lupdate_files})
  341. get_filename_component(_ext ${_file} EXT)
  342. get_filename_component(_abs_FILE ${_file} ABSOLUTE)
  343. if(_ext MATCHES "ts")
  344. list(APPEND _my_tsfiles ${_abs_FILE})
  345. else()
  346. if(NOT _ext)
  347. list(APPEND _my_dirs ${_abs_FILE})
  348. else()
  349. list(APPEND _my_sources ${_abs_FILE})
  350. endif()
  351. endif()
  352. endforeach()
  353. foreach(_ts_file ${_my_tsfiles})
  354. if(_my_sources)
  355. # make a .pro file to call lupdate on, so we don't make our commands too
  356. # long for some systems
  357. get_filename_component(_ts_name ${_ts_file} NAME_WE)
  358. set(_ts_pro ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_ts_name}_lupdate.pro)
  359. set(_pro_srcs)
  360. foreach(_pro_src ${_my_sources})
  361. set(_pro_srcs "${_pro_srcs} \\\n \"${_pro_src}\"")
  362. endforeach()
  363. set(_pro_includes)
  364. get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES)
  365. list(REMOVE_DUPLICATES _inc_DIRS)
  366. foreach(_pro_include ${_inc_DIRS})
  367. get_filename_component(_abs_include "${_pro_include}" ABSOLUTE)
  368. set(_pro_includes "${_pro_includes} \\\n \"${_abs_include}\"")
  369. endforeach()
  370. file(WRITE ${_ts_pro} "SOURCES =${_pro_srcs}\nINCLUDEPATH =${_pro_includes}\n")
  371. endif()
  372. add_custom_command(OUTPUT ${_ts_file}
  373. COMMAND ${QT_LUPDATE_EXECUTABLE}
  374. ARGS ${_lupdate_options} ${_ts_pro} ${_my_dirs} -ts ${_ts_file}
  375. DEPENDS ${_my_sources} ${_ts_pro} VERBATIM)
  376. endforeach()
  377. QT4_ADD_TRANSLATION(${_qm_files} ${_my_tsfiles})
  378. endmacro()
  379. macro(QT4_ADD_TRANSLATION _qm_files)
  380. foreach (_current_FILE ${ARGN})
  381. get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
  382. get_filename_component(qm ${_abs_FILE} NAME_WE)
  383. get_source_file_property(output_location ${_abs_FILE} OUTPUT_LOCATION)
  384. if(output_location)
  385. file(MAKE_DIRECTORY "${output_location}")
  386. set(qm "${output_location}/${qm}.qm")
  387. else()
  388. set(qm "${CMAKE_CURRENT_BINARY_DIR}/${qm}.qm")
  389. endif()
  390. add_custom_command(OUTPUT ${qm}
  391. COMMAND ${QT_LRELEASE_EXECUTABLE}
  392. ARGS ${_abs_FILE} -qm ${qm}
  393. DEPENDS ${_abs_FILE} VERBATIM
  394. )
  395. set(${_qm_files} ${${_qm_files}} ${qm})
  396. endforeach ()
  397. endmacro()
  398. function(qt4_use_modules _target _link_type)
  399. if(NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.11)
  400. message(DEPRECATION "The qt4_use_modules function is obsolete. Use target_link_libraries with IMPORTED targets instead.")
  401. endif()
  402. if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE")
  403. set(modules ${ARGN})
  404. set(link_type ${_link_type})
  405. else()
  406. set(modules ${_link_type} ${ARGN})
  407. endif()
  408. foreach(_module ${modules})
  409. string(TOUPPER ${_module} _ucmodule)
  410. set(_targetPrefix QT_QT${_ucmodule})
  411. if (_ucmodule STREQUAL QAXCONTAINER OR _ucmodule STREQUAL QAXSERVER)
  412. if (NOT QT_Q${_ucmodule}_FOUND)
  413. message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
  414. endif()
  415. set(_targetPrefix QT_Q${_ucmodule})
  416. else()
  417. if (NOT QT_QT${_ucmodule}_FOUND)
  418. message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
  419. endif()
  420. if ("${_ucmodule}" STREQUAL "MAIN")
  421. message(FATAL_ERROR "Can not use \"${_module}\" module with qt4_use_modules.")
  422. endif()
  423. endif()
  424. target_link_libraries(${_target} ${link_type} ${${_targetPrefix}_LIBRARIES})
  425. set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${${_targetPrefix}_INCLUDE_DIR} ${QT_HEADERS_DIR} ${QT_MKSPECS_DIR}/default)
  426. set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS ${${_targetPrefix}_COMPILE_DEFINITIONS})
  427. endforeach()
  428. endfunction()