Qt4Macros.cmake 18 KB

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