helpers.cmake 20 KB

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