Qt4Macros.cmake 18 KB

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