黑苹果 macOS 10.14 编译 obs-studio 22.0.3

13 篇文章 0 订阅

01 安装 brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

这个安装过程会要求回车2次,同时安装Xcode Command Line Tools
执行过程如下:


softdeMac:~ soft$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/sbin
/usr/local/share
/usr/local/var
/usr/local/opt
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var/homebrew
/usr/local/var/homebrew/linked
/usr/local/Cellar
/usr/local/Caskroom
/usr/local/Homebrew
/usr/local/Frameworks
==> The Xcode Command Line Tools will be installed.

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown soft /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks
==> /usr/bin/sudo /bin/mkdir -p /Users/soft/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/soft/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown soft /Users/soft/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown soft /Library/Caches/Homebrew
==> Searching online for the Command Line Tools
==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> Installing Command Line Tools (macOS Mojave version 10.14) for Xcode-10.0
==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ (macOS\ Mojave\ version\ 10.14)\ for\ Xcode-10.0
Software Update Tool

Downloaded Command Line Tools (macOS Mojave version 10.14) for Xcode
Installing Command Line Tools (macOS Mojave version 10.14) for Xcode
Done with Command Line Tools (macOS Mojave version 10.14) for Xcode
Done.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
==> Downloading and installing Homebrew...
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 113116 (delta 0), reused 1 (delta 0), pack-reused 113115
Receiving objects: 100% (113116/113116), 26.02 MiB | 3.63 MiB/s, done.
Resolving deltas: 100% (82735/82735), done.
From https://github.com/Homebrew/brew
 * [new branch]          master     -> origin/master
 * [new tag]             0.1        -> 0.1
......
 * [new tag]             1.7.7      -> 1.7.7
HEAD is now at fdd8e9b7c Merge pull request #5148 from MikeMcQuaid/travis-only-macos
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 4856, done.
remote: Counting objects: 100% (4856/4856), done.
remote: Compressing objects: 100% (4653/4653), done.
remote: Total 4856 (delta 56), reused 324 (delta 13), pack-reused 0
Receiving objects: 100% (4856/4856), 4.04 MiB | 1.49 MiB/s, done.
Resolving deltas: 100% (56/56), done.
Checking out files: 100% (4873/4873), done.
Tapped 2 commands and 4642 formulae (4,898 files, 12.6MB).
==> Migrating /Library/Caches/Homebrew to /Users/soft/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics.html

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh

02 安装xcode

xcode需要在苹果商店现在,需要有个一苹果商店的账号(Apple ID).这个账号可以免费注册。
在点击苹果商店,在搜索栏搜索xcode,点击获取/安装,开始下载,可看到下载进度。下载完成,会自动安装。
下载xcode

下载完成后,安装
xcode sdk install

安装完成后,记得输入切换指令

sudo xcode-select --switch /Applications/Xcode.app/

03 安装必要软件

安装git wget cmake make FFmpeg x264

brew install git wget cmake make FFmpeg x264
brew install qt

安装好qt后,根据提示配置qt path路径

echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.bash_profile
softdeMac:obs-studio soft$ source ~/.bash_profile

安装cmake-gui
cmake-gui 安装,从cmake.org下载安装mac版本
下载最新链接 https://cmake.org/files/v3.13/cmake-3.13.0-rc1-Darwin-x86_64.dmg
cmake-gui

04 下载obs-studio代码

mkdir git
cd git
git clone --recursive https://github.com/obsproject/obs-studio.git
cd obs-studio

05 编译obs-studio 22.0.3

05.01 切换稳定版本 22.0.3

cd obs-studio
git checkout -b b22.03. 22.03

05.02 配置cmake-gui

配置路径,设置QTDIR=/usr/local/opt/qt/ ,这个路径安装好qt是有提示的。
cmake path qtdir

点击配置
cmake configure

配置编译工具
cmake configure

设置CMAKE_INSTALL_PREFIX,打开xcode

CMAKE_INSTALL_PREFIX=/Users/soft/git/obs-studio/build/mac64/install
cmake configure

05.03 编译obs-studio 22.0.3

设置 Scheme 的工作路径
Use custom working directory=/Users/soft/git/obs-studio/build/mac64/rundir/Debug/bin

cmake configure cmake configure

05.04 运行调试

调试运行 调试运行效果 调试环境命令行运行

06 obs-studio 完整配置

05 只是最小可运行环境。根据cmake-gui的提示,可以看到,还需要很多依赖包,说着说obs-studio还支持很多扩展。比如:

softdeMac:~ soft$ brew install MbedTls lua python swig speexdsp luajit freetype dbus
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mbedtls-2.13.0.mojave.bottl
######################################################################## 100.0%
==> Pouring mbedtls-2.13.0.mojave.bottle.tar.gz
?  /usr/local/Cellar/mbedtls/2.13.0: 136 files, 3.4MB
==> Downloading https://homebrew.bintray.com/bottles/lua-5.3.5_1.mojave.bottle.t
######################################################################## 100.0%
==> Pouring lua-5.3.5_1.mojave.bottle.tar.gz
==> Caveats
You may also want luarocks:
  brew install luarocks
