• UE5 不同的编译模式下,module的组织形式


    由于最近在琢磨UE5.4这个引擎,在学习过程中,碰到了一些非常有意思的事情,我在尝试把之前写的一些底层库搬到UE里面,比如底层库,网络库等等,我通过建立module,将这些库用源代码的方式整合进了UE5,因为我一直认为整体编译可以更方便的更改编译条件,因此都是用源代码的方式,比如一个atom的库,编译的C#脚本如下:

    1. // Copyright Epic Games, Inc. All Rights Reserved.
    2. using System.IO;
    3. using UnrealBuildTool;
    4. public class atom : ModuleRules
    5. {
    6. public atom(ReadOnlyTargetRules Target) : base(Target)
    7. {
    8. PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
    9. PublicIncludePaths.AddRange(
    10. new string[] {
    11. // ... add public include paths required here ...
    12. }
    13. );
    14. PrivateIncludePaths.AddRange(
    15. new string[] {
    16. // ... add other private include paths required here ...
    17. }
    18. );
    19. PublicDependencyModuleNames.AddRange(
    20. new string[]
    21. {
    22. //"Core",
    23. // ... add other public dependencies that you statically link with here ...
    24. }
    25. );
    26. PrivateDependencyModuleNames.AddRange(
    27. new string[]
    28. {
    29. //"CoreUObject",
    30. //"Engine",
    31. // "Slate",
    32. // "SlateCore",
    33. // ... add private dependencies that you statically link with here ...
    34. }
    35. );
    36. DynamicallyLoadedModuleNames.AddRange(
    37. new string[]
    38. {
    39. // ... add any modules that your module loads dynamically here ...
    40. }
    41. );
    42. }
    43. }

    非常的简单,甚至屏蔽了所有依赖。 然后在入口的module引用这个库。其编译脚本如下:

    1. // Copyright Epic Games, Inc. All Rights Reserved.
    2. using System.IO;
    3. using UnrealBuildTool;
    4. public class Portal : ModuleRules
    5. {
    6. public Portal(ReadOnlyTargetRules Target) : base(Target)
    7. {
    8. PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
    9. PublicIncludePaths.AddRange(
    10. new string[] {
    11. // ... add public include paths required here ...
    12. "atom/code",
    13. }
    14. );
    15. PrivateIncludePaths.AddRange(
    16. new string[] {
    17. // ... add other private include paths required here ...
    18. }
    19. );
    20. PublicDependencyModuleNames.AddRange(
    21. new string[]
    22. {
    23. "Core",
    24. // ... add other public dependencies that you statically link with here ...
    25. "atom"
    26. }
    27. );
    28. PrivateDependencyModuleNames.AddRange(
    29. new string[]
    30. {
    31. "CoreUObject",
    32. "Engine",
    33. "Slate",
    34. "SlateCore",
    35. // ... add private dependencies that you statically link with here ...
    36. }
    37. );
    38. DynamicallyLoadedModuleNames.AddRange(
    39. new string[]
    40. {
    41. // ... add any modules that your module loads dynamically here ...
    42. }
    43. );
    44. }
    45. }

    然后在public dependcy里面将该库引入。这样,就可以编译了。

    但是问题来了,这个方法只适合客户端模式,不适合编辑器模式!因为客户端可以用静态库,而编辑器模式需要的是动态库。编辑器模式下甚至打不开编辑器。告诉我atom的dll不存在。

    这个非常的坑,我想了很多办法都没有办法兼容两种模式。

    后来,迫不得已,我只能将这个atom库改成静态库,不参与编译。其新的编译脚本如下:

    1. // Copyright Epic Games, Inc. All Rights Reserved.
    2. using System.IO;
    3. using UnrealBuildTool;
    4. public class atom : ModuleRules
    5. {
    6. public atom(ReadOnlyTargetRules Target) : base(Target)
    7. {
    8. //PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
    9. Type = ModuleType.External;
    10. PublicIncludePaths.AddRange(
    11. new string[] {
    12. // ... add public include paths required here ...
    13. }
    14. );
    15. PrivateIncludePaths.AddRange(
    16. new string[] {
    17. // ... add other private include paths required here ...
    18. }
    19. );
    20. PublicDependencyModuleNames.AddRange(
    21. new string[]
    22. {
    23. //"Core",
    24. // ... add other public dependencies that you statically link with here ...
    25. }
    26. );
    27. PrivateDependencyModuleNames.AddRange(
    28. new string[]
    29. {
    30. //"CoreUObject",
    31. //"Engine",
    32. // "Slate",
    33. // "SlateCore",
    34. // ... add private dependencies that you statically link with here ...
    35. }
    36. );
    37. DynamicallyLoadedModuleNames.AddRange(
    38. new string[]
    39. {
    40. // ... add any modules that your module loads dynamically here ...
    41. }
    42. );
    43. PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "lib", "x64", "atom_Debug.lib"));
    44. }
    45. }

    主要是将module的类型改成External,不参与编译,同时准备好这个库的静态库。

    然后入口module的编译脚本如下:

    1. // Copyright Epic Games, Inc. All Rights Reserved.
    2. using System.IO;
    3. using UnrealBuildTool;
    4. public class Portal : ModuleRules
    5. {
    6. public Portal(ReadOnlyTargetRules Target) : base(Target)
    7. {
    8. PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
    9. PublicIncludePaths.AddRange(
    10. new string[] {
    11. // ... add public include paths required here ...
    12. "atom/code",
    13. }
    14. );
    15. PrivateIncludePaths.AddRange(
    16. new string[] {
    17. // ... add other private include paths required here ...
    18. }
    19. );
    20. PublicDependencyModuleNames.AddRange(
    21. new string[]
    22. {
    23. "Core",
    24. // ... add other public dependencies that you statically link with here ...
    25. "atom",
    26. }
    27. );
    28. PrivateDependencyModuleNames.AddRange(
    29. new string[]
    30. {
    31. "CoreUObject",
    32. "Engine",
    33. "Slate",
    34. "SlateCore",
    35. // ... add private dependencies that you statically link with here ...
    36. }
    37. );
    38. DynamicallyLoadedModuleNames.AddRange(
    39. new string[]
    40. {
    41. // ... add any modules that your module loads dynamically here ...
    42. }
    43. );
    44. }
    45. }

    这个地方引入了静态库,再编译,就可以再客户端模式和编辑器模式下一同生效。

  • 相关阅读:
    【LeetCode-98】
    动态数组【python】
    下属不服管,当众顶撞自己怎么办?
    隐私计算头条周刊(9.11-9.17)
    什么是服务器节点?
    Python基础入门例程1-NP1 Hello World!
    机器学习之算法部分(算法篇2)
    如何打造小红书产品差异化,打造产品优势?
    oracle标准版不支持tts
    VS2015 Winform 添加文件后 中文乱码
  • 原文地址:https://blog.csdn.net/draracle/article/details/143268554