BlueRoseNote/07-Other/MAC/安装Mac UE开发环境.md

158 lines
6.4 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 安装homebrew
参考:
- https://www.jianshu.com/p/e0471aa6672d
国内镜像安装命令:
```c++
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
```
安装完之后需要替换源:
### 1.必备设置
- 替换 brew.git
```bash
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
```
- 替换 homebrew-core.git
```bash
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
```
### 2.按需设置
- 替换 homebrew-cask.git
```bash
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
```
- 替换homebrew-bottles
首先要先区分你的mac用哪种终端工具如果是 bash则执行
```bash
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
```
若是 zsh则执行
```bash
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
```
## git
之后就可以输入命令安装git
```bash
brew install git
```
## macOS开发环境
https://ue5wiki.com/wiki/2329190d/
运行生成解决方案.sh时会提示
>ERROR: Invalid SDK MacOSX.sdk, not found in /Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs
确认安装Xcode之后执行
```bash
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms /Library/Developer/CommandLineTools/Platforms
```
## 为 xcode 开启多线程编译
AMD CPU信息查看APP
https://github.com/trulyspinach/SMCAMDProcessor/releases/tag/0.7.1
首先看一下 Mac 的硬件配置:
>sysctl machdep.cpu
找到 `machdep.cpu.core_count` 字段,其中的数值就是 Mac 的核心数。然后可以给 xcode 开启多线程,数量数为核心数 *2如我的是 8 核,就可以开启 16 线程:
> defaults write com.apple.Xcode PBXNumberOfParallelBuildSubtasks 16
# 证书
需要以下文件
- .cer
- .p12
- .mobileprovision
并将其放入
`/Users/你的用户名/Library/Mobiledevice/provisioning Profiles`最后双击导入。p12建议设置一个密码mac里不支持无密码的p12证书。
运行GenerateProjectFiles.command生成解决方案***此时可以检查证书是否有效***。
# 编译流程
- 先编译ShaderCompileWork
- 后编译UE5
***一定要注意虚拟机的CPU以及内存的关系CPU线程数 * 2 < 内存GB 数。所以给的CPU数目一定不能多。*** 即使是黑苹果下如果内存不够多开了比较占用内存的APP会比较容易死机。比如我使用的是7950x 16核心 32线程 与 64GB内存基本就处于一个平衡状态。如果开了XCode的情况打包引擎会出现死机情况。
# 疑难问题解
## UE5.1 Setup.bat 提示unsupported compression method问题
问题为:
>Checking dependencies...
>Updating dependencies: 0% (0/97340)...
> Failed to download 'https://cdn.unrealengine.com/dependencies/UnrealEngine-11447123-52802068b7db445d94de6cd13d574a02/00ba053f58ab8d00cf41519fd27d8059d397a4fb': InvalidDataException: The archive entry was compressed using an unsupported compression method.
此文问题普遍发生在5.0~5.1以及UE4版本解决方法
去 https://github.com/EpicGames/UnrealEngine/releases 的各个版本标签下,下载**Commit.gitdeps.xml**文件,并替换`\Engine\Build`下同名文件即可。
## ExternalBuildToolExecution failed with a nonzero exit code
问题表现为编译到一半提示 `ExternalBuildToolExecution failed with a nonzero exit code`。这主要是因为XCode代码检索会占用非常多的内存使得CPU线程数 * 2 > 内存GB从而导致编译失败。
解决方法:
>在CMD中输入 `defaults write com.apple.dt.XCode IDEIndexDisable 1`禁用XCode代码检索即可。
## ATOMIC_VAR_INIT错误
https://forums.unrealengine.com/t/cannot-build-ue-5-1-1-from-source-on-macos-ventura-13-3-1-xcode-14-3/885545
macOS 13.4 Xcode 14.3编译UE5.1会报错,其原因是:
>So it seems the error is related to the deprecation of `ATOMIC_VAR_INIT` [since C++20 2](https://en.cppreference.com/w/cpp/atomic/ATOMIC_VAR_INIT). I gather [from this table 3](https://en.wikipedia.org/wiki/Xcode#Xcode_11.0_-_14.x_(since_SwiftUI_framework)_2) that Xcode 14.3 includes a clang patch version bump from 14.0.0 to 14.0.3, and a llvm major version bump from 14.0.0 to 15.0.0. With my limited understanding of clang and llvm, I would guess that llvm 15 compiles at C++20, and therefore throws the build error, whereas the build is successful with Xcode 14.2.
解决方法是:
在`Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs`中添加判断语句对高版本XCode添加`-Wno-deprecated-pragma`编译变量。
```c++
if (CompilerVersionGreaterOrEqual(14, 0, 0))
{
Arguments.Add("-Wno-deprecated-pragma");
}
```
最后修改结果:
```csharp
protected override void GetCompileArguments_Global(CppCompileEnvironment CompileEnvironment, List<string> Arguments)
{
base.GetCompileArguments_Global(CompileEnvironment, Arguments);
Arguments.Add("-fasm-blocks");
if (CompileEnvironment.bEnableOSX109Support)
{
Arguments.Add("-faligned-new"); // aligned operator new is supported only on macOS 10.14 and above
}
// Pass through architecture and OS info
Arguments.Add("" + FormatArchitectureArg(CompileEnvironment.Architecture));
Arguments.Add($"-isysroot \"{SDKPath}\"");
Arguments.Add("-mmacosx-version-min=" + (CompileEnvironment.bEnableOSX109Support ? "10.9" : Settings.MacOSVersion));
List<string> FrameworksSearchPaths = new List<string>();
foreach (UEBuildFramework Framework in CompileEnvironment.AdditionalFrameworks)
{
FileReference FrameworkPath = new FileReference(Path.GetFullPath(Framework.Name));
if (!FrameworksSearchPaths.Contains(FrameworkPath.Directory.FullName))
{
Arguments.Add($"-F \"{NormalizeCommandLinePath(FrameworkPath.Directory)}\"");
FrameworksSearchPaths.Add(FrameworkPath.Directory.FullName);
}
}
//添加的代码在这里
if (CompilerVersionGreaterOrEqual(14, 0, 0))
{
Arguments.Add("-Wno-deprecated-pragma");
}
}
```
## std::ref问题
添加头文件即可。
```c++
#include <functional>
```
## 清理引擎构建历史&缓存
XCode的构建历史
>~/Library/Developer/Xcode/DerivedData
本人采用删除Engine、LocalBuild文件夹中所有文件与UE5 XCode解决方案文件再使用git恢复。最后再运行Setup.command、GenerateProjectFiles.command。