Precompiled header includes break in 4.15

Hi. I have a plugin I have to maintain for several versions of UE. I tried to compile it today for 4.15, as one of the projects I have to support will soon start migrating to it.
The problem I have is that, in 4.14 and previous, UBT required the first include in every cpp to be the PCH for the plugin, whereas in 4.15, UBT requires the first included file to be the header file corresponding to the cpp file (i.e., “foo.h” for “foo.cpp”). This is clearly incompatible.
Is there any way to remove that requirement via the Build.cs file or similar? Or can the corresponding errors be turned to warnings? Otherwise the only alternative I see is ifdef-ing all the includes, which is a bit tiresome (and pretty ugly, IMHO).
Thanks.

Hi, update: I just tried to ifdef

#if (ENGINE_MINOR_VERSION < 15)
#include "FooPluginPCH.h"
#endif
#include "Foo.h"

And UBT is still complaining that the first include must be “Foo.h”. :’(

Hi, after much fiddling and looking at UBT source, i managed to fix it by adding the following to the module’s Build.cs file:

PCHUsage = PCHUsageMode.NoSharedPCHs;

Now it prints a warning when generating the VS project, but everything is building/working fine!
Thanks anyway :slight_smile:

Hi, I am struggling with updating plugins also. When I try your fix, i get:

Error CS0103 The name 'PCHUsage ’ does not exist in the current context

Did this work for you? Thanks!

Hi, sorry, I should have written the full code (PCHUsage is a property of ModuleRules):

using System.IO;

namespace UnrealBuildTool.Rules
{
    public class ExamplePlugin : ModuleRules
    {
        public ExamplePlugin(TargetInfo Target)
        {
            // This prevents UBT from complaining when it finds module PCH before class header
            PCHUsage = PCHUsageMode.NoSharedPCHs;
			
			// rest of rules
			// ...
        }
    }
}

This works for me in UE 4.11 to 4.15.
Hope it helps!

Thank you! Much appreciated.