helpers.cmake 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. # OBS CMake Windows helper functions module
  2. # cmake-format: off
  3. # cmake-lint: disable=C0103
  4. # cmake-lint: disable=R0912
  5. # cmake-lint: disable=R0915
  6. # cmake-format: on
  7. include_guard(GLOBAL)
  8. include(helpers_common)
  9. # set_target_properties_obs: Set target properties for use in obs-studio
  10. function(set_target_properties_obs target)
  11. set(options "")
  12. set(oneValueArgs "")
  13. set(multiValueArgs PROPERTIES)
  14. cmake_parse_arguments(PARSE_ARGV 0 _STPO "${options}" "${oneValueArgs}" "${multiValueArgs}")
  15. message(DEBUG "Setting additional properties for target ${target}...")
  16. while(_STPO_PROPERTIES)
  17. list(POP_FRONT _STPO_PROPERTIES key value)
  18. set_property(TARGET ${target} PROPERTY ${key} "${value}")
  19. endwhile()
  20. get_target_property(target_type ${target} TYPE)
  21. if(target_type STREQUAL EXECUTABLE)
  22. if(target STREQUAL obs-browser-helper)
  23. set(OBS_EXECUTABLE_DESTINATION "${OBS_PLUGIN_DESTINATION}")
  24. elseif(target STREQUAL inject-helper OR target STREQUAL get-graphics-offsets)
  25. set(OBS_EXECUTABLE_DESTINATION "${OBS_DATA_DESTINATION}/obs-plugins/win-capture")
  26. # cmake-format: off
  27. _target_install_obs(${target} DESTINATION ${OBS_EXECUTABLE_DESTINATION} 32BIT)
  28. # cmake-format: on
  29. endif()
  30. # cmake-format: off
  31. _target_install_obs(${target} DESTINATION ${OBS_EXECUTABLE_DESTINATION})
  32. # cmake-format: on
  33. if(target STREQUAL obs-studio)
  34. get_property(obs_executables GLOBAL PROPERTY _OBS_EXECUTABLES)
  35. get_property(obs_modules GLOBAL PROPERTY OBS_MODULES_ENABLED)
  36. add_dependencies(${target} ${obs_executables} ${obs_modules})
  37. _bundle_dependencies(${target})
  38. target_add_resource(${target} "${CMAKE_CURRENT_SOURCE_DIR}/../AUTHORS"
  39. "${OBS_DATA_DESTINATION}/obs-studio/authors")
  40. elseif(target STREQUAL obs-browser-helper)
  41. set_property(GLOBAL APPEND PROPERTY _OBS_EXECUTABLES ${target})
  42. return()
  43. else()
  44. set_property(GLOBAL APPEND PROPERTY _OBS_EXECUTABLES ${target})
  45. endif()
  46. elseif(target_type STREQUAL SHARED_LIBRARY)
  47. set_target_properties(${target} PROPERTIES VERSION ${OBS_VERSION_MAJOR} SOVERSION ${OBS_VERSION_CANONICAL})
  48. # cmake-format: off
  49. _target_install_obs(
  50. ${target}
  51. DESTINATION "${OBS_EXECUTABLE_DESTINATION}"
  52. LIBRARY_DESTINATION "${OBS_LIBRARY_DESTINATION}"
  53. HEADER_DESTINATION "${OBS_INCLUDE_DESTINATION}")
  54. # cmake-format: on
  55. elseif(target_type STREQUAL MODULE_LIBRARY)
  56. set_target_properties(${target} PROPERTIES VERSION 0 SOVERSION ${OBS_VERSION_CANONICAL})
  57. if(target STREQUAL libobs-d3d11
  58. OR target STREQUAL libobs-opengl
  59. OR target STREQUAL libobs-winrt)
  60. set(target_destination "${OBS_EXECUTABLE_DESTINATION}")
  61. elseif(target STREQUAL "obspython" OR target STREQUAL "obslua")
  62. set(target_destination "${OBS_SCRIPT_PLUGIN_DESTINATION}")
  63. elseif(target STREQUAL graphics-hook)
  64. set(target_destination "${OBS_DATA_DESTINATION}/obs-plugins/win-capture")
  65. target_add_resource(graphics-hook "${CMAKE_CURRENT_SOURCE_DIR}/obs-vulkan64.json" "${target_destination}")
  66. target_add_resource(graphics-hook "${CMAKE_CURRENT_SOURCE_DIR}/obs-vulkan32.json" "${target_destination}")
  67. # cmake-format: off
  68. _target_install_obs(${target} DESTINATION ${target_destination} 32BIT)
  69. # cmake-format: on
  70. elseif(target STREQUAL obs-virtualcam-module)
  71. set(target_destination "${OBS_DATA_DESTINATION}/obs-plugins/win-dshow")
  72. # cmake-format: off
  73. _target_install_obs(${target} DESTINATION ${target_destination} 32BIT)
  74. # cmake-format: on
  75. else()
  76. set(target_destination "${OBS_PLUGIN_DESTINATION}")
  77. endif()
  78. # cmake-format: off
  79. _target_install_obs(${target} DESTINATION ${target_destination})
  80. # cmake-format: on
  81. if(${target} STREQUAL obspython)
  82. add_custom_command(
  83. TARGET ${target}
  84. POST_BUILD
  85. COMMAND "${CMAKE_COMMAND}" -E echo "Add obspython import module"
  86. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_SCRIPT_PLUGIN_DESTINATION}/"
  87. COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE_DIR:obspython>/obspython.py"
  88. "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_SCRIPT_PLUGIN_DESTINATION}/"
  89. COMMENT "")
  90. install(
  91. FILES "$<TARGET_FILE_DIR:obspython>/obspython.py"
  92. DESTINATION "${OBS_SCRIPT_PLUGIN_DESTINATION}"
  93. COMPONENT Runtime)
  94. elseif(${target} STREQUAL obs-browser)
  95. message(DEBUG "Add Chromium Embedded Framework to project for obs-browser plugin...")
  96. if(TARGET CEF::Library)
  97. get_target_property(imported_location CEF::Library IMPORTED_LOCATION_RELEASE)
  98. if(imported_location)
  99. cmake_path(GET imported_location PARENT_PATH cef_location)
  100. cmake_path(GET cef_location PARENT_PATH cef_root_location)
  101. add_custom_command(
  102. TARGET ${target}
  103. POST_BUILD
  104. COMMAND "${CMAKE_COMMAND}" -E echo "Add Chromium Embedded Framework to library directory"
  105. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_OUTPUT_DIR}/$<CONFIG>/${target_destination}"
  106. COMMAND
  107. "${CMAKE_COMMAND}" -E copy_if_different "${imported_location}" "${cef_location}/chrome_elf.dll"
  108. "${cef_location}/libEGL.dll" "${cef_location}/libGLESv2.dll" "${cef_location}/snapshot_blob.bin"
  109. "${cef_location}/v8_context_snapshot.bin" "${OBS_OUTPUT_DIR}/$<CONFIG>/${target_destination}"
  110. COMMAND
  111. "${CMAKE_COMMAND}" -E copy_if_different "${cef_root_location}/Resources/chrome_100_percent.pak"
  112. "${cef_root_location}/Resources/chrome_200_percent.pak" "${cef_root_location}/Resources/icudtl.dat"
  113. "${cef_root_location}/Resources/resources.pak" "${OBS_OUTPUT_DIR}/$<CONFIG>/${target_destination}/"
  114. COMMAND "${CMAKE_COMMAND}" -E copy_directory "${cef_root_location}/Resources/locales"
  115. "${OBS_OUTPUT_DIR}/$<CONFIG>/${target_destination}/locales"
  116. COMMENT "")
  117. install(
  118. FILES "${imported_location}"
  119. "${cef_location}/chrome_elf.dll"
  120. "${cef_location}/libEGL.dll"
  121. "${cef_location}/libGLESv2.dll"
  122. "${cef_location}/snapshot_blob.bin"
  123. "${cef_location}/v8_context_snapshot.bin"
  124. "${cef_root_location}/Resources/chrome_100_percent.pak"
  125. "${cef_root_location}/Resources/chrome_200_percent.pak"
  126. "${cef_root_location}/Resources/icudtl.dat"
  127. "${cef_root_location}/Resources/resources.pak"
  128. DESTINATION "${target_destination}"
  129. COMPONENT Runtime)
  130. install(
  131. DIRECTORY "${cef_root_location}/Resources/locales"
  132. DESTINATION "${target_destination}"
  133. USE_SOURCE_PERMISSIONS
  134. COMPONENT Runtime)
  135. endif()
  136. endif()
  137. endif()
  138. set_property(GLOBAL APPEND PROPERTY OBS_MODULES_ENABLED ${target})
  139. endif()
  140. target_link_options(${target} PRIVATE "/PDBALTPATH:$<TARGET_PDB_FILE_NAME:${target}>")
  141. target_install_resources(${target})
  142. get_target_property(target_sources ${target} SOURCES)
  143. set(target_ui_files ${target_sources})
  144. list(FILTER target_ui_files INCLUDE REGEX ".+\\.(ui|qrc)")
  145. source_group(
  146. TREE "${CMAKE_CURRENT_SOURCE_DIR}"
  147. PREFIX "UI Files"
  148. FILES ${target_ui_files})
  149. if(${target} STREQUAL libobs)
  150. set(target_source_files ${target_sources})
  151. set(target_header_files ${target_sources})
  152. list(FILTER target_source_files INCLUDE REGEX ".+\\.(m|c[cp]?p?|swift)")
  153. list(FILTER target_header_files INCLUDE REGEX ".+\\.h(pp)?")
  154. source_group(
  155. TREE "${CMAKE_CURRENT_SOURCE_DIR}"
  156. PREFIX "Source Files"
  157. FILES ${target_source_files})
  158. source_group(
  159. TREE "${CMAKE_CURRENT_SOURCE_DIR}"
  160. PREFIX "Header Files"
  161. FILES ${target_header_files})
  162. endif()
  163. endfunction()
  164. # _target_install_obs: Helper function to install build artifacts to rundir and install location
  165. function(_target_install_obs target)
  166. set(options "32BIT")
  167. set(oneValueArgs "DESTINATION" "LIBRARY_DESTINATION" "HEADER_DESTINATION")
  168. set(multiValueArgs "")
  169. cmake_parse_arguments(PARSE_ARGV 0 _TIO "${options}" "${oneValueArgs}" "${multiValueArgs}")
  170. if(_TIO_32BIT)
  171. get_target_property(target_type ${target} TYPE)
  172. if(target_type STREQUAL EXECUTABLE)
  173. set(suffix exe)
  174. else()
  175. set(suffix dll)
  176. endif()
  177. cmake_path(RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR BASE_DIRECTORY "${OBS_SOURCE_DIR}" OUTPUT_VARIABLE project_path)
  178. set(32bit_project_path "${OBS_SOURCE_DIR}/build_x86/${project_path}")
  179. set(target_file "${32bit_project_path}/$<CONFIG>/${target}32.${suffix}")
  180. set(target_pdb_file "${32bit_project_path}/$<CONFIG>/${target}32.pdb")
  181. set(comment "Copy ${target} (32-bit) to destination")
  182. install(
  183. FILES "${32bit_project_path}/$<CONFIG>/${target}32.${suffix}"
  184. DESTINATION "${_TIO_DESTINATION}"
  185. COMPONENT Runtime
  186. OPTIONAL)
  187. else()
  188. set(target_file "$<TARGET_FILE:${target}>")
  189. set(target_pdb_file "$<TARGET_PDB_FILE:${target}>")
  190. set(comment "Copy ${target} to destination")
  191. get_target_property(target_type ${target} TYPE)
  192. if(target_type STREQUAL EXECUTABLE)
  193. install(TARGETS ${target} RUNTIME DESTINATION "${_TIO_DESTINATION}" COMPONENT Runtime)
  194. elseif(target_type STREQUAL SHARED_LIBRARY)
  195. if(NOT _TIO_LIBRARY_DESTINATION)
  196. set(_TIO_LIBRARY_DESTINATION ${_TIO_DESTINATION})
  197. endif()
  198. if(NOT _TIO_HEADER_DESTINATION)
  199. set(_TIO_HEADER_DESTINATION include)
  200. endif()
  201. install(
  202. TARGETS ${target}
  203. RUNTIME DESTINATION "${_TIO_DESTINATION}"
  204. LIBRARY DESTINATION "${_TIO_LIBRARY_DESTINATION}"
  205. COMPONENT Runtime
  206. EXCLUDE_FROM_ALL
  207. PUBLIC_HEADER
  208. DESTINATION "${_TIO_HEADER_DESTINATION}"
  209. COMPONENT Development
  210. EXCLUDE_FROM_ALL)
  211. elseif(target_type STREQUAL MODULE_LIBRARY)
  212. install(
  213. TARGETS ${target}
  214. LIBRARY DESTINATION "${_TIO_DESTINATION}"
  215. COMPONENT Runtime
  216. NAMELINK_COMPONENT Development)
  217. endif()
  218. endif()
  219. add_custom_command(
  220. TARGET ${target}
  221. POST_BUILD
  222. COMMAND "${CMAKE_COMMAND}" -E echo "${comment}"
  223. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_OUTPUT_DIR}/$<CONFIG>/${_TIO_DESTINATION}"
  224. COMMAND "${CMAKE_COMMAND}" -E copy ${target_file} "${OBS_OUTPUT_DIR}/$<CONFIG>/${_TIO_DESTINATION}"
  225. COMMAND "${CMAKE_COMMAND}" -E $<IF:$<CONFIG:Debug,RelWithDebInfo,Release>,copy,true> ${target_pdb_file}
  226. "${OBS_OUTPUT_DIR}/$<CONFIG>/${_TIO_DESTINATION}"
  227. COMMENT ""
  228. VERBATIM)
  229. install(
  230. FILES ${target_pdb_file}
  231. CONFIGURATIONS RelWithDebInfo Debug Release
  232. DESTINATION "${_TIO_DESTINATION}"
  233. COMPONENT Runtime
  234. OPTIONAL)
  235. endfunction()
  236. # target_export: Helper function to export target as CMake package
  237. function(target_export target)
  238. # Exclude CMake package from 'ALL' target
  239. set(exclude_variant EXCLUDE_FROM_ALL)
  240. _target_export(${target})
  241. get_target_property(target_type ${target} TYPE)
  242. if(NOT target_type STREQUAL INTERFACE_LIBRARY)
  243. install(
  244. FILES "$<TARGET_PDB_FILE:${target}>"
  245. CONFIGURATIONS RelWithDebInfo Debug Release
  246. DESTINATION "${OBS_EXECUTABLE_DESTINATION}"
  247. COMPONENT Development
  248. OPTIONAL)
  249. endif()
  250. endfunction()
  251. # Helper function to add resources into bundle
  252. function(target_install_resources target)
  253. message(DEBUG "Installing resources for target ${target}...")
  254. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/data")
  255. file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
  256. foreach(data_file IN LISTS data_files)
  257. cmake_path(RELATIVE_PATH data_file BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/" OUTPUT_VARIABLE
  258. relative_path)
  259. cmake_path(GET relative_path PARENT_PATH relative_path)
  260. target_sources(${target} PRIVATE "${data_file}")
  261. source_group("Resources/${relative_path}" FILES "${data_file}")
  262. endforeach()
  263. get_property(obs_module_list GLOBAL PROPERTY OBS_MODULES_ENABLED)
  264. if(target IN_LIST obs_module_list)
  265. set(target_destination "${OBS_DATA_DESTINATION}/obs-plugins/${target}")
  266. elseif(target STREQUAL obs-studio)
  267. set(target_destination "${OBS_DATA_DESTINATION}/obs-studio")
  268. else()
  269. set(target_destination "${OBS_DATA_DESTINATION}/${target}")
  270. endif()
  271. install(
  272. DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
  273. DESTINATION "${target_destination}"
  274. USE_SOURCE_PERMISSIONS
  275. COMPONENT Runtime)
  276. add_custom_command(
  277. TARGET ${target}
  278. POST_BUILD
  279. COMMAND "${CMAKE_COMMAND}" -E echo "Copy ${target} resources to data directory"
  280. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_OUTPUT_DIR}/$<CONFIG>/${target_destination}"
  281. COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/data"
  282. "${OBS_OUTPUT_DIR}/$<CONFIG>/${target_destination}"
  283. COMMENT ""
  284. VERBATIM)
  285. endif()
  286. endfunction()
  287. # Helper function to add a specific resource to a bundle
  288. function(target_add_resource target resource)
  289. get_property(obs_module_list GLOBAL PROPERTY OBS_MODULES_ENABLED)
  290. if(ARGN)
  291. set(target_destination "${ARGN}")
  292. elseif(${target} IN_LIST obs_module_list)
  293. set(target_destination "${OBS_DATA_DESTINATION}/obs-plugins/${target}")
  294. elseif(target STREQUAL obs-studio)
  295. set(target_destination "${OBS_DATA_DESTINATION}/obs-studio")
  296. else()
  297. set(target_destination "${OBS_DATA_DESTINATION}/${target}")
  298. endif()
  299. message(DEBUG "Add resource '${resource}' to target ${target} at destination '${target_destination}'...")
  300. install(
  301. FILES "${resource}"
  302. DESTINATION "${target_destination}"
  303. COMPONENT Runtime)
  304. add_custom_command(
  305. TARGET ${target}
  306. POST_BUILD
  307. COMMAND "${CMAKE_COMMAND}" -E echo "Copy ${target} resource ${resource} to library directory"
  308. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_OUTPUT_DIR}/$<CONFIG>/${target_destination}/"
  309. COMMAND "${CMAKE_COMMAND}" -E copy "${resource}" "${OBS_OUTPUT_DIR}/$<CONFIG>/${target_destination}/"
  310. COMMENT ""
  311. VERBATIM)
  312. source_group("Resources" FILES "${resource}")
  313. endfunction()
  314. # _bundle_dependencies: Resolve third party dependencies and add them to Windows binary directory
  315. function(_bundle_dependencies target)
  316. message(DEBUG "Discover dependencies of target ${target}...")
  317. set(found_dependencies)
  318. find_dependencies(TARGET ${target} FOUND_VAR found_dependencies)
  319. get_property(obs_module_list GLOBAL PROPERTY OBS_MODULES_ENABLED)
  320. list(LENGTH obs_module_list num_modules)
  321. if(num_modules GREATER 0)
  322. add_dependencies(${target} ${obs_module_list})
  323. foreach(module IN LISTS obs_module_list)
  324. find_dependencies(TARGET ${module} FOUND_VAR found_dependencies)
  325. endforeach()
  326. endif()
  327. list(REMOVE_DUPLICATES found_dependencies)
  328. set(library_paths_DEBUG)
  329. set(library_paths_RELWITHDEBINFO)
  330. set(library_paths_RELEASE)
  331. set(library_paths_MINSIZEREL)
  332. set(plugins_list)
  333. foreach(library IN LISTS found_dependencies)
  334. # CEF needs to be placed in obs-plugins directory on Windows, which is handled already
  335. if(${library} STREQUAL CEF::Library)
  336. continue()
  337. endif()
  338. get_target_property(library_type ${library} TYPE)
  339. get_target_property(is_imported ${library} IMPORTED)
  340. if(is_imported)
  341. get_target_property(imported_location ${library} IMPORTED_LOCATION)
  342. foreach(config IN ITEMS RELEASE RELWITHDEBINFO MINSIZEREL DEBUG)
  343. get_target_property(imported_location_${config} ${library} IMPORTED_LOCATION_${config})
  344. if(imported_location_${config})
  345. _check_library_location(${imported_location_${config}})
  346. elseif(NOT imported_location_${config} AND imported_location_RELEASE)
  347. _check_library_location(${imported_location_RELEASE})
  348. else()
  349. _check_library_location(${imported_location})
  350. endif()
  351. endforeach()
  352. if(library MATCHES "Qt6?::.+")
  353. find_qt_plugins(COMPONENT ${library} TARGET ${target} FOUND_VAR plugins_list)
  354. endif()
  355. endif()
  356. endforeach()
  357. foreach(config IN ITEMS DEBUG RELWITHDEBINFO RELEASE MINSIZEREL)
  358. list(REMOVE_DUPLICATES library_paths_${config})
  359. endforeach()
  360. add_custom_command(
  361. TARGET ${target}
  362. POST_BUILD
  363. COMMAND "${CMAKE_COMMAND}" -E echo "Copy dependencies to binary directory (${OBS_EXECUTABLE_DESTINATION})..."
  364. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_EXECUTABLE_DESTINATION}"
  365. COMMAND "${CMAKE_COMMAND}" -E "$<IF:$<CONFIG:Debug>,copy_if_different,true>"
  366. "$<$<CONFIG:Debug>:${library_paths_DEBUG}>" "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_EXECUTABLE_DESTINATION}"
  367. COMMAND
  368. "${CMAKE_COMMAND}" -E "$<IF:$<CONFIG:RelWithDebInfo>,copy_if_different,true>"
  369. "$<$<CONFIG:RelWithDebInfo>:${library_paths_RELWITHDEBINFO}>"
  370. "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_EXECUTABLE_DESTINATION}"
  371. COMMAND "${CMAKE_COMMAND}" -E "$<IF:$<CONFIG:Release>,copy_if_different,true>"
  372. "$<$<CONFIG:Release>:${library_paths_RELEASE}>" "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_EXECUTABLE_DESTINATION}"
  373. COMMAND
  374. "${CMAKE_COMMAND}" -E "$<IF:$<CONFIG:MinSizeRel>,copy_if_different,true>"
  375. "$<$<CONFIG:MinSizeRel>:${library_paths_MINSIZEREL}>" "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_EXECUTABLE_DESTINATION}"
  376. COMMENT "."
  377. VERBATIM COMMAND_EXPAND_LISTS)
  378. install(
  379. FILES ${library_paths_DEBUG}
  380. CONFIGURATIONS Debug
  381. DESTINATION "${OBS_EXECUTABLE_DESTINATION}"
  382. COMPONENT Runtime)
  383. install(
  384. FILES ${library_paths_RELWITHDEBINFO}
  385. CONFIGURATIONS RelWithDebInfo
  386. DESTINATION "${OBS_EXECUTABLE_DESTINATION}"
  387. COMPONENT Runtime)
  388. install(
  389. FILES ${library_paths_RELEASE}
  390. CONFIGURATIONS Release
  391. DESTINATION "${OBS_EXECUTABLE_DESTINATION}"
  392. COMPONENT Runtime)
  393. install(
  394. FILES ${library_paths_MINSIZEREL}
  395. CONFIGURATIONS MinSizeRel
  396. DESTINATION "${OBS_EXECUTABLE_DESTINATION}"
  397. COMPONENT Runtime)
  398. list(REMOVE_DUPLICATES plugins_list)
  399. foreach(plugin IN LISTS plugins_list)
  400. message(TRACE "Adding Qt plugin ${plugin}...")
  401. cmake_path(GET plugin PARENT_PATH plugin_path)
  402. cmake_path(GET plugin_path STEM plugin_stem)
  403. list(APPEND plugin_stems ${plugin_stem})
  404. if(plugin MATCHES ".+d\\.dll$")
  405. list(APPEND plugin_${plugin_stem}_debug ${plugin})
  406. else()
  407. list(APPEND plugin_${plugin_stem} ${plugin})
  408. endif()
  409. endforeach()
  410. list(REMOVE_DUPLICATES plugin_stems)
  411. foreach(stem IN LISTS plugin_stems)
  412. set(plugin_list ${plugin_${stem}})
  413. set(plugin_list_debug ${plugin_${stem}_debug})
  414. add_custom_command(
  415. TARGET ${target}
  416. POST_BUILD
  417. COMMAND "${CMAKE_COMMAND}" -E echo
  418. "Copy Qt plugins ${stem} to binary directory (${OBS_EXECUTABLE_DESTINATION}/${stem})"
  419. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_EXECUTABLE_DESTINATION}/${stem}"
  420. COMMAND "${CMAKE_COMMAND}" -E "$<IF:$<CONFIG:Debug>,copy_if_different,true>" "${plugin_list_debug}"
  421. "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_EXECUTABLE_DESTINATION}/${stem}"
  422. COMMAND "${CMAKE_COMMAND}" -E "$<IF:$<CONFIG:Debug>,true,copy_if_different>" "${plugin_list}"
  423. "${OBS_OUTPUT_DIR}/$<CONFIG>/${OBS_EXECUTABLE_DESTINATION}/${stem}"
  424. COMMENT ""
  425. VERBATIM COMMAND_EXPAND_LISTS)
  426. install(
  427. FILES ${plugin_list_debug}
  428. CONFIGURATIONS Debug
  429. DESTINATION "${OBS_EXECUTABLE_DESTINATION}/${stem}"
  430. COMPONENT Runtime)
  431. install(
  432. FILES ${plugin_list}
  433. CONFIGURATIONS RelWithDebInfo Release MinSizeRel
  434. DESTINATION "${OBS_EXECUTABLE_DESTINATION}/${stem}"
  435. COMPONENT Runtime)
  436. endforeach()
  437. endfunction()
  438. # _check_library_location: Check for corresponding DLL given an import library path
  439. macro(_check_library_location location)
  440. if(library_type STREQUAL "SHARED_LIBRARY")
  441. set(library_location "${location}")
  442. else()
  443. string(STRIP "${location}" location)
  444. if(location MATCHES ".+lib$")
  445. cmake_path(GET location FILENAME _dll_name)
  446. cmake_path(GET location PARENT_PATH _implib_path)
  447. cmake_path(SET _bin_path NORMALIZE "${_implib_path}/../bin")
  448. string(REPLACE ".lib" ".dll" _dll_name "${_dll_name}")
  449. string(REPLACE ".dll" ".pdb" _pdb_name "${_dll_name}")
  450. find_program(
  451. _dll_path
  452. NAMES "${_dll_name}"
  453. HINTS ${_implib_path} ${_bin_path} NO_CACHE
  454. NO_DEFAULT_PATH)
  455. find_program(
  456. _pdb_path
  457. NAMES "${_pdb_name}"
  458. HINTS ${_implib_path} ${_bin_path} NO_CACHE
  459. NO_DEFAULT_PATH)
  460. if(_dll_path)
  461. set(library_location "${_dll_path}")
  462. set(library_pdb_location "${_pdb_path}")
  463. else()
  464. unset(library_location)
  465. unset(library_pdb_location)
  466. endif()
  467. unset(_dll_path)
  468. unset(_pdb_path)
  469. unset(_bin_path)
  470. unset(_implib_path)
  471. unset(_dll_name)
  472. unset(_pdb_name)
  473. else()
  474. unset(library_location)
  475. unset(library_pdb_location)
  476. endif()
  477. endif()
  478. if(library_location)
  479. list(APPEND library_paths_${config} ${library_location})
  480. endif()
  481. if(library_pdb_location)
  482. list(APPEND library_paths_${config} ${library_pdb_location})
  483. endif()
  484. unset(location)
  485. unset(library_location)
  486. unset(library_pdb_location)
  487. endmacro()