CMake 3.16 now supports precompiled headers

Having trouble installing or compiling FreeCAD? Get help here.
User avatar
apeltauer
Posts: 212
Joined: Fri Aug 11, 2017 2:19 pm

CMake 3.16 now supports precompiled headers

Postby apeltauer » Sun Nov 03, 2019 8:23 am

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
Site Admin
Posts: 14999
Joined: Thu Feb 19, 2009 10:32 am

Re: CMake 3.16 now supports precompiled headers

Postby wmayer » Sun Nov 03, 2019 3:32 pm

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: 212
Joined: Fri Aug 11, 2017 2:19 pm

Re: CMake 3.16 now supports precompiled headers

Postby apeltauer » Sun Nov 03, 2019 6:08 pm

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
Site Admin
Posts: 14999
Joined: Thu Feb 19, 2009 10:32 am

Re: CMake 3.16 now supports precompiled headers

Postby wmayer » Sun Nov 03, 2019 7:29 pm

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
Posts: 8802
Joined: Mon Dec 12, 2011 4:45 pm

Re: CMake 3.16 now supports precompiled headers

Postby triplus » Sun Nov 03, 2019 11:51 pm

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: 212
Joined: Fri Aug 11, 2017 2:19 pm

Re: CMake 3.16 now supports precompiled headers

Postby apeltauer » Mon Nov 04, 2019 6:24 am

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...