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:
macro( _precompiled_headers PrecompiledHeader PrecompiledSource SourcesVar ) if( MSVC ) get_filename_component( PrecompiledBasename ${PrecompiledHeader} NAME_WE ) set( PrecompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${PrecompiledBasename}.pch" ) set( Sources ${${SourcesVar}} ) set_property( SOURCE ${PrecompiledSource} APPEND_STRING PROPERTY COMPILE_FLAGS "/Yc\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\"" ) set_property( SOURCE ${PrecompiledSource} APPEND PROPERTY OBJECT_OUTPUTS "${PrecompiledBinary}" ) set_property( SOURCE ${Sources} APPEND_STRING PROPERTY COMPILE_FLAGS "/Yu\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\"" ) set_property( SOURCE ${Sources} APPEND PROPERTY OBJECT_DEPENDS "${PrecompiledBinary}" ) else() message( "Precompiled header support not provided for this platform" ) endif() # Add precompiled header to SourcesVar list( APPEND ${SourcesVar} ${PrecompiledSource} ) endmacro() The one interesting thing I have noticed is the way these compile flags translate to actual vcproj output: <FileConfiguration Name="MinSizeRel|Win32"> <Tool Name="VCCLCompilerTool" ForcedIncludeFiles="C:/Code/work/cmake-decomp/cmake/files/source/hash_map_hack.hpp;StdAfx.cpp" PrecompiledHeaderFile="C:/Code/work/cmake-decomp/build-vc9/server/exchange/tools/uploadlog/StdAfx.pch" PrecompiledHeaderThrough="StdAfx.h" UsePrecompiledHeader="2" AdditionalDependencies="C:\Code\work\cmake-decomp\build-vc9\server\exchange\tools\uploadlog\StdAfx.pch" /> 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?
-- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake