Qt4Macros.cmake 18 KB

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