setup_obs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. if [[ ! -r ${buildspec_file} ]] {
  23. log_error \
  24. 'No buildspec.json found. Please create a build specification for your project.' \
  25. 'A buildspec.json.template file is provided in the repository to get you started.'
  26. return 2
  27. }
  28. log_info 'Setting up OBS-Studio...'
  29. read -r obs_version obs_repo obs_branch obs_hash <<< \
  30. "$(jq -r --arg key "obs-studio" \
  31. '.dependencies[$key] | {version, repository, branch, hash} | join(" ")' \
  32. ${buildspec_file})"
  33. if [[ -z ${obs_version} ]] {
  34. log_error "No obs-studio version found in buildspec.json"
  35. return 2
  36. }
  37. pushd
  38. mkcd ${project_root:h}/obs-studio
  39. if [[ -d .git ]] {
  40. git config advice.detachedHead false
  41. git config remote.pluginbuild.url "${obs_repo:-https://github.com/obsproject/obs-studio.git}"
  42. git config remote.pluginbuild.fetch "+refs/heads/${obs_branch:-master}:refs/remotes/origin/${obs_branch:-master}"
  43. git rev-parse -q --verify "${obs_hash}^{commit}" > /dev/null || git fetch pluginbuild
  44. git checkout ${obs_branch:-master} -B ${product_name}
  45. git reset --hard "${obs_hash}"
  46. log_status 'Found existing obs-studio repository.'
  47. } else {
  48. git clone "${obs_repo:-https://github.com/obsproject/obs-studio.git}" "${PWD}"
  49. git config advice.detachedHead false
  50. git checkout -f "${obs_hash}" --
  51. git checkout ${obs_branch:-master} -b ${product_name}
  52. log_status 'obs-studio checked out.'
  53. }
  54. git submodule foreach --recursive git submodule sync
  55. git submodule update --init --recursive
  56. log_info 'Configuring obs-studio...'
  57. local -a cmake_args=(
  58. -DCMAKE_BUILD_TYPE=${BUILD_CONFIG:-Release}
  59. -DENABLE_PLUGINS=OFF
  60. -DENABLE_UI=OFF
  61. -DENABLE_SCRIPTING=OFF
  62. -DCMAKE_INSTALL_PREFIX="${project_root:h}/obs-build-dependencies/obs-plugin-deps"
  63. -DCMAKE_PREFIX_PATH="${project_root:h}/obs-build-dependencies/obs-plugin-deps"
  64. )
  65. if (( _loglevel == 0 )) cmake_args+=(-Wno_deprecated -Wno-dev --log-level=ERROR)
  66. case ${target} {
  67. macos-*)
  68. cmake_args+=(
  69. -DCMAKE_OSX_ARCHITECTURES=${${target##*-}//universal/x86_64;arm64}
  70. -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-10.15}
  71. )
  72. ;;
  73. linux-*)
  74. cmake_args+=(
  75. -DENABLE_PIPEWIRE=OFF
  76. )
  77. ;;
  78. }
  79. cmake -S . -B plugin_build_${target##*-} -G Ninja ${cmake_args}
  80. log_info 'Building libobs and obs-frontend-api...'
  81. local -a cmake_args=()
  82. if (( _loglevel > 1 )) cmake_args+=(--verbose)
  83. cmake --build plugin_build_${target##*-} --config ${BUILD_CONFIG:-Release} ${cmake_args} -t obs-frontend-api
  84. cmake --install plugin_build_${target##*-} --config ${BUILD_CONFIG:-Release} --component obs_libraries ${cmake_args}
  85. popd