Qt4Macros.cmake 19 KB

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