helpers.cmake 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 Release
  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
  35. "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:${target}>"
  36. "$<$<CONFIG:Debug,RelWithDebInfo,Release>:$<TARGET_PDB_FILE:${target}>>" "${OBS_BUILD_DIR}/obs-plugins/64bit"
  37. COMMENT "Copy ${target} to obs-studio directory ${OBS_BUILD_DIR}"
  38. VERBATIM)
  39. endif()
  40. if(TARGET plugin-support)
  41. target_link_libraries(${target} PRIVATE plugin-support)
  42. endif()
  43. target_install_resources(${target})
  44. get_target_property(target_sources ${target} SOURCES)
  45. set(target_ui_files ${target_sources})
  46. list(FILTER target_ui_files INCLUDE REGEX ".+\\.(ui|qrc)")
  47. source_group(
  48. TREE "${CMAKE_CURRENT_SOURCE_DIR}"
  49. PREFIX "UI Files"
  50. FILES ${target_ui_files})
  51. set(valid_uuid FALSE)
  52. check_uuid(${_windowsAppUUID} valid_uuid)
  53. if(NOT valid_uuid)
  54. message(FATAL_ERROR "Specified Windows package UUID is not a valid UUID value: ${_windowsAppUUID}")
  55. else()
  56. set(UUID_APP ${_windowsAppUUID})
  57. endif()
  58. configure_file(cmake/windows/resources/installer-Windows.iss.in
  59. "${CMAKE_CURRENT_BINARY_DIR}/installer-Windows.generated.iss")
  60. configure_file(cmake/windows/resources/resource.rc.in "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.rc")
  61. target_sources(${CMAKE_PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.rc")
  62. endfunction()
  63. # Helper function to add resources into bundle
  64. function(target_install_resources target)
  65. message(DEBUG "Installing resources for target ${target}...")
  66. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/data")
  67. file(GLOB_RECURSE data_files "${CMAKE_CURRENT_SOURCE_DIR}/data/*")
  68. foreach(data_file IN LISTS data_files)
  69. cmake_path(RELATIVE_PATH data_file BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/" OUTPUT_VARIABLE
  70. relative_path)
  71. cmake_path(GET relative_path PARENT_PATH relative_path)
  72. target_sources(${target} PRIVATE "${data_file}")
  73. source_group("Resources/${relative_path}" FILES "${data_file}")
  74. endforeach()
  75. install(
  76. DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/data/"
  77. DESTINATION data/obs-plugins/${target}
  78. USE_SOURCE_PERMISSIONS)
  79. if(OBS_BUILD_DIR)
  80. add_custom_command(
  81. TARGET ${target}
  82. POST_BUILD
  83. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
  84. COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/data"
  85. "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
  86. COMMENT "Copy ${target} resources to data directory"
  87. VERBATIM)
  88. endif()
  89. endif()
  90. endfunction()
  91. # Helper function to add a specific resource to a bundle
  92. function(target_add_resource target resource)
  93. message(DEBUG "Add resource '${resource}' to target ${target} at destination '${target_destination}'...")
  94. install(
  95. FILES "${resource}"
  96. DESTINATION data/obs-plugins/${target}
  97. COMPONENT Runtime)
  98. if(OBS_BUILD_DIR)
  99. add_custom_command(
  100. TARGET ${target}
  101. POST_BUILD
  102. COMMAND "${CMAKE_COMMAND}" -E make_directory "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
  103. COMMAND "${CMAKE_COMMAND}" -E copy "${resource}" "${OBS_BUILD_DIR}/data/obs-plugins/${target}"
  104. COMMENT "Copy ${target} resource ${resource} to library directory"
  105. VERBATIM)
  106. endif()
  107. source_group("Resources" FILES "${resource}")
  108. endfunction()