01_install_dependencies.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/bin/bash
  2. ##############################################################################
  3. # macOS dependency management function
  4. ##############################################################################
  5. #
  6. # This script file can be included in build scripts for macOS or run directly.
  7. #
  8. ##############################################################################
  9. # Halt on errors
  10. set -eE
  11. install_obs-deps() {
  12. status "Set up precompiled macOS OBS dependencies v${1}"
  13. ensure_dir "${DEPS_BUILD_DIR}"
  14. step "Download..."
  15. check_and_fetch "https://github.com/obsproject/obs-deps/releases/download/${1}/macos-deps-${1}-${ARCH:-x86_64}.tar.xz" "${2}"
  16. mkdir -p obs-deps
  17. step "Unpack..."
  18. /usr/bin/tar -xf "./macos-deps-${1}-${ARCH:-x86_64}.tar.xz" -C ./obs-deps
  19. /usr/bin/xattr -r -d com.apple.quarantine ./obs-deps
  20. }
  21. install_qt-deps() {
  22. status "Set up precompiled dependency Qt v${1}"
  23. ensure_dir "${DEPS_BUILD_DIR}"
  24. step "Download..."
  25. if [[ -n ${CI} ]]; then
  26. _ARCH='universal'
  27. _HASH=${CI_QT_HASH_UNIVERSAL}
  28. else
  29. _ARCH="${ARCH:-x86_64}"
  30. _HASH="${2}"
  31. fi
  32. check_and_fetch "https://github.com/obsproject/obs-deps/releases/download/${1}/macos-deps-qt6-${1}-${_ARCH}.tar.xz" "${_HASH}"
  33. mkdir -p obs-deps
  34. step "Unpack..."
  35. /usr/bin/tar -xf "./macos-deps-qt6-${1}-${_ARCH}.tar.xz" -C ./obs-deps
  36. /usr/bin/xattr -r -d com.apple.quarantine ./obs-deps
  37. }
  38. install_vlc() {
  39. status "Set up dependency VLC v${1}"
  40. ensure_dir "${DEPS_BUILD_DIR}"
  41. unset _SKIP
  42. if [ "${CI}" -a "${RESTORED_VLC}" ]; then
  43. _SKIP=TRUE
  44. elif [ -d "${DEPS_BUILD_DIR}/vlc-${1}" -a -f "${DEPS_BUILD_DIR}/vlc-${1}/include/vlc/vlc.h" ]; then
  45. _SKIP=TRUE
  46. fi
  47. if [ -z "${_SKIP}" ]; then
  48. step "Download..."
  49. check_and_fetch "https://downloads.videolan.org/vlc/${1}/vlc-${1}.tar.xz" "${2}"
  50. step "Unpack..."
  51. /usr/bin/tar -xf vlc-${1}.tar.xz
  52. else
  53. step "Found existing VLC..."
  54. fi
  55. }
  56. install_sparkle() {
  57. status "Set up dependency Sparkle v${1}"
  58. ensure_dir "${DEPS_BUILD_DIR}"
  59. unset _SKIP
  60. if [ "${CI}" -a "${RESTORED_SPARKLE}" ]; then
  61. _SKIP=TRUE
  62. elif [ -d "${DEPS_BUILD_DIR}/obs-deps/lib/Sparkle.framework" -a -f "${DEPS_BUILD_DIR}/obs-deps/lib/Sparkle.framework/Sparkle" ]; then
  63. _SKIP=TRUE
  64. fi
  65. if [ -z "${_SKIP}" ]; then
  66. step "Download..."
  67. check_and_fetch "https://github.com/sparkle-project/Sparkle/releases/download/${1}/Sparkle-${1}.tar.xz" "${2}"
  68. step "Unpack..."
  69. ensure_dir "${DEPS_BUILD_DIR}/sparkle"
  70. /usr/bin/tar -xf ../Sparkle-${1}.tar.xz
  71. cp -cpR "${DEPS_BUILD_DIR}"/sparkle/Sparkle.framework "${DEPS_BUILD_DIR}"/obs-deps/lib/
  72. else
  73. step "Found existing Sparkle Framework..."
  74. fi
  75. }
  76. install_cef() {
  77. status "Set up dependency CEF v${1}"
  78. ensure_dir "${DEPS_BUILD_DIR}"
  79. unset _SKIP
  80. if [ "${CI}" -a "${RESTORED_CEF}" ]; then
  81. _SKIP=TRUE
  82. elif [ -d "${DEPS_BUILD_DIR}/cef_binary_${1}_macos_${ARCH:-x86_64}" -a -f "${DEPS_BUILD_DIR}/cef_binary_${1}_macos_${ARCH:-x86_64}/build/libcef_dll_wrapper/libcef_dll_wrapper.a" ]; then
  83. _SKIP=TRUE
  84. fi
  85. if [ -z "${_SKIP}" ]; then
  86. step "Download..."
  87. check_and_fetch "https://cdn-fastly.obsproject.com/downloads/cef_binary_${1}_macos_${ARCH:-x86_64}.tar.xz" "${2}"
  88. step "Unpack..."
  89. /usr/bin/tar -xf cef_binary_${1}_macos_${ARCH:-x86_64}.tar.xz
  90. cd cef_binary_${1}_macos_${ARCH:-x86_64}
  91. step "Fix tests..."
  92. /usr/bin/sed -i '.orig' '/add_subdirectory(tests\/ceftests)/d' ./CMakeLists.txt
  93. /usr/bin/sed -E -i '' 's/"10.(9|10|11)"/"'${MACOSX_DEPLOYMENT_TARGET:-${CI_MACOSX_DEPLOYMENT_TARGET}}'"/' ./cmake/cef_variables.cmake
  94. step "Run CMake..."
  95. check_ccache
  96. cmake ${CCACHE_OPTIONS} ${QUIET:+-Wno-deprecated -Wno-dev --log-level=ERROR} \
  97. -S . -B build \
  98. -G Ninja \
  99. -DPROJECT_ARCH=${CMAKE_ARCHS:-x86_64} \
  100. -DCEF_COMPILER_FLAGS="-Wno-deprecated-copy" \
  101. -DCMAKE_BUILD_TYPE=Release \
  102. -DCMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++ -Wno-deprecated-declarations -Wno-unknown-warning-option" \
  103. -DCMAKE_EXE_LINKER_FLAGS="-std=c++11 -stdlib=libc++" \
  104. -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-${CI_MACOSX_DEPLOYMENT_TARGET}}
  105. step "Build CEF v${1}..."
  106. cmake --build build
  107. mkdir -p build/libcef_dll
  108. else
  109. step "Found existing Chromium Embedded Framework and loader library..."
  110. fi
  111. }
  112. install_dependencies() {
  113. status "Install Homebrew dependencies"
  114. trap "caught_error 'install_dependencies'" ERR
  115. BUILD_DEPS=(
  116. "obs-deps ${MACOS_DEPS_VERSION:-${CI_DEPS_VERSION}} ${MACOS_DEPS_HASH:-${CI_DEPS_HASH}}"
  117. "qt-deps ${MACOS_DEPS_VERSION:-${CI_DEPS_VERSION}} ${QT_HASH:-${CI_QT_HASH}}"
  118. "cef ${MACOS_CEF_BUILD_VERSION:-${CI_MACOS_CEF_VERSION}} ${CEF_HASH:-${CI_CEF_HASH}}"
  119. "vlc ${VLC_VERSION:-${CI_VLC_VERSION}} ${VLC_HASH:-${CI_VLC_HASH}}"
  120. "sparkle ${SPARKLE_VERSION:-${CI_SPARKLE_VERSION}} ${SPARKLE_HASH:-${CI_SPARKLE_HASH}}"
  121. )
  122. install_homebrew_deps
  123. for DEPENDENCY in "${BUILD_DEPS[@]}"; do
  124. set -- ${DEPENDENCY}
  125. trap "caught_error ${DEPENDENCY}" ERR
  126. FUNC_NAME="install_${1}"
  127. ${FUNC_NAME} ${2} ${3} ${4}
  128. done
  129. }
  130. install-dependencies-standalone() {
  131. CHECKOUT_DIR="$(/usr/bin/git rev-parse --show-toplevel)"
  132. PRODUCT_NAME="OBS-Studio"
  133. DEPS_BUILD_DIR="${CHECKOUT_DIR}/../obs-build-dependencies"
  134. source "${CHECKOUT_DIR}/CI/include/build_support.sh"
  135. source "${CHECKOUT_DIR}/CI/include/build_support_macos.sh"
  136. status "Setup of OBS build dependencies"
  137. check_macos_version
  138. check_archs
  139. install_dependencies
  140. }
  141. print_usage() {
  142. echo -e "Usage: ${0}\n" \
  143. "-h, --help : Print this help\n" \
  144. "-q, --quiet : Suppress most build process output\n" \
  145. "-v, --verbose : Enable more verbose build process output\n" \
  146. "-a, --architecture : Specify build architecture (default: x86_64, alternative: arm64)\n"
  147. }
  148. install-dependencies-main() {
  149. if [ -z "${_RUN_OBS_BUILD_SCRIPT}" ]; then
  150. while true; do
  151. case "${1}" in
  152. -h | --help ) print_usage; exit 0 ;;
  153. -q | --quiet ) export QUIET=TRUE; shift ;;
  154. -v | --verbose ) export VERBOSE=TRUE; shift ;;
  155. -a | --architecture ) ARCH="${2}"; shift 2 ;;
  156. -- ) shift; break ;;
  157. * ) break ;;
  158. esac
  159. done
  160. install-dependencies-standalone
  161. fi
  162. }
  163. install-dependencies-main $*