Qt4Macros.cmake 19 KB

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