[CMake] PCHSupport.cmake

Rajiv Bhagwat dataflow at mtnl.net.in
Mon Mar 26 05:01:19 EST 2007


Precompiled headers are too good to bypass. Ideally, support for these
should be built in CMake.

After playing with 1260-PCHSupport.cmake for some time to get it working for
Windows, I realized that a much simpler approach would be possible.
Specifically, having to set & change the build type every time was an
irritant.

Please check the attached file FindPCHSupport.cmake. Place it along with
your other local modules.
To use it, in your CMakeLists.txt file, add:
-----------
find_package(PCHSupport REQUIRED)
use_precompiled_header(myproject stdafx.h stdafx.cpp)
-----------

MSVC usually creates the stdafx.h and stdafx.cpp files for you, 'myproject'
is the project which will use these. It is easy to use other names, such as
precompiled.hpp and precompiled.cxx, for example. You need to have the cpp
file ready, the macro does not create it. Typically, the stdafx.cpp just
includes the stdafx.h header.

Couple of other notes: the location for the myproject.pch needs to be Debug/
or MinSizeRel/ etc w.r.t the build directory, this is done using $(IntDir)
MSVC build time variable. Creating it there and using it from there is not
obvious, it needed a bit of experimentation. The simpler approach of using a
single pch file causes problems while switching from release to debug
builds.
The macro adds just one small project to the build. CMake ensures that both
use same flags besides the PCH related flags. Note the use of '_EXPORTS',
which I believe is due to a recent CMake addition & without which the PCH
project won't work with 2.4.6.

And yes, I reckon that PCH is not a 'package', but instead of using another
location for storing such commonly used cross-project macros, I prefer to
move it with other *local* modules and use it in a similar fashion. Feel
free to 'include' the file otherwise.

The compile times are now down to 1/4 or 1/3 of the original - a huge
reduction.

Enjoy.
- Rajiv

----- Original Message ----- 
From: "Axel Roebel" <Axel.Roebel at ircam.fr>
To: <cmake at cmake.org>
Sent: Tue, 20 Feb 2007 8:59 PM
Subject: [CMake] PCHSupport.cmake


>
> I uploaded my current version of PCHSupport.cmake
> as attachment to bug 1260.
> The cmake module now supports adding the
> same precompiled header
> to multiple targets following a
> proposition by frederic heem
>
> See:
>
> http://www.cmake.org/Bug/bug.php?op=show&bugid=1260&pos=1
>
>
>
> -- 
> Axel Roebel
> IRCAM Analysis/Synthesis Team
> Phone: ++33-1-4478 4845 | Fax: ++33-1-4478 1540
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake

-------------- next part --------------
A non-text attachment was scrubbed...
Name: FindPCHSupport.cmake
Type: application/octet-stream
Size: 896 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20070326/012207fb/FindPCHSupport-0001.obj


More information about the CMake mailing list