[CMake] Precompiled header support in Visual Studio?

Robert Dailey rcdailey at gmail.com
Fri Oct 21 16:11:44 EDT 2011


I did some searching and on stackoverflow I found a post that had code in it
to provide precompiled header support:
http://stackoverflow.com/questions/148570/using-pre-compiled-headers-with-cmake

Below is the relevant macro I am using from that post. Unfortunately this
does not seem to work when generating for VS2008 or VS 2003. For some reason
the CPP files other than the precompiled source itself do not have the
"Using precompiled headers" option set on them when I view that file's
properties.

What improvements could be made to this macro? I'm not familiar at all with
the command line parameters so I'm hoping someone can help me out.

macro( set_precompiled_header pch_header pch_source source )
  IF(MSVC)
    GET_FILENAME_COMPONENT(PrecompiledBasename ${PrecompiledHeader} NAME_WE)
    SET(PrecompiledBinary
"${CMAKE_CURRENT_BINARY_DIR}/${PrecompiledBasename}.pch")
    SET(Sources ${${SourcesVar}})

    SET_SOURCE_FILES_PROPERTIES(${PrecompiledSource}
                                PROPERTIES COMPILE_FLAGS
"/Yc\"${PrecompiledHeader}\" /Fp\"${PrecompiledBinary}\""
                                           OBJECT_OUTPUTS
"${PrecompiledBinary}")
    SET_SOURCE_FILES_PROPERTIES(${Sources}
                                PROPERTIES COMPILE_FLAGS
"/Yu\"${PrecompiledBinary}\" /FI\"${PrecompiledBinary}\"
/Fp\"${PrecompiledBinary}\""
                                           OBJECT_DEPENDS
"${PrecompiledBinary}")
  ENDIF(MSVC)
endmacro()

---------
Robert Dailey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111021/a04834d1/attachment.htm>


More information about the CMake mailing list