helpers.cmake 21 KB

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