bundleutils.cmake 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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/PlugIns/obspython.py")
  77. list(APPEND _OTHER_BINARIES
  78. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/PlugIns/obspython.py")
  79. endif()
  80. if(EXISTS
  81. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Resources/obs-mac-virtualcam.plugin"
  82. )
  83. list(
  84. APPEND
  85. _OTHER_BINARIES
  86. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Resources/obs-mac-virtualcam.plugin"
  87. )
  88. endif()
  89. # Create libobs symlink for legacy plugin support
  90. execute_process(
  91. COMMAND
  92. /bin/sh -c
  93. "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"
  94. ${_QUIET_FLAG})
  95. # Python potentially leaves __pycache__ directories inside the bundle which will
  96. # break codesigning
  97. if(EXISTS "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/PlugIns/__pycache__")
  98. file(REMOVE_RECURSE
  99. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/PlugIns/__pycache__")
  100. endif()
  101. # Codesign all binaries inside-out
  102. message(STATUS "OBS: Codesign dependencies")
  103. if(EXISTS
  104. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/Sparkle.framework"
  105. )
  106. execute_process(
  107. COMMAND
  108. /usr/bin/codesign --remove-signature
  109. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app"
  110. ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  111. execute_process(
  112. COMMAND
  113. /usr/bin/codesign --force --sign "${_CODESIGN_IDENTITY}" --deep --options
  114. runtime
  115. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/Sparkle.framework/Versions/A/Resources/Autoupdate.app"
  116. ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  117. endif()
  118. if(EXISTS
  119. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/Chromium Embedded Framework.framework"
  120. )
  121. set(CEF_HELPER_OUTPUT_NAME "OBS Helper")
  122. set(CEF_HELPER_APP_SUFFIXES ":" " (GPU):.gpu" " (Plugin):.plugin"
  123. " (Renderer):.renderer")
  124. foreach(_SUFFIXES ${CEF_HELPER_APP_SUFFIXES})
  125. string(REPLACE ":" ";" _SUFFIXES ${_SUFFIXES})
  126. list(GET _SUFFIXES 0 _NAME_SUFFIX)
  127. list(GET _SUFFIXES 1 _PLIST_SUFFIX)
  128. set(_HELPER_OUTPUT_NAME "${CEF_HELPER_OUTPUT_NAME}${_NAME_SUFFIX}")
  129. set(_HELPER_ENTITLEMENT_PLIST "entitlements-helper${_PLIST_SUFFIX}.plist")
  130. execute_process(
  131. COMMAND
  132. /usr/bin/codesign --remove-signature
  133. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/OBS Helper${_NAME_SUFFIX}.app"
  134. ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  135. execute_process(
  136. COMMAND
  137. /usr/bin/codesign --force --sign "${_CODESIGN_IDENTITY}" --deep
  138. --options runtime --entitlements
  139. "${_CODESIGN_ENTITLEMENTS}/entitlements-helper${_PLIST_SUFFIX}.plist"
  140. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}/Contents/Frameworks/OBS Helper${_NAME_SUFFIX}.app"
  141. ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  142. endforeach()
  143. endif()
  144. foreach(_DEPENDENCY IN LISTS _OTHER_BINARIES _DYLIBS _FRAMEWORKS _OBS_PLUGINS
  145. _OBS_SCRIPTING_PLUGINS _QT_PLUGINS)
  146. if(NOT IS_SYMLINK "${_DEPENDENCY}")
  147. execute_process(COMMAND /usr/bin/codesign --remove-signature
  148. "${_DEPENDENCY}" ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  149. execute_process(
  150. COMMAND
  151. /usr/bin/codesign --force --sign "${_CODESIGN_IDENTITY}" --options
  152. runtime --entitlements "${_CODESIGN_ENTITLEMENTS}/entitlements.plist"
  153. "${_DEPENDENCY}" ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  154. endif()
  155. endforeach()
  156. # Codesign main app
  157. message(STATUS "OBS: Codesign main app")
  158. execute_process(
  159. COMMAND
  160. /usr/bin/codesign --remove-signature
  161. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}" ${_VERBOSE_FLAG} ${_QUIET_FLAG})
  162. execute_process(
  163. COMMAND
  164. /usr/bin/codesign --force --sign "${_CODESIGN_IDENTITY}" --options runtime
  165. --entitlements "${_CODESIGN_ENTITLEMENTS}/entitlements.plist"
  166. "${CMAKE_INSTALL_PREFIX}/${_BUNDLENAME}" ${_VERBOSE_FLAG} ${_QUIET_FLAG})