魔改UE4引擎UBT使其支持Swift和Objective-C混编

原版UE4不支持Swift和ObjectiveC的混编,但是需要引用第三方SDK又必须要支持。
以UE4.25.4和MacOS为例,结合网上的资料,记录一下引擎修改过程。

  1. 修改XCodeProject.cs

文件在
/Users/Shared/EpicGames/UE_4.25/Engine/Source/Programs/UnrealBuildTool/ProjectFiles/Xcode/XCodeProject.cs
目录,每个机器UE的安装目录可能不同,找不到就全局搜文件名。

在如下位置添加代码,大概在946行。

// Enable Swift
Content.Append("\t\t\t\tCLANG_ENABLE_MODULES = YES;" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\tSWIFT_VERSION = 5.0;" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\tLIBRARY_SEARCH_PATHS = \"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\";" + ProjectFileGenerator.NewLine);
if (ConfigName == "Debug")
{
     Content.Append("\t\t\t\tSWIFT_OPTIMIZATION_LEVEL = \"-Onone\";" + ProjectFileGenerator.NewLine);
}
Content.Append("\t\t\t\tALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\tEMBEDDED_CONTENT_CONTAINS_SWIFT = YES;" + ProjectFileGenerator.NewLine);
Content.Append("\t\t\t\tCODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION = YES;" + ProjectFileGenerator.NewLine);

  1. 修改IOSToolChain.cs文件

文件地址在../../Platform/IOS/IOSToolChain.cs

在如下两个位置添加代码,大概在537行和558行

Result += " -rpath \"/usr/lib/swift\"";
// enable swift support
Result += " -rpath \"@executable_path/Frameworks\"";
String swiftLibPath = String.Format(" -L {0}Platforms/{1}.platform/Developer/SDKs/{1}{2}.sdk/usr/lib/swift",
                            Settings.Value.XcodeDeveloperDir, bIsDevice? Settings.Value.DevicePlatformName : Settings.Value.SimulatorPlatformName, Settings.Value.IOSSDKVersion);
Result += swiftLibPath;
swiftLibPath = String.Format(" -L {0}Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/{1}",
                            Settings.Value.XcodeDeveloperDir, bIsDevice? Settings.Value.DevicePlatformName.ToLower() : Settings.Value.SimulatorPlatformName.ToLower());
Result += swiftLibPath;
swiftLibPath = String.Format(" -L {0}Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/{1}",
                            Settings.Value.XcodeDeveloperDir, bIsDevice? Settings.Value.DevicePlatformName.ToLower() : Settings.Value.SimulatorPlatformName.ToLower());
Result += swiftLibPath;
if (Settings.Value.IOSSDKVersionFloat >= 14.0f)
{
         Result += String.Format(" -lswiftCompatibility51");
}
  1. 重新编译

在/Users/Shared/EpicGames/UE_4.25/Engine/Source/Programs/UnrealBuildTool/目录执行命令msbuild

可能会因为没有权限编译失败,需要提权后再执行msbuild

修改root密码并提权

sudo passwd root
su root

参考资料
https://docs.msdk.qq.com/v5/zh-CN/FAQS/0d98c74797e49d00bcc4c17c9d557a2b/d71ccef2c59e1043aa80b86d9358c9c3.html

发表评论

[/0o0] [..^v^..] [0_0] [T.T] [=3-❤] [❤.❤] [^v^] [-.0] [!- -] [=x=] [→_→] [><] 更多 »
昵称

抢沙发~