cmake-precompiled-header
cmake-precompiled-header copied to clipboard
Visual Studio and GCC precompiled header macro for CMake
cmake-precompiled-header
Precompiled header setup for CMake. Supported CMake generators:
- Visual Studio
- NMake Makefiles
- Unix Makefiles (GCC)
- MinGW Makefiles
- MSYS Makefiles
- Ninja
Usage
Create a pchheader.{c,cpp} and pchheader.h and add then to the CMake target:
add_library(target ... pchheader.cpp pchheeader.h)
pchheader.h can include all the huge header files that are used everywhere in your project:
#include <string>
#include <iostream>
#include <list>
#include <map>
pchheader.{c,cpp} should just include the header file:
#include "pchheader.h"
In your main CMakeLists.txt, include the macro file:
include(PrecompiledHeader.cmake)
Then add this line, to set up precompiled headers:
add_precompiled_header(target pchheader.h FORCEINCLUDE)
Additional documentation is in PrecompiledHeader.cmake.