==> Summary
?  /usr/local/Cellar/lua/5.3.5_1: 28 files, 274.5KB
==> Installing dependencies for python: gdbm, readline and sqlite
==> Installing python dependency: gdbm
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.mojave.bottle.tar
######################################################################## 100.0%
==> Pouring gdbm-1.18.mojave.bottle.tar.gz
?  /usr/local/Cellar/gdbm/1.18: 20 files, 588.7KB
==> Installing python dependency: readline
==> Downloading https://homebrew.bintray.com/bottles/readline-7.0.5.mojave.bottl
######################################################################## 100.0%
==> Pouring readline-7.0.5.mojave.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

==> Summary
?  /usr/local/Cellar/readline/7.0.5: 46 files, 1.5MB
==> Installing python dependency: sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.25.2.mojave.bottle
######################################################################## 100.0%
==> Pouring sqlite-3.25.2.mojave.bottle.tar.gz
==> Caveats
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.

If you need to have sqlite first in your PATH run:
  echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile

For compilers to find sqlite you may need to set:
  export LDFLAGS="-L/usr/local/opt/sqlite/lib"
  export CPPFLAGS="-I/usr/local/opt/sqlite/include"

==> Summary
?  /usr/local/Cellar/sqlite/3.25.2: 11 files, 3.7MB
==> Installing python
==> Downloading https://homebrew.bintray.com/bottles/python-3.7.0.mojave.bottle.
######################################################################## 100.0%
==> Pouring python-3.7.0.mojave.bottle.6.tar.gz
==> /usr/local/Cellar/python/3.7.0/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python/
==> /usr/local/Cellar/python/3.7.0/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python/
==> /usr/local/Cellar/python/3.7.0/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python/
==> Caveats
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

If you need Homebrew's Python 2.7 run
  brew install python@2

Pip, setuptools, and wheel have been installed. To update them run
  pip3 install --upgrade pip setuptools wheel

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
?  /usr/local/Cellar/python/3.7.0: 4,781 files, 102MB
==> Installing dependencies for swig: pcre
==> Installing swig dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.42.mojave.bottle.tar
######################################################################## 100.0%
==> Pouring pcre-8.42.mojave.bottle.tar.gz
?  /usr/local/Cellar/pcre/8.42: 204 files, 5.5MB
==> Installing swig
==> Downloading https://homebrew.bintray.com/bottles/swig-3.0.12.mojave.bottle.t
######################################################################## 100.0%
==> Pouring swig-3.0.12.mojave.bottle.tar.gz
?  /usr/local/Cellar/swig/3.0.12: 755 files, 5.5MB
==> Downloading https://homebrew.bintray.com/bottles/speexdsp-1.2rc3.mojave.bott
######################################################################## 100.0%
==> Pouring speexdsp-1.2rc3.mojave.bottle.tar.gz
?  /usr/local/Cellar/speexdsp/1.2rc3: 19 files, 616.2KB
==> Caveats
==> lua
You may also want luarocks:
  brew install luarocks
==> readline
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

==> sqlite
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.

If you need to have sqlite first in your PATH run:
  echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile

For compilers to find sqlite you may need to set:
  export LDFLAGS="-L/usr/local/opt/sqlite/lib"
  export CPPFLAGS="-I/usr/local/opt/sqlite/include"

==> python
Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python/libexec/bin

If you need Homebrew's Python 2.7 run
  brew install python@2

Pip, setuptools, and wheel have been installed. To update them run
  pip3 install --upgrade pip setuptools wheel

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Downloading https://homebrew.bintray.com/bottles/luajit-2.0.5.mojave.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring luajit-2.0.5.mojave.bottle.1.tar.gz
?  /usr/local/Cellar/luajit/2.0.5: 31 files, 1.9MB

==> Installing dependencies for freetype: libpng
==> Installing freetype dependency: libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.35.mojave.bottle
######################################################################## 100.0%
==> Pouring libpng-1.6.35.mojave.bottle.tar.gz
?  /usr/local/Cellar/libpng/1.6.35: 26 files, 1.2MB
==> Installing freetype
==> Downloading https://homebrew.bintray.com/bottles/freetype-2.9.1.mojave.bottl
######################################################################## 100.0%
==> Pouring freetype-2.9.1.mojave.bottle.tar.gz
?  /usr/local/Cellar/freetype/2.9.1: 60 files, 2.6MB

==> Downloading https://homebrew.bintray.com/bottles/dbus-1.12.10.mojave.bottle.
######################################################################## 100.0%
==> Pouring dbus-1.12.10.mojave.bottle.tar.gz
==> /usr/local/Cellar/dbus/1.12.10/bin/dbus-uuidgen --ensure=/usr/local/var/lib/
==> Caveats
To have launchd start dbus now and restart at login:
  brew services start dbus
