There is a very old, long-standing open bug (in the "backlog" now) that outlines many of the issues related to supporting pre-compiled headers.
http://public.kitware.com/Bug/view.php?id=1260 Doing a "copy and rename" strategy for StdAfx.cpp is a reasonable work-around until such time as this can be addressed in a general way. General support for this particular feature does not appear to be on any short-term horizon as far as I'm aware. HTH, David On Thu, Mar 17, 2011 at 1:53 PM, Kawicki, Ryan H <[email protected]> wrote: >> > Quick question. >> > >> > I am trying to add precompiled headers to a project that >> has been converted to use Cmake. >> > >> > In our library directory, we include all our source and >> build two targets (one static and one dynamic), but setting >> multiple source values only affects the source and not the >> source associated to a particular target. Is there a way to >> get around this issue or something in the works to correct >> this, like an optional target command? >> > >> > Thanks... >> > >> > Code below describing the issue: >> > >> > FUNCTION (ADD_MSVC_PRECOMPILED_HEADERS >> > PrecompiledSource PrecompiledHeader TargetProject) >> > IF (MSVC) >> > # define the location of the precompiled header >> > SET(PrecompiledBinary >> "${CMAKE_CURRENT_BINARY_DIR}/${TargetProject}.pch") >> > # set the target project to use the precompiled binary >> > SET_PROPERTY(TARGET ${TargetProject} >> > APPEND >> > PROPERTY COMPILE_FLAGS >> > "/Yu\"${PrecompiledHeader}\" >> /Fp\"${PrecompiledBinary}\"") >> > # set the source file to compile out the pch >> > SET_PROPERTY(SOURCE ${PrecompiledSource} >> > APPEND >> > PROPERTY COMPILE_FLAGS >> > "/Yc\"${PrecompiledHeader}\" >> /Fp\"${PrecompiledBinary}\"") >> > ENDIF (MSVC) >> > ENDFUNCTION (ADD_MSVC_PRECOMPILED_HEADERS) >> > >> > ADD_LIBRARY(MyLibDynamic SHARED ${SRC}) >> ADD_LIBRARY(MyLibStatic STATIC >> > ${SRC}) >> > >> > ADD_MSVC_PRECOMPILED_HEADERS(StdAfx.cpp StdAfx.h MyLibDynamic) >> > ADD_MSVC_PRECOMPILED_HEADERS(StdAfx.cpp StdAfx.h MyLibStatic) >> > >> > When MyLibDynamic builds, it builds MyLibStatic.pch but >> tries to find MyLibDynamic.pch. >> > This is because the second function call to setup >> precompiled headers >> > modifies what appears to be a property that is not unique to all >> > targets added at the same directory level of the CMakeLists. >> > >> > Thanks again. . . >> >> You might copy or symlink the concerned sources, one per >> target, and impose the properties on these symlinks, e.g. as follows: >> >> ADD_CUSTOM_COMMAND( >> OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/StdAfxDynamic.cpp >> OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/StdAfxStatic.cpp >> COMMAND ${CMAKE_COMMAND} -E create_symlink >> ${CMAKE_CURRENT_SOURCE_DIR}/StdAfx.cpp >> ${CMAKE_CURRENT_BINARY_DIR}/StdAfxDynamic.cpp >> COMMAND ${CMAKE_COMMAND} -E create_symlink >> ${CMAKE_CURRENT_SOURCE_DIR}/StdAfx.cpp >> ${CMAKE_CURRENT_BINARY_DIR}/StdAfxStatic.cpp >> DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/StdAfx.cpp >> ) >> >> ADD_LIBRARY(MyLibDynamic SHARED StdAfxDynamic.cpp ${SRC}) >> ADD_LIBRARY(MyLibStatic STATIC StdAfxStatic.cpp ${SRC}) >> >> ADD_MSVC_PRECOMPILED_HEADERS(StdAfxDynamic.cpp StdAfx.h >> MyLibDynamic) ADD_MSVC_PRECOMPILED_HEADERS(StdAfxStatic.cpp >> StdAfx.h MyLibStatic) >> >> Of course, SRC mustn't contain StdAfx.cpp anymore for this to work. >> >> 'hope that helps. >> >> Regards, >> >> Michael > > Thanks for the reply. While I haven't tested this solution out, > I don't think I would prefer this kind of solution, as I would > hope that CMake would support this option out of the box. > > Looks like I'll have to see if there is a ticket for this > kind of change or search the code to see how hard this > can be added to CMake. > > Thanks, > > Ryan > _______________________________________________ > 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 > _______________________________________________ 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
