bundleutils.cmake 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. if(POLICY CMP0007)
  2. cmake_policy(SET CMP0007 NEW)
  3. endif()
  4. if(POLICY CMP0009)
  5. cmake_policy(SET CMP0009 NEW)
  6. endif()
  7. if(POLICY CMP0011)
  8. cmake_policy(SET CMP0011 NEW)
  9. endif()
  10. # Add additional search paths for dylibbundler
  11. list(APPEND _FIXUP_BUNDLES
  12. "-s \"${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks\"")
  13. list(APPEND _FIXUP_BUNDLES "-s \"${CMAKE_INSTALL_PREFIX}/lib\"")
  14. list(APPEND _FIXUP_BUNDLES "-s \"${CMAKE_INSTALL_PREFIX}/Frameworks\"")
  15. foreach(_PREFIX_PATH IN LISTS _DEPENDENCY_PREFIX)
  16. list(APPEND _FIXUP_BUNDLES "-s \"${_PREFIX_PATH}/lib\"")
  17. file(GLOB _DYLIBS "${_PREFIX_PATH}/lib/*.dylib")
  18. file(
  19. COPY ${_DYLIBS}
  20. DESTINATION ${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks
  21. FOLLOW_SYMLINK_CHAIN)
  22. unset(_DYLIBS)
  23. endforeach()
  24. # Unlinked modules need to be supplied manually to dylibbundler
  25. # Find all modules (plugin and standalone)
  26. file(GLOB _OBS_PLUGINS
  27. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/PlugIns/*.plugin")
  28. file(GLOB _OBS_SCRIPTING_PLUGINS
  29. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/PlugIns/*.so")
  30. # Add modules to fixups
  31. foreach(_OBS_PLUGIN IN LISTS _OBS_PLUGINS)
  32. get_filename_component(PLUGIN_NAME "${_OBS_PLUGIN}" NAME_WLE)
  33. list(APPEND _FIXUP_BUNDLES
  34. "-x \"${_OBS_PLUGIN}/Contents/MacOS/${PLUGIN_NAME}\"")
  35. endforeach()
  36. if(EXISTS
  37. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/MacOS/obs-ffmpeg-mux")
  38. list(
  39. APPEND
  40. _FIXUP_BUNDLES
  41. "-x \"${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/MacOS/obs-ffmpeg-mux\""
  42. )
  43. endif()
  44. # Add scripting modules to fixups
  45. foreach(_OBS_PLUGIN IN LISTS _OBS_SCRIPTING_PLUGINS)
  46. list(APPEND _FIXUP_BUNDLES "-x \"${_OBS_PLUGIN}\"")
  47. endforeach()
  48. # Run dylibbbundler
  49. if(DEFINED ENV{VERBOSE})
  50. set(_VERBOSE_FLAG "--verbose")
  51. endif()
  52. if(DEFINED ENV{QUIET})
  53. set(_QUIET_FLAG "OUTPUT_QUIET")
  54. endif()
  55. list(REMOVE_DUPLICATES _FIXUP_BUNDLES)
  56. string(REPLACE ";" " " _FIXUP_BUNDLES "${_FIXUP_BUNDLES}")
  57. message(STATUS "OBS: Bundle linked libraries and dependencies")
  58. execute_process(
  59. COMMAND
  60. /bin/sh -c
  61. "${_BUNDLER_COMMAND} -a \"${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}\" -cd -of -q -f ${_FIXUP_BUNDLES} ${_VERBOSE_FLAG}"
  62. ${_QUIET_FLAG})
  63. # Find all dylibs, frameworks and other code elements inside bundle
  64. file(GLOB _DYLIBS
  65. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/*.dylib")
  66. file(GLOB _FRAMEWORKS
  67. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/*.framework")
  68. file(GLOB_RECURSE _QT_PLUGINS
  69. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/PlugIns/*.dylib")
  70. if(EXISTS
  71. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/MacOS/obs-ffmpeg-mux")
  72. list(APPEND _OTHER_BINARIES
  73. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/MacOS/obs-ffmpeg-mux")
  74. endif()
  75. if(EXISTS
  76. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Resources/obs-mac-virtualcam.plugin"
  77. )
  78. list(
  79. APPEND
  80. _OTHER_BINARIES
  81. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Resources/obs-mac-virtualcam.plugin"
  82. )
  83. endif()
  84. # Create libobs symlink for legacy plugin support
  85. execute_process(
  86. COMMAND
  87. /bin/sh -c
  88. "cd \"${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks\" && ln -fs libobs.framework/Versions/Current/libobs libobs.0.dylib && ln -fsv libobs.framework/Versions/Current/libobs libobs.dylib"
  89. ${_QUIET_FLAG})
  90. # Python potentially leaves __pycache__ directories inside the bundle which will
  91. # break codesigning
  92. if(EXISTS "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/PlugIns/__pycache__")
  93. file(REMOVE_RECURSE
  94. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/PlugIns/__pycache__")
  95. endif()
  96. # Codesign all binaries inside-out
  97. message(STATUS "OBS: Codesign dependencies")
  98. if(EXISTS
  99. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/Chromium Embedded Framework.framework"
  100. )
  101. set(CEF_HELPER_OUTPUT_NAME "OBS Helper")
  102. set(CEF_HELPER_APP_SUFFIXES ":" " (GPU):.gpu" " (Plugin):.plugin"
  103. " (Renderer):.renderer")
  104. foreach(_SUFFIXES ${CEF_HELPER_APP_SUFFIXES})
  105. string(REPLACE ":" ";" _SUFFIXES ${_SUFFIXES})
  106. list(GET _SUFFIXES 0 _NAME_SUFFIX)
  107. list(GET _SUFFIXES 1 _PLIST_SUFFIX)
  108. set(_HELPER_OUTPUT_NAME "${CEF_HELPER_OUTPUT_NAME}${_NAME_SUFFIX}")
  109. set(_HELPER_ENTITLEMENT_PLIST "entitlements-helper${_PLIST_SUFFIX}.plist")
  110. execute_process(
  111. COMMAND
  112. /usr/bin/codesign --remove-signature
  113. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/OBS Helper${_NAME_SUFFIX}.app"
  114. ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  115. execute_process(
  116. COMMAND
  117. /usr/bin/codesign --force --sign "${_CODESIGN_IDENTITY}" --deep
  118. --options runtime --entitlements
  119. "${_CODESIGN_ENTITLEMENTS}/entitlements-helper${_PLIST_SUFFIX}.plist"
  120. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/OBS Helper${_NAME_SUFFIX}.app"
  121. ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  122. endforeach()
  123. endif()
  124. foreach(_DEPENDENCY IN LISTS _OTHER_BINARIES _DYLIBS _FRAMEWORKS _OBS_PLUGINS
  125. _OBS_SCRIPTING_PLUGINS _QT_PLUGINS)
  126. if(NOT IS_SYMLINK "${_DEPENDENCY}")
  127. execute_process(COMMAND /usr/bin/codesign --remove-signature
  128. "${_DEPENDENCY}" ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  129. execute_process(
  130. COMMAND
  131. /usr/bin/codesign --force --sign "${_CODESIGN_IDENTITY}" --options
  132. runtime --entitlements "${_CODESIGN_ENTITLEMENTS}/entitlements.plist"
  133. "${_DEPENDENCY}" ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  134. endif()
  135. endforeach()
  136. # Codesign main app
  137. message(STATUS "OBS: Codesign main app")
  138. execute_process(
  139. COMMAND
  140. /usr/bin/codesign --remove-signature
  141. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}" ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  142. execute_process(
  143. COMMAND
  144. /usr/bin/codesign --force --sign "${_CODESIGN_IDENTITY}" --options runtime
  145. --entitlements "${_CODESIGN_ENTITLEMENTS}/entitlements.plist"
  146. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}" ${_VERBOSE_FLAG} ${_QUIET_FLAG})