# UBT GenerateClangDatabase is NOT incremental and recreates whole compile\_commands.json each time

**URL:** <https://forums.unrealengine.com/t/ubt-generateclangdatabase-is-not-incremental-and-recreates-whole-compile-commands-json-each-time/2005308>\
**Category:** Platform & Builds\
**Tags:** clang, build, unreal-engine, ubt\
**Created:** [September 4, 2024, 5:00pm UTC](https://forums.unrealengine.com/t/ubt-generateclangdatabase-is-not-incremental-and-recreates-whole-compile-commands-json-each-time/2005308 "2024-09-04T17:00:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzemzmcdonalda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dzemzmcdonalda/32/1214680_2.png) [@dzemzmcdonalda](https://forums.unrealengine.com/u/dzemzmcdonalda)\
**Post date:** [September 4, 2024, 5:00pm UTC](https://forums.unrealengine.com/t/ubt-generateclangdatabase-is-not-incremental-and-recreates-whole-compile-commands-json-each-time/2005308/1 "2024-09-04T17:00:07Z")

</div>

Hi,

In order to generate `compile_commands.json` for `clangd` Language Server, one can use `-mode=GenerateClangDatabase` flag in Unreal Build Tool (more details described [here](https://forums.unrealengine.com/t/get-compile-commands-json/433389/18) )

However, a problem with this mode is that it isn’t “_incremental_” which means it regenerates whole file every time, not only the part that requires it, resulting in very long execution times (around 45sec on my machine).

This makes it pretty hard to use since database needs to be regenerated when any `#include` directive has changed or when any source file has been added/removed/renamed. This should pretty much run every time when build process is invoked, just to make sure database is up to date.

Is there some hidden option/flag that makes it incremental?  
Is there a reason why it’s NOT incremental?  
Was it incremental in the past?

My engine version is `5.4.2`, built from git on Linux

---

<div class="post-metadata">

**Author:** ![dzemzmcdonalda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dzemzmcdonalda/32/1214680_2.png) [@dzemzmcdonalda](https://forums.unrealengine.com/u/dzemzmcdonalda)\
**Post date:** [September 20, 2024, 7:06pm UTC](https://forums.unrealengine.com/t/ubt-generateclangdatabase-is-not-incremental-and-recreates-whole-compile-commands-json-each-time/2005308/2 "2024-09-20T19:06:59Z")

</div>

TLDR: `-NoExecCodeGenActions`

I think I found a workaround/fix to this issue.  
There is a hidden flag in [UnrealEngine/Engine/Source/Programs/UnrealBuildTool/Modes/GenerateClangDatabase.cs](https://github.com/EpicGames/UnrealEngine/blob/40eea367040d50aadd9f030ed5909fc890c159c2/Engine/Source/Programs/UnrealBuildTool/Modes/GenerateClangDatabase.cs#L25-L32)

```auto

		/// <summary>
		/// Execute any actions which result in code generation (eg. ISPC compilation)
		/// </summary>
		[CommandLine("-ExecCodeGenActions")]
		[CommandLine("-NoExecCodeGenActions", Value = "false")]
		public bool bExecCodeGenActions = true;

```

which controls generation of `*.generated.h` files.

**So adding `-NoExecCodeGenActions` fixes this issue for my use case.**  
Execution time is decreased from 45sec to roughly 3sec.  
(but have in mind that whole Project and Engine must be compiled already)

I’m not sure if this is optimal though since 3 sec is still pretty long for something that should be run for each compilation attempt. For comparison, changing one `.cpp` file in my Project requires around 2-5sec for its recompilation. So additional 3sec would make noticeable difference.

---

<div class="post-metadata">

**Author:** ![melmass](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/melmass/32/539417_2.png) [@melmass](https://forums.unrealengine.com/u/melmass)\
**Post date:** [June 30, 2025, 11:40am UTC](https://forums.unrealengine.com/t/ubt-generateclangdatabase-is-not-incremental-and-recreates-whole-compile-commands-json-each-time/2005308/3 "2025-06-30T11:40:37Z")

</div>

Thanks for the discovery. It seems like it’s not needed anymore, and it’s actually faster without this flag (3sec vs 2sec)

---

<div class="post-metadata">

**Author:** ![dzemzmcdonalda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dzemzmcdonalda/32/1214680_2.png) [@dzemzmcdonalda](https://forums.unrealengine.com/u/dzemzmcdonalda)\
**Post date:** [July 1, 2025, 2:59pm UTC](https://forums.unrealengine.com/t/ubt-generateclangdatabase-is-not-incremental-and-recreates-whole-compile-commands-json-each-time/2005308/4 "2025-07-01T14:59:18Z")

</div>

I haven’t tested it for a while, but it seems they improved a lot of stuff in GenerateClangDatabase. Perhaps there was a bug that was always forcing full recompilation and `-NoExecCodeGenActions` was a simple workaround.

Looking through the code, it was always meant to be incremental, so I’m not sure why it wasn’t working for me back in 5.4.2:

```c++
if (bExecCodeGenActions)
{
	// Filter all the actions to execute
	HashSet<FileItem> PrerequisiteItems = new HashSet<FileItem>(Makefile.Actions.SelectMany(x => x.ProducedItems).Where(x => x.HasExtension(".h") || x.HasExtension(".cpp") || x.HasExtension(".cc") || x.HasExtension(".c")));
	List<LinkedAction> PrerequisiteActions = ActionGraph.GatherPrerequisiteActions(Actions, PrerequisiteItems);

	Utils.ExecuteCustomBuildSteps(Makefile.PreBuildScripts, Logger);

	// Execute code generation actions
	if (PrerequisiteActions.Any())
	{
		Logger.LogInformation("Executing actions that produce source files...");
		await ActionGraph.ExecuteActionsAsync(BuildConfiguration, PrerequisiteActions, new List<TargetDescriptor> { TargetDescriptor }, Logger);
	}
}

```

---

<div class="post-metadata">

**Author:** ![dzemzmcdonalda](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dzemzmcdonalda/32/1214680_2.png) [@dzemzmcdonalda](https://forums.unrealengine.com/u/dzemzmcdonalda)\
**Post date:** [July 1, 2025, 3:03pm UTC](https://forums.unrealengine.com/t/ubt-generateclangdatabase-is-not-incremental-and-recreates-whole-compile-commands-json-each-time/2005308/5 "2025-07-01T15:03:23Z")

</div>

Also, if you’re interested @mel , they’ve added few additional flags into this tool since 5.4.

[This is what we have in 5.6:](https://github.com/EpicGames/UnrealEngine/blob/f07fb656e30ea59ce28127ca209d46c80156e1f2/Engine/Source/Programs/UnrealBuildTool/Modes/GenerateClangDatabase.cs#L21-L52)

```c++
/// <summary>
/// Optional set of source files to include in the compile database. If this is empty, all files will be included by default and -Exclude can be used to exclude some.
/// Relative to the root directory, or to the project file.
/// </summary>
[CommandLine("-Include=")]
List<string> IncludeRules = new List<string>();

/// <summary>
/// Optional set of source files to exclude from the compile database. 
/// Relative to the root directory, or to the project file.
/// </summary>
[CommandLine("-Exclude=")]
List<string> ExcludeRules = new List<string>();

/// <summary>
/// Execute any actions which result in code generation (eg. ISPC compilation)
/// </summary>
[CommandLine("-ExecCodeGenActions")]
[CommandLine("-NoExecCodeGenActions", Value = "false")]
public bool bExecCodeGenActions = true;

/// <summary>
/// Optionally override the output filename for handling multiple targets
/// </summary>
[CommandLine("-OutputFilename=")]
public string OutputFilename = "compile_commands.json";

/// <summary>
/// Optionally overrite the output directory for the compile_commands file.
/// </summary>
[CommandLine("-OutputDir=")]
public string OutputDir = Unreal.RootDirectory.ToString();

```
