What is the difference between Public/Private in ModuleRules?

There are many methods that have a Public and Private version when declaring rules in the *.build.cs file. Such as IncludePaths, DependencyModuleNames, etc. How does the build system treat the two versions of Public/Private differently?

This is a rather complicated and confusing topic. I’m planning to write a tutorial over the holidays.

The rule of thumb is this:

  • Public includes/modules will be re-exported from your module. You are basically indicating that, in order to use your module, users will also require dependencies from these other headers and modules. This generally happens if your module’s public header files expose and/or use types or functions that are declared in another module. This mechanism allows users of your module to add a dependency to your module without also explicitly having to add all the other indirect dependencies. In effect, the header file and linker dependencies are passed through from your module to the user’s module.

  • Private includes/modules indicate that these are internal dependencies of your module. They will not be visible to the outside world. This generally happens if your internal, private .cpp and .h files consume types or functions that are declared in another module.

We try to minimize public dependencies whenever we can. One common way to eliminate indirect dependencies from modules is to use forward-declarations in their public header files and only use those types and functions internally inside private files.

Yes, I assumed this was the case but wanted to be sure. Thank you for your answer.