ObsPluginHelpers.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Functions for generating external plugins
  2. set(EXTERNAL_PLUGIN_OUTPUT_DIR "${CMAKE_BINARY_DIR}/rundir")
  3. # Fix XCode includes to ignore warnings on system includes
  4. function(target_include_directories_system _target)
  5. if(XCODE)
  6. foreach(_arg ${ARGN})
  7. if("${_arg}" STREQUAL "PRIVATE" OR "${_arg}" STREQUAL "PUBLIC" OR "${_arg}" STREQUAL "INTERFACE")
  8. set(_scope ${_arg})
  9. else()
  10. target_compile_options(${_target} ${_scope} -isystem${_arg})
  11. endif()
  12. endforeach()
  13. else()
  14. target_include_directories(${_target} SYSTEM ${_scope} ${ARGN})
  15. endif()
  16. endfunction()
  17. function(install_external_plugin_data_internal target source_dir target_dir)
  18. install(DIRECTORY ${source_dir}/
  19. DESTINATION "${target}/${target_dir}"
  20. USE_SOURCE_PERMISSIONS)
  21. add_custom_command(TARGET ${target} POST_BUILD
  22. COMMAND "${CMAKE_COMMAND}" -E copy_directory
  23. "${CMAKE_CURRENT_SOURCE_DIR}/${source_dir}" "${EXTERNAL_PLUGIN_OUTPUT_DIR}/$<CONFIGURATION>/${target}/${target_dir}"
  24. VERBATIM)
  25. endfunction()
  26. # Installs data
  27. # 'target' is the destination target project being installed to
  28. # 'data_loc' specifies the directory of the data
  29. function(install_external_plugin_data target data_loc)
  30. install_external_plugin_data_internal(${target} ${data_loc} "data")
  31. endfunction()
  32. # Installs data in an architecture-specific data directory on windows/linux (data/32bit or data/64bit). Does not apply for mac.
  33. # 'target' is the destination target project being installed to
  34. # 'data_loc' specifies the directory of the data being installed
  35. function(install_external_plugin_arch_data target data_loc)
  36. if(APPLE)
  37. set(_bit_suffix "")
  38. elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  39. set(_bit_suffix "/64bit")
  40. else()
  41. set(_bit_suffix "/32bit")
  42. endif()
  43. install_external_plugin_data_internal(${target} ${data_loc} "data${_bit_suffix}")
  44. endfunction()
  45. # Installs data in the target's bin directory
  46. # 'target' is the destination target project being installed to
  47. # 'data_loc' specifies the directory of the data being installed
  48. function(install_external_plugin_data_to_bin target data_loc)
  49. if(APPLE)
  50. set(_bit_suffix "")
  51. elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  52. set(_bit_suffix "/64bit")
  53. else()
  54. set(_bit_suffix "/32bit")
  55. endif()
  56. install_external_plugin_data_internal(${target} ${data_loc} "bin${_bit_suffix}")
  57. endfunction()
  58. # Installs an additional binary to a target
  59. # 'target' is the destination target project being installed to
  60. # 'additional_target' specifies the additional binary
  61. function(install_external_plugin_additional target additional_target)
  62. if(APPLE)
  63. set(_bit_suffix "")
  64. elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  65. set(_bit_suffix "64bit/")
  66. else()
  67. set(_bit_suffix "32bit/")
  68. endif()
  69. set_target_properties(${additional_target} PROPERTIES
  70. PREFIX "")
  71. install(TARGETS ${additional_target}
  72. LIBRARY DESTINATION "bin"
  73. RUNTIME DESTINATION "bin")
  74. add_custom_command(TARGET ${additional_target} POST_BUILD
  75. COMMAND "${CMAKE_COMMAND}" -E copy
  76. "$<TARGET_FILE:${additional_target}>"
  77. "${EXTERNAL_PLUGIN_OUTPUT_DIR}/$<CONFIGURATION>/${target}/bin/${_bit_suffix}$<TARGET_FILE_NAME:${additional_target}>"
  78. VERBATIM)
  79. endfunction()
  80. # Installs the binary of the target
  81. # 'target' is the target project being installed
  82. function(install_external_plugin target)
  83. install_external_plugin_additional(${target} ${target})
  84. endfunction()
  85. # Installs the binary and data of the target
  86. # 'target' is the destination target project being installed to
  87. function(install_external_plugin_with_data target data_loc)
  88. install_external_plugin(${target})
  89. install_external_plugin_data(${target} ${data_loc})
  90. endfunction()
  91. # Installs an additional binary to the data of a target
  92. # 'target' is the destination target project being installed to
  93. # 'additional_target' specifies the additional binary
  94. function(install_external_plugin_bin_to_data target additional_target)
  95. install(TARGETS ${additional_target}
  96. LIBRARY DESTINATION "data"
  97. RUNTIME DESTINATION "data")
  98. add_custom_command(TARGET ${additional_target} POST_BUILD
  99. COMMAND "${CMAKE_COMMAND}" -E copy
  100. "$<TARGET_FILE:${additional_target}>"
  101. "${EXTERNAL_PLUGIN_OUTPUT_DIR}/$<CONFIGURATION>/${target}/data/$<TARGET_FILE_NAME:${additional_target}>"
  102. VERBATIM)
  103. endfunction()
  104. # Installs an additional binary in an architecture-specific data directory on windows/linux (data/32bit or data/64bit). Does not apply for mac.
  105. # 'target' is the destination target project being installed to
  106. # 'additional_target' specifies the additional binary
  107. function(install_external_plugin_bin_to_arch_data target additional_target)
  108. if(APPLE)
  109. set(_bit_suffix "")
  110. elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  111. set(_bit_suffix "/64bit")
  112. else()
  113. set(_bit_suffix "/32bit")
  114. endif()
  115. install(TARGETS ${additional_target}
  116. LIBRARY DESTINATION "data${_bit_suffix}"
  117. RUNTIME DESTINATION "data${_bit_suffix}")
  118. add_custom_command(TARGET ${additional_target} POST_BUILD
  119. COMMAND "${CMAKE_COMMAND}" -E copy
  120. "$<TARGET_FILE:${additional_target}>"
  121. "${EXTERNAL_PLUGIN_OUTPUT_DIR}/$<CONFIGURATION>/${target}/data${_bit_suffix}/$<TARGET_FILE_NAME:${additional_target}>"
  122. VERBATIM)
  123. endfunction()