4.7 KiB
安装homebrew
参考:
国内镜像安装命令:
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
安装完之后需要替换源:
1.必备设置
- 替换 brew.git:
git -C "$(brew --repo)" remote set-url origin https://mirrors.ustc.edu.cn/brew.git
- 替换 homebrew-core.git:
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
2.按需设置
- 替换 homebrew-cask.git:
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.ustc.edu.cn/homebrew-cask.git
- 替换homebrew-bottles: 首先要先区分你的mac用哪种终端工具,如果是 bash,则执行:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
若是 zsh,则执行:
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
macOS开发环境
https://ue5wiki.com/wiki/2329190d/
运行生成解决方案.sh时会提示:
ERROR: Invalid SDK MacOSX.sdk, not found in /Library/Developer/CommandLineTools/Platforms/MacOSX.platform/Developer/SDKs
确认安装Xcode之后执行
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
编译流程
- 先编译ShaderCompileWork
- 后编译UE5
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. I gather from this table 3 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.
解决方法是:
- ShaderCompileWorker.target.cs添加下面的代码。
- UnrealEditor.Target.cs添加下面的代码(去掉bOverrideBuildEnvironment那一行)。
using UnrealBuildTool;
using System.Collections.Generic;
public class YourGameTarget : TargetRules
{
public YourGameTarget(TargetInfo Target) : base(Target)
{
if(Target.Platform == UnrealTargetPlatform.Mac)
{
bOverrideBuildEnvironment = true;
AdditionalCompilerArguments = "-Wno-deprecated-pragma"; // you can add more separated with spaces here
}
...
}
}
我对文件做了一些修改Engine/Source/Programs/UnrealBuildTool/Platform/Mac/MacToolChain.cs
,错误消失了。
if (CompilerVersionGreaterOrEqual(14, 0, 0))
{
Arguments.Add("-Wno-deprecated-pragma");
}
功能齐全:
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");
}
}