==> Summary
?  /usr/local/Cellar/dbus/1.12.10: 76 files, 2MB

browser是指基础了cef,需要单独下载。
Sparkle也需要单独下载。

cef 比较特殊,制作安装包时需要单独处理。本实验先不包含cef。

Sparkle下载地址:
https://github.com/sparkle-project/Sparkle/releases/download/1.20.0/Sparkle-1.20.0.tar.bz2
加压后到~/Sparkle-1.20.0/

编译运行./obs
提示:

[softdeMac:bin soft$ ./obs
dyld: Library not loaded: @rpath/Sparkle.framework/Versions/A/Sparkle
  Referenced from: /Users/soft/git/obs-studio/build/mac64/rundir/Release/bin/./obs
  Reason: image not found
Abort trap: 6

这是说明需要把Sparkle依赖拷贝到obs目录下。
我们只要把依赖拷贝到obs-studio源码下面的additional_install_files目录的应用版本下即可。
根据不同macOS的版本和Debug/Release版本。
32位系统对应exec32/exec32d/exec32r。
64位系统对应exec64/exec64d/exec64r。
exec64对应Release版本。
exec64d对应Debug版本。
把需要的依赖拷贝到对应的execXX目录即可。

cd ~/git/obs-studio/additional_install_files/exec64/
# cd ~/git/obs-studio/additional_install_files/exec64d/
# cd ~/git/obs-studio/additional_install_files/exec64r/

cp /usr/local/opt/qt/lib/QtWidgets.framework/QtWidgets ./QtWidgets
cp /usr/local/opt/qt/lib/QtCore.framework/QtCore ./QtCore
cp /usr/local/opt/qt/lib/QtGui.framework/QtGui ./QtGui
cp /usr/local/opt/qt/lib/QtMacExtras.framework/QtMacExtras ./QtMacExtras
cp /usr/local/opt/ffmpeg/lib/libavcodec.58.dylib ./libavcodec.58.dylib
cp /usr/local/opt/ffmpeg/lib/libavformat.58.dylib ./libavformat.58.dylib
cp /usr/local/opt/ffmpeg/lib/libavutil.56.dylib ./libavutil.56.dylib
cp /usr/lib/libcurl.4.dylib ./libcurl.4.dylib
chmod 644 Qt*

cp -r /usr/local/opt/qt/plugins/platforms ./
cp -r /usr/local/opt/qt/plugins/styles ./
# 需要特别注意,当勾选Sparkle时,可能会引起调试异常
cp -r ~/Sparkle-1.20.0/Sparkle.framework ./

主要项目作用:
工程项目

设置工作目录
设置工作目录1

设置工作路/~/git/obs-studio/build/mac64/rundir/Debug/bin/
设置工作目录2

07 注意事项

07.01 勾选Sparkle项目时,可能引起xcode调试异常

不影响实际运行./obs方式运行,和打包后正常运行。仅仅调试时异常。
调试异常

07.02 package项目调整

默认打包不能再非开发环境使用

直接通过package项目生成的dmg包。不能在非开发环境运行。
1 依赖包不全
2 动态库的引用路径需要进行处理。

需要参考如下文件:
cmake/osxbundle/fixup_bundle.sh
cmake/osxbundle/Info.plist
cmake/osxbundle/obs.icns
cmake/osxbundle/obslaunch.sh
cmake/Modules/ObsHelpers.cmake

另外也可以参考CI目录下面和mac相关的脚本。

A:查找依赖
查找依赖的方法,主要是制作安装包,在非开发环境运行:./obs
根据提示,逐个查找依赖,拷贝到对应的目录。
~/git/obs-studio/additional_install_files/exec64/
~/git/obs-studio/additional_install_files/exec64d/
~/git/obs-studio/additional_install_files/exec64r/

B:修改相对路径@rpath
主要方法是使用 otool 查看相对路径,使用install_name_tool 修改二进制和动态库的引用路径。
根据如下两个文件,可知,只要调用了fixup_bundle.sh。即可解决相对路径问题。
cmake/Modules/ObsHelpers.cmake
cmake/osxbundle/fixup_bundle.sh
修改ObsHelpers.cmake代码:

	install(CODE
		"if(DEFINED ENV{FIXUP_BUNDLE})
			execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/cmake/osxbundle/fixup_bundle.sh\" . bin WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}\")
		endif()")

改为

	install(CODE
		"
			execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/cmake/osxbundle/fixup_bundle.sh\" . bin WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}\")
		")

并且cmake-gui中 不勾选 USE_LIBC++选项。
不勾选USE_LIBC++

07.03 取消安装包中的cmake/include目录

默认install目录包含cmake和include目录。我们制作dmg安装包时,时不需要这两个目录的。
在cmake 中去掉对应的install语句即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值