I have seen a few (old) posts on the 'net about hacking together some support for pre-compiled headers in CMake. They all seem a bit all-over the place and everyone has their own way of doing it. What is the best way of doing it currently?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- How to know full paths to DLL's from .csproj f
- Importing NuGet references through a local project
相关文章
- How to show location of errors, references to memb
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- How to track MongoDB requests from a console appli
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
Im using the following macro to generate and use precompiled headers:
Lets say you have a variable ${MySources} with all your sourcefiles, the code you would want to use would be simply be
The code would still function just fine on non-MSVC platforms too. Pretty neat :)
if you don't wanna reinvent the wheel, just use either Cotire as the top answer suggests or a simpler one - cmake-precompiled-header here. To use it just include the module and call:
The cleanest way is to add the precompiled option as a global option. In the vcxproj file this will show up as
<PrecompiledHeader>Use</PrecompiledHeader>
and not do this for every individual file.Then you need to add the
Create
option to the StdAfx.cpp. The following is how I use it:This is tested and works for MSVC 2010 and will create a MyDll.pch file, I am not bothered what file name is used so I didn't make any effort to specify it.
As the precompiled header option doesnt work for rc files, i needed to adjust the macro supplied by jari.
Edit: The usage of this precompiled headers reduced the Overall build time of my main Project from 4min 30s down to 1min 40s. This is for me a really good thing. In the precompile header are only headers like boost/stl/Windows/mfc.
I ended up using an adapted version of larsm macro. Using $(IntDir) for pch path keeps precompiled headers for debug and release builds separate.
An example of usage precompiled header with cmake and Visual Studio 2015
"stdafx.h", "stdafx.cpp" - precompiled header name.
Put the following below in the root cmake file.
Put the following below in the project cmake file.
"src" - a folder with source files.