Skip to content

cmake: use precompiled headers#1181

Merged
brakhane merged 1 commit into
masterfrom
cmake-pch
Jul 30, 2025
Merged

cmake: use precompiled headers#1181
brakhane merged 1 commit into
masterfrom
cmake-pch

Conversation

@brakhane

@brakhane brakhane commented Jul 21, 2025

Copy link
Copy Markdown
Collaborator

Preliminary results on my laptop without ccache

engine editor total time
no pch no pch 4:21
no pch stdafx.h 3:33
commoninclude.h stdafx.h 3:30
wickedengine.h stdafx.h 2:54

With the recent changes regarding warnings, PCH on GCC work as well, and compilation is faster for GCC as well with PCH enabled, although only slightly. The difference is a lot larger on Clang.

It also works for cmake on windows, even when using MSVC and CMake, PCH give significant better performance.

See this run for example; ccache was disabled and "ON/OFF" refers to the state of PCH.

Therefore, I think we can always use PCH and don't need a flag for it.

@brakhane brakhane force-pushed the cmake-pch branch 12 times, most recently from 6770052 to 8cb1175 Compare July 28, 2025 19:46
@brakhane brakhane force-pushed the cmake-pch branch 7 times, most recently from 71e5fdc to 28c47b1 Compare July 29, 2025 19:25
@brakhane brakhane marked this pull request as ready for review July 29, 2025 19:28
@brakhane brakhane requested a review from turanszkij July 29, 2025 19:28

@turanszkij turanszkij left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have nothing to add, just question is it going to be a breaking change in other people's projects that use Wicked Engine with cmake? Looks like maybe not, but I don't understand changes in the other project cmakes.

@brakhane

brakhane commented Jul 30, 2025

Copy link
Copy Markdown
Collaborator Author

No, it won’t affect other projects. The target_precompile_headers only uses PRIVATE which means it only applies to when the target itself is built, not when it is used.

The changes in the example projects were only needed because they were also changed to use PCH themselves. Since in CMake, PCH are always included when compiling, it caused the embedded imgui to also be compiled with it. Both wicked an imgui use some stb headers and that caused the same function to be defined multiple times resulting in a linker error. I could just have not added the PCH line in the example projects to avoid this, but since mixing third party sources into the “real” sources was kinda iffy anyway, I decided to fix it by actually turning the embedded imgui into a separate target that the example depends on, as an exaple on what should be done in a real project. This way, the PCH only applies to the example sources, not the imgui ones.

@brakhane brakhane merged commit f428e1a into master Jul 30, 2025
4 checks passed
@brakhane brakhane deleted the cmake-pch branch July 30, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants