ObsDefaults_macOS.cmake 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. cmake_minimum_required(VERSION 3.20)
  2. # Enable modern cmake policies
  3. if(POLICY CMP0009)
  4. cmake_policy(SET CMP0009 NEW)
  5. endif()
  6. if(POLICY CMP0011)
  7. cmake_policy(SET CMP0011 NEW)
  8. endif()
  9. if(POLICY CMP0025)
  10. cmake_policy(SET CMP0025 NEW)
  11. endif()
  12. # Build options
  13. set(CMAKE_OSX_ARCHITECTURES
  14. "x86_64"
  15. CACHE STRING "OBS build architecture for macOS - x86_64 required at least")
  16. set_property(CACHE CMAKE_OSX_ARCHITECTURES PROPERTY STRINGS x86_64 arm64
  17. "x86_64;arm64")
  18. set(CMAKE_OSX_DEPLOYMENT_TARGET
  19. "10.13"
  20. CACHE STRING "OBS deployment target for macOS - 10.13+ required")
  21. set_property(CACHE CMAKE_OSX_DEPLOYMENT_TARGET PROPERTY STRINGS 10.13 10.14
  22. 10.15 11 12)
  23. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  24. set(CMAKE_INSTALL_PREFIX
  25. "${CMAKE_BINARY_DIR}/rundir"
  26. CACHE STRING "Directory to install OBS after building" FORCE)
  27. endif()
  28. if(NOT DEFINED CMAKE_PREFIX_PATH)
  29. message(
  30. WARNING
  31. "No CMAKE_PREFIX_PATH set: OBS supplies pre-built dependencies for building on macOS.\n"
  32. "While OBS can be built using packages installed via Homebrew, pre-built dependencies "
  33. "contain beneficial patches and fixes for use within OBS and is the suggested source "
  34. "of these dependencies.\n"
  35. "You can download the appropriate obs-deps package for your "
  36. "architecture and set CMAKE_PREFIX_PATH to this directory:\n"
  37. "CMAKE_PREFIX_PATH=\"<PATH_TO_OBS_DEPS>\"\n"
  38. "Download pre-built OBS dependencies at https://github.com/obsproject/obs-deps/releases\n"
  39. )
  40. endif()
  41. # SWIG hard codes the directory to its library directory at compile time. As
  42. # obs-deps need to be relocatable, we need to force SWIG to look for its files
  43. # in a directory relative to the PREFIX_PATH. The best way to ensure this is to
  44. # set the SWIG_LIB environment variable.
  45. if(NOT DEFINED ENV{SWIG_LIB} AND EXISTS "${CMAKE_PREFIX_PATH}/bin/swig")
  46. set(ENV{SWIG_LIB} "${CMAKE_PREFIX_PATH}/share/swig/CURRENT")
  47. endif()
  48. macro(setup_obs_project)
  49. # Set code signing options
  50. set(OBS_BUNDLE_CODESIGN_IDENTITY
  51. "-"
  52. CACHE STRING "OBS code signing identity for macOS")
  53. set(OBS_CODESIGN_ENTITLEMENTS
  54. "${CMAKE_SOURCE_DIR}/cmake/bundle/macOS/entitlements.plist"
  55. CACHE INTERNAL "Path to codesign entitlements plist")
  56. set(OBS_CODESIGN_LINKER
  57. ON
  58. CACHE BOOL "Enable linker code-signing on macOS (macOS 11+ required)")
  59. # Xcode configuration
  60. if(XCODE)
  61. # Tell Xcode to pretend the linker signed binaries so that editing with
  62. # install_name_tool preserves ad-hoc signatures. This option is supported by
  63. # codesign on macOS 11 or higher. See CMake Issue 21854:
  64. # https://gitlab.kitware.com/cmake/cmake/-/issues/21854
  65. set(CMAKE_XCODE_GENERATE_SCHEME ON)
  66. if(OBS_CODESIGN_LINKER)
  67. set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "-o linker-signed")
  68. endif()
  69. endif()
  70. # Set default options for bundling on macOS
  71. set(CMAKE_MACOSX_RPATH ON)
  72. set(CMAKE_SKIP_BUILD_RPATH OFF)
  73. set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
  74. set(CMAKE_INSTALL_RPATH "@executable_path/../Frameworks/")
  75. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH OFF)
  76. # Set bundle parameters for cmake's automatic plist generation
  77. set(MACOSX_BUNDLE_EXECUTABLE_NAME "OBS")
  78. set(MACOSX_BUNDLE_BUNDLE_NAME "${OBS_PRODUCT_NAME}")
  79. set(MACOSX_BUNDLE_BUNDLE_VERSION "${OBS_BUILD_NUMBER}")
  80. set(MACOSX_BUNDLE_COPYRIGHT "${OBS_LEGAL_COPYRIGHT}")
  81. set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.obsproject.obs-studio")
  82. set(MACOSX_BUNDLE_ICON_FILE "AppIcon")
  83. set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${OBS_VERSION_CANONICAL}")
  84. string(TIMESTAMP CURRENT_YEAR "%Y")
  85. # Set paths for distribution bundling
  86. set(OBS_BUNDLE_NAME "OBS")
  87. set(OBS_EXECUTABLE_DESTINATION "${CMAKE_INSTALL_BINDIR}")
  88. set(OBS_INCLUDE_DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/obs")
  89. set(OBS_LIBRARY_DESTINATION "${CMAKE_INSTALL_LIBDIR}")
  90. set(OBS_CMAKE_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake")
  91. if(BUILD_FOR_DISTRIBUTION)
  92. set_option(CMAKE_BUILD_TYPE "Release")
  93. set(CPACK_PACKAGE_VERSION "${OBS_VERSION_CANONICAL}")
  94. else()
  95. set(CPACK_PACKAGE_VERSION "${OBS_VERSION_CANONICAL}-${OBS_BUILD_NUMBER}")
  96. endif()
  97. if(BUILD_FOR_DISTRIBUTION OR DEFINED ENV{CI})
  98. set_option(ENABLE_SPARKLE_UPDATER ON)
  99. set_option(ENABLE_RTMPS ON)
  100. endif()
  101. set(CPACK_PACKAGE_NAME "OBS")
  102. set(CPACK_PACKAGE_VENDOR "${OBS_WEBSITE}")
  103. set(CPACK_GENERATOR "DragNDrop")
  104. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${OBS_COMMENTS}")
  105. if(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
  106. set(CPACK_ARCH_SUFFIX "Intel")
  107. elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
  108. set(CPACK_ARCH_SUFFIX "Apple")
  109. else()
  110. set(CPACK_ARCH_SUFFIX "Universal")
  111. endif()
  112. set(CPACK_PACKAGE_FILE_NAME
  113. "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-macOS-${CPACK_ARCH_SUFFIX}"
  114. )
  115. set(CPACK_COMPONENTS_ALL obs_app obs_frameworks obs_plugins
  116. obs_scripting_plugins obs_resources)
  117. set(CPACK_COMPONENT_OBS_APP_DISPLAY_NAME "OBS Studio")
  118. set(CPACK_COMPONENT_OBS_FRAMEWORKS_DISPLAY_NAME "OBS Frameworks")
  119. set(CPACK_COMPONENT_OBS_PLUGINS_DISPLAY_NAME "OBS Plugins")
  120. set(CPACK_COMPONENT_OBS_SCRIPTING_PLUGINS_DISPLAY_NAME
  121. "OBS Scripting Plugins")
  122. set(CPACK_COMPONENT_OBS_RESOURCES_DISPLAY_NAME "OBS Resources")
  123. set(CPACK_DMG_BACKGROUND_IMAGE
  124. "${CMAKE_SOURCE_DIR}/cmake/bundle/macOS/background.tiff")
  125. set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/cmake/bundle/macOS/AppIcon.icns")
  126. get_filename_component(CPACK_DMG_BACKGROUND_FILENAME
  127. ${CPACK_DMG_BACKGROUND_IMAGE} NAME)
  128. set(CPACK_DMG_FORMAT "UDZO")
  129. set(CPACK_DMG_DS_STORE_SETUP_SCRIPT "${CMAKE_BINARY_DIR}/package.applescript")
  130. set(_DMG_WINDOW_X "100")
  131. set(_DMG_WINDOW_Y "100")
  132. set(_DMG_WINDOW_WIDTH "540")
  133. set(_DMG_WINDOW_HEIGHT "380")
  134. set(_DMG_ICON_SIZE "96")
  135. set(_DMG_TEXT_SIZE "16")
  136. set(_DMG_OBS_X "124")
  137. set(_DMG_OBS_Y "180")
  138. set(_DMG_APP_LINK_X "416")
  139. set(_DMG_APP_LINK_Y "180")
  140. configure_file("${CMAKE_SOURCE_DIR}/cmake/bundle/macOS/package.applescript.in"
  141. "${CMAKE_BINARY_DIR}/package.applescript" @ONLY)
  142. include(CPack)
  143. if(ENABLE_UI)
  144. install(
  145. CODE "
  146. set(_BUNDLENAME \"$<TARGET_FILE_BASE_NAME:obs>.app\")
  147. if(EXISTS \"\${CMAKE_INSTALL_PREFIX}/\${_BUNDLENAME}\")
  148. file(REMOVE_RECURSE \"\${CMAKE_INSTALL_PREFIX}/\${_BUNDLENAME}\")
  149. endif()")
  150. endif()
  151. endmacro()