[cmake-developers] RFC: CMake precompiled header support and custom compiler based implementation

Adam Strzelecki ono at java.pl
Sat Feb 28 11:59:55 EST 2015


Dear CMake developers,

I wish to raise up the subject about native precompiled header support in CMake. There are obvious reasons to use precompiled headers with big source code bases, and there were several requests on the list for precompiled header support and several 3rd party implementations.

Now I wish to share mine:

  https://github.com/nanoant/CMakePCHCompiler


The main goal is to solve shortcomings on all solutions using custom commands, that simply are not able to catch all compiler defines or flags, like these added via add_definitions, simply because these flags are accessible via any variable back to custom function.

My solution uses a CXX meta-compiler (CXXPCH) that simply defines patched compiler run template. This ensures that all defines and flags also apply to precompiled header.


I also want to suggest to put native precompiled header support somewhere high on the TODO list and I propose this simple API for specifying precompiled header for given target:

	target_precompiled_header(<target> <path/to/precompiled_header.h>)

	target_precompiled_header(<target> <path/to/precompiled_header.h> SHARED
	                          <other_target_to_share_precompiled_header_with>)

Regards,
-- 
Adam



More information about the cmake-developers mailing list