01_install_dependencies.sh 6.5 KB

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