setup_obs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. autoload -Uz log_error log_info log_status
  2. if (( ! ${+buildspec_file} )) {
  3. log_error "'buildspec_file' not set. Please set before running ${0}."
  4. return 2
  5. }
  6. if (( ! ${+commands[git]} )) {
  7. log_error 'git not found. Please install git.'
  8. return 2
  9. }
  10. if (( ! ${+commands[jq]} )) {
  11. log_error 'jq not found. Please install jq.'
  12. return 2
  13. }
  14. if (( ! ${+project_root} )) {
  15. log_error "'project_root' not set. Please set before running ${0}."
  16. return 2
  17. }
  18. if (( ! ${+target} )) {
  19. log_error "'target' not set. Please set before running ${0}."
  20. return 2
  21. }
  22. log_info 'Setting up OBS-Studio...'
  23. local obs_version
  24. local obs_repo
  25. local obs_branch
  26. local obs_hash
  27. read -r obs_version obs_repo obs_branch obs_hash <<< \
  28. "$(jq -r --arg key "obs-studio" \
  29. '.dependencies[$key] | {version, repository, branch, hash} | join(" ")' \
  30. ${buildspec_file})"
  31. if [[ -z ${obs_version} ]] {
  32. log_error "No obs-studio version found in buildspec.json"
  33. return 2
  34. }
  35. pushd
  36. mkcd ${project_root:h}/obs-studio
  37. if (( ! (${skips[(Ie)all]} + ${skips[(Ie)unpack]}) )) {
  38. if [[ -d .git ]] {
  39. git config advice.detachedHead false
  40. git config remote.pluginbuild.url "${obs_repo:-https://github.com/obsproject/obs-studio.git}"
  41. git config remote.pluginbuild.fetch "+refs/heads/${obs_branch:-master}:refs/remotes/origin/${obs_branch:-master}"
  42. git rev-parse -q --verify "${obs_hash}^{commit}" > /dev/null || git fetch pluginbuild
  43. git checkout ${obs_branch:-master} -B ${product_name}
  44. git reset --hard "${obs_hash}"
  45. log_status 'Found existing obs-studio repository.'
  46. } else {
  47. git clone "${obs_repo:-https://github.com/obsproject/obs-studio.git}" "${PWD}"
  48. git config advice.detachedHead false
  49. git checkout -f "${obs_hash}" --
  50. git checkout ${obs_branch:-master} -b ${product_name}
  51. log_status 'obs-studio checked out.'
  52. }
  53. git submodule foreach --recursive git submodule sync
  54. git submodule update --init --recursive
  55. }
  56. if (( ! (${skips[(Ie)all]} + ${skips[(Ie)build]}) )) {
  57. log_info 'Configuring obs-studio...'
  58. local -a cmake_args=(
  59. -DCMAKE_BUILD_TYPE=${BUILD_CONFIG:-Release}
  60. -DQT_VERSION=${QT_VERSION}
  61. -DENABLE_PLUGINS=OFF
  62. -DENABLE_UI=OFF
  63. -DENABLE_SCRIPTING=OFF
  64. -DCMAKE_INSTALL_PREFIX="${project_root:h}/obs-build-dependencies/plugin-deps-${OBS_DEPS_VERSION}-qt${QT_VERSION}-${target##*-}"
  65. -DCMAKE_PREFIX_PATH="${project_root:h}/obs-build-dependencies/plugin-deps-${OBS_DEPS_VERSION}-qt${QT_VERSION}-${target##*-}"
  66. )
  67. if (( _loglevel == 0 )) cmake_args+=(-Wno_deprecated -Wno-dev --log-level=ERROR)
  68. if (( _loglevel > 2 )) cmake_args+=(--debug-output)
  69. local num_procs
  70. case ${target} {
  71. macos-*)
  72. autoload -Uz read_codesign
  73. if (( ${+CODESIGN} )) {
  74. read_codesign
  75. }
  76. cmake_args+=(
  77. -DCMAKE_OSX_ARCHITECTURES=${${target##*-}//universal/x86_64;arm64}
  78. -DCMAKE_OSX_DEPLOYMENT_TARGET=${DEPLOYMENT_TARGET:-10.15}
  79. -DOBS_CODESIGN_LINKER=ON
  80. -DOBS_BUNDLE_CODESIGN_IDENTITY="${CODESIGN_IDENT:--}"
  81. )
  82. num_procs=$(( $(sysctl -n hw.ncpu) + 1 ))
  83. ;;
  84. linux-*)
  85. cmake_args+=(
  86. -DENABLE_PIPEWIRE=OFF
  87. )
  88. num_procs=$(( $(nproc) + 1 ))
  89. ;;
  90. }
  91. log_debug "Attempting to configure OBS with CMake arguments: ${cmake_args}"
  92. cmake -S . -B plugin_build_${target##*-} -G ${generator} ${cmake_args}
  93. log_info 'Building libobs and obs-frontend-api...'
  94. local -a cmake_args=()
  95. if (( _loglevel > 1 )) cmake_args+=(--verbose)
  96. if [[ ${generator} == 'Unix Makefiles' ]] cmake_args+=(--parallel ${num_procs})
  97. cmake --build plugin_build_${target##*-} --config ${BUILD_CONFIG:-Release} ${cmake_args} -t obs-frontend-api
  98. cmake --install plugin_build_${target##*-} --config ${BUILD_CONFIG:-Release} --component obs_libraries ${cmake_args}
  99. }
  100. popd