CMake 3.16 now supports precompiled headers

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
apeltauer
Posts: 399
Joined: Fri Aug 11, 2017 2:19 pm

CMake 3.16 now supports precompiled headers

Post by apeltauer »

Hi all,
just came across this:
https://www.qt.io/blog/2019/08/01/preco ... ming-cmake
https://gitlab.kitware.com/cmake/cmake/ ... uests/3553
https://cmake.org/cmake/help/git-stage/ ... aders.html

Just started to test it a little bit. The feature i think is very interesting is the reuse of precompiled header in other projects.
Does anyone has also started playing around with this new feature?
What do you think, if we could create one big precompiled header and all other projects are using this. Maybe we can reduce the compile time on windows.

BR Manuel
Last edited by Kunda1 on Sun Nov 03, 2019 11:54 am, edited 1 time in total.
Reason: Fixed typo in the thread summary
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: CMake 3.16 now supports precompiled headers

Post by wmayer »

Very interesting.
Maybe we can reduce the compile time on windows.
I don't think that we can reduce the compile time much further because we already use pch for our Windows builds. Our solution is not a general approach as in cmake but tailored for MSVC builds on Windows only.

Since pch is activated for the Windows builds we already have seen a reduction of around 40% which is the same number as provided by your links and that's why I don't expect a considerable reduction.
User avatar
apeltauer
Posts: 399
Joined: Fri Aug 11, 2017 2:19 pm

Re: CMake 3.16 now supports precompiled headers

Post by apeltauer »

Can someone give me a little help what the cmake functions are doing?
GET_MSVC_PRECOMPILED_SOURCE(....)
Add_MSVC_PRECOMPILED_SOURCE(....)

@Werner, don’t you think we could also reduce the compile size when just using one big precompiled header file for all projects?
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: CMake 3.16 now supports precompiled headers

Post by wmayer »

apeltauer wrote: Sun Nov 03, 2019 6:08 pm @Werner, don’t you think we could also reduce the compile size when just using one big precompiled header file for all projects?
On travis it may reduce the build process by a a couple of minutes (for local builds it's probably much less). But the problem is that in the various PreCompiled.h files we have module-specific defines and handling them in a single PreCompiled.h is almost impossible. And if we even manage to get it working another major downside would be that as soon as you make a change you end up in re-compiling the whole project -- while for module-specific PCH's you would only rebuild that affected module.
Can someone give me a little help what the cmake functions are doing?
If you create a VS project and manually activate PCH it will activate some special compiler flags for the .cpp files. Therefore it must distinguish between the file the must be built as very first (the PreCompiled.cpp) and all other .cpp files. The ADD_MSVC_PRECOMPILED_HEADER macro just uses the MSVC-specific compiler switches.

GET_MSVC_PRECOMPILED_SOURCE can be used if in a CMake file you use a single variable to keep source and header files. Because the compiler switches can only be applied to source files you must extract the source files.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: CMake 3.16 now supports precompiled headers

Post by triplus »

If anybody is prepared to invest the effort on Linux, and share some results, that would be great. As reducing the (GCC) compile time on Travis would help for sure. And nice set of links by the way. For example on Linux ccache is commonly used and the hint about the need to set up ccache sloppiness:

https://ccache.dev/manual/latest.html#_ ... ed_headers

Is useful.
User avatar
apeltauer
Posts: 399
Joined: Fri Aug 11, 2017 2:19 pm

Re: CMake 3.16 now supports precompiled headers

Post by apeltauer »

wmayer wrote: Sun Nov 03, 2019 7:29 pm If you create a VS project and manually activate PCH it will activate some special compiler flags for the .cpp files. Therefore it must distinguish between the file the must be built as very first (the PreCompiled.cpp) and all other .cpp files. The ADD_MSVC_PRECOMPILED_HEADER macro just uses the MSVC-specific compiler switches.

GET_MSVC_PRECOMPILED_SOURCE can be used if in a CMake file you use a single variable to keep source and header files. Because the compiler switches can only be applied to source files you must extract the source files.
Thanks for the explanation...
Post Reply