To my knowledge there are no dedicated target properties or commands that allow one to easily add precompiled headers support to a target. In my case, I'm generating for visual studio and I have the following that I can use to enable precompiled headers:<div>
<br></div><div><div>macro( _precompiled_headers PrecompiledHeader PrecompiledSource SourcesVar )</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if( MSVC )</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>get_filename_component( PrecompiledBasename ${PrecompiledHeader} NAME_WE )</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>set( PrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${PrecompiledBasename}.pch" )</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>set( Sources ${${SourcesVar}} )</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>set_property(</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>SOURCE ${PrecompiledSource} APPEND_STRING PROPERTY</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>COMPILE_FLAGS "/Yc\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\""</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>)</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>set_property(</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>SOURCE ${PrecompiledSource} APPEND PROPERTY</div><div>
<span class="Apple-tab-span" style="white-space:pre">                        </span>OBJECT_OUTPUTS "${PrecompiledBinary}"</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>set_property(</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>SOURCE ${Sources} APPEND_STRING PROPERTY</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>COMPILE_FLAGS "/Yu\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\""</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>set_property(</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>SOURCE ${Sources} APPEND PROPERTY</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>OBJECT_DEPENDS "${PrecompiledBinary}"</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>else()</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>message( "Precompiled header support not provided for this platform" )</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>endif()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span># Add precompiled header to SourcesVar</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>list( APPEND ${SourcesVar} ${PrecompiledSource} )</div><div>endmacro()</div></div><div><br></div><div>The one interesting thing I have noticed is the way these compile flags translate to actual vcproj output:</div>
<div><div><br></div><div><span style="white-space:pre-wrap">                                </span><FileConfiguration</div><div><span style="white-space:pre-wrap">                                        </span>Name="MinSizeRel|Win32"></div>
<div><span style="white-space:pre-wrap">                                        </span><Tool</div><div><span style="white-space:pre-wrap">                                        </span>Name="VCCLCompilerTool"</div><div><span style="white-space:pre-wrap">                                        </span>ForcedIncludeFiles="C:/Code/work/cmake-decomp/cmake/files/source/hash_map_hack.hpp;StdAfx.cpp"</div>
<div><span style="white-space:pre-wrap">                                        </span>PrecompiledHeaderFile="C:/Code/work/cmake-decomp/build-vc9/server/exchange/tools/uploadlog/StdAfx.pch"</div><div><span style="white-space:pre-wrap">                                        </span>PrecompiledHeaderThrough="StdAfx.h"</div>
<div><span style="white-space:pre-wrap">                                        </span>UsePrecompiledHeader="2"</div><div><span style="white-space:pre-wrap">                                        </span>AdditionalDependencies="C:\Code\work\cmake-decomp\build-vc9\server\exchange\tools\uploadlog\StdAfx.pch"</div>
<div><span style="white-space:pre-wrap">                                        </span>/></div></div><div><br></div><div>CMake seems to do more than just add them as general compiler flags, it seems to know exactly which attributes in the VCPROJ XML are mapped to their respective command line alternatives, and uses the appropriate ones. If this is true, why do we not have a dedicated target & source file property that I can use to enable precompiled headers instead of using these command line strings directly? Am I misunderstanding something?</div>