helpers.cmake 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # CMake Windows helper functions module
  2. # cmake-format: off
  3. # cmake-lint: disable=C0103
  4. # cmake-format: on
  5. include_guard(GLOBAL)
  6. include(helpers_common)
  7. # set_target_properties_plugin: Set target properties for use in obs-studio
  8. function(set_target_properties_plugin target)
  9. set(options "")
  10. set(oneValueArgs "")
  11. set(multiValueArgs PROPERTIES)
  12. cmake_parse_arguments(PARSE_ARGV 0 _STPO "${options}" "${oneValueArgs}" "${multiValueArgs}")
  13. message(DEBUG "Setting additional properties for target ${target}...")
  14. while(_STPO_PROPERTIES)
  15. list(POP_FRONT _STPO_PROPERTIES key value)
  16. set_property(TARGET ${target} PROPERTY ${key} "${value}")
  17. endwhile()
  18. string(TIMESTAMP CURRENT_YEAR "%Y")
  19. set_target_properties(${target} PROPERTIES VERSION 0 SOVERSION ${PLUGIN_VERSION})
  20. install(
  21. TARGETS ${target}
  22. RUNTIME DESTINATION bin/64bit
  23. LIBRARY DESTINATION obs-plugins/64bit)
  24. install(
  25. FILES "$<TARGET_PDB_FILE:${target}>"
  26. CONFIGURATIONS RelWithDebInfo Debug
  27. DESTINATION obs-plugins/64bit
  28. OPTIONAL)
  29. if(OBS_BUILD_DIR)
  30. add_custom_command(
  31. TARGET ${target}
  32. POST_BUILD
  33. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/obs-plugins/64bit"
  34. COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:${target}>"
  35. "$<$<CONFIG:Debug,RelWithDebInfo>:$<TARGET_PDB_FILE:${target}>>" "${OBS_BUILD_DIR}/obs-plugin/64bit"
  36. COMMENT "Copy ${target} to obs-studio directory ${OBS_BUILD_DIR}"
  37. VERBATIM)
  38. endif()
  39. if(TARGET plugin-support)
  40. target_link_libraries(${target} PRIVATE plugin-support)
  41. endif()
  42. target_install_resources(${target})
  43. get_target_property(target_sources ${target} SOURCES)
  44. set(target_ui_files ${target_sources})
  45. list(FILTER target_ui_files INCLUDE REGEX ".+\\.(ui|qrc)")
  46. source_group(
  47. TREE "${CMAKE_CURRENT_SOURCE_DIR}"
  48. PREFIX "UI Files"
  49. FILES ${target_ui_files})
  50. set(valid_uuid FALSE)
  51. check_uuid(${_windowsAppUUID} valid_uuid)
  52. if(NOT valid_uuid)
  53. message(FATAL_ERROR "Specified Windows package UUID is not a valid UUID value: ${_windowsAppUUID}")
  54. else()
  55. set(UUID_APP ${_windowsAppUUID})
  56. endif()
  57. configure_file(cmake/windows/resources/installer-Windows.iss.in
  58. "${CMAKE_CURRENT_BINARY_DIR}/installer-Windows.generated.iss")
  59. configure_file(cmake/windows/resources/resource.rc.in "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.rc")
  60. target_sources(${CMAKE_PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.rc")
  61. endfunction()
  62. # Helper function to add resources into bundle
  63. function(target_install_resources target)
  64. message(DEBUG "Installing resources for target ${target}...")
  65. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/data")
  66. file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
  67. foreach(data_file IN LISTS data_files)
  68. cmake_path(RELATIVE_PATH data_file BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/" OUTPUT_VARIABLE
  69. relative_path)
  70. cmake_path(GET relative_path PARENT_PATH relative_path)
  71. target_sources(${target} PRIVATE "${data_file}")
  72. source_group("Resources/${relative_path}" FILES "${data_file}")
  73. endforeach()
  74. install(
  75. DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
  76. DESTINATION data/obs-plugins/${target}
  77. USE_SOURCE_PERMISSIONS)
  78. if(OBS_BUILD_DIR)
  79. add_custom_command(
  80. TARGET ${target}
  81. POST_BUILD
  82. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
  83. COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/data"
  84. "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
  85. COMMENT "Copy ${target} resources to data directory"
  86. VERBATIM)
  87. endif()
  88. endif()
  89. endfunction()
  90. # Helper function to add a specific resource to a bundle
  91. function(target_add_resource target resource)
  92. message(DEBUG "Add resource '${resource}' to target ${target} at destination '${target_destination}'...")
  93. install(
  94. FILES "${resource}"
  95. DESTINATION data/obs-plugins/${target}
  96. COMPONENT Runtime)
  97. if(OBS_BUILD_DIR)
  98. add_custom_command(
  99. TARGET ${target}
  100. POST_BUILD
  101. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
  102. COMMAND "${CMAKE_COMMAND}" -E copy "${resource}" "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
  103. COMMENT "Copy ${target} resource ${resource} to library directory"
  104. VERBATIM)
  105. endif()
  106. source_group("Resources" FILES "${resource}")
  107. endfunction()