On Thu, Feb 16, 2012 at 7:39 PM,  <[email protected]> wrote:
> My team has been using precompiled headers under CMake and Visual Studio
> 2008 for quite a while.  Now we’ve switched to VS 2010,  the cmake code we
> used to support precompiled headers is no longer working.
>
>
>
> The following is the code in question and we’re just using
> set_source_files_properties to add the appropreiate /Yc , /Yu and /FI flags.
>
>
>
> It appears, under VS 2010, the property manager is not accepting or over
> writing these settings.
>
>
>
> Doesn’t anyone know how to get precompiled headers working under CMake for
> Visual Studio 2010?
>
>
>
>
>
>
>
>
>
> IF(EXISTS ${pch_unity})
>
>    FILE(READ ${pch_unity} buffer)
>
> ENDIF(EXISTS ${pch_unity})
>
> IF(NOT (${buffer} STREQUAL ${file_contents}))
>
>    FILE(WRITE ${pch_unity} ${file_contents})
>
> ENDIF(NOT (${buffer} STREQUAL ${file_contents}))
>
> SET_SOURCE_FILES_PROPERTIES(${pch_unity}  PROPERTIES COMPILE_FLAGS
> "/Yc\"${pch_abs}\"")
>
>
>
> ###########################################################
>
> #
>
> # Update properties of source files to use the precompiled header.
>
> # Additionally, force the inclusion of the precompiled header at beginning
> of each source file.
>
> #
>
> FOREACH(source_file ${srcFilesThatUsePCH} )
>
>    SET_SOURCE_FILES_PROPERTIES(
>
>      ${source_file}
>
>      PROPERTIES COMPILE_FLAGS
>
>      "/Yu\"${pch_abs}\" /FI\"${pch_abs}\""
>
>    )
>
> ENDFOREACH(source_file)
>
>
>
> ###########################################################
>
> #
>
> # Finally, update the source file collection to contain the precompiled
> header translation unit
>
> #
>
> SET(${FILES_VARIABLE_NAME} ${${FILES_VARIABLE_NAME}} ${pch_unity}
> PARENT_SCOPE)
>
>

For me I use the same exact macro that I have used since VS 2005.

Attached is the macro and here is an example library that uses the macro.

SET( ${PROJECT_NAME}_SRCS
        ./src/smException.cxx
        ./src/smitkIndent.cxx
        ./src/smState.cxx
        ./src/smPropertyMap.cxx
        ./src/smOperation.cxx
        ./src/smPgmSettings.cxx
        ./src/smStringList.cxx
        ./src/smObject.cxx
        ./src/smAppBase.cxx
        ./src/smSpawnJob.cxx
        ./src/smLog.cxx
        ./src/smBIRADS7.cxx
        ./src/smErrorBase.cxx
)

SET( ${PROJECT_NAME}_EXT_HDRS
        ./Include/smException.h
        ./Include/smitkIndent.h
        ./Include/smMacros.h
        ./Include/smPropertyMap.h
        ./Include/smOperation.h
        ./Include/smPgmSettings.h
        ./Include/smStringList.h
        ./Include/smConstants.h
        ./Include/smLog.h
        ./Include/smBIRADS7.h
        ./Include/smErrorBase.h
)

SET( ${PROJECT_NAME}_MOC_HDRS
        ./Include/smState.h
        ./Include/smObject.h
        ./Include/smAppBase.h
        ./Include/smSpawnJob.h
)

# some .ui files
SET( ${PROJECT_NAME}_UIS
)

# and finally an resource file
SET( ${PROJECT_NAME}_RCS
)

SET( ${PROJECT_NAME}_INT_HDRS

)

#Add precompiled header support
MSVC_PCH_SUPPORT(${PROJECT_NAME})

# this command will generate rules that will run rcc on all files from
UPMC_LA_RCS
# in result UPMC_LA_RC_SRCS variable will contain paths to files produced by rcc
QT4_ADD_RESOURCES( ${PROJECT_NAME}_RC_SRCS ${${PROJECT_NAME}_RCS} )

# and finally this will run moc:
QT4_WRAP_CPP( ${PROJECT_NAME}_MOC_SRCS ${${PROJECT_NAME}_MOC_HDRS} )

# this will run uic on .ui files:
QT4_WRAP_UI( ${PROJECT_NAME}_UI_HDRS ${${PROJECT_NAME}_UIS} )

IF(BUILD_EXPERIMENTAL)
add_subdirectory(Experimental)
ENDIF(BUILD_EXPERIMENTAL)

include_directories(
        ${PROJECT_BINARY_DIR}
        ${PROJECT_BINARY_DIR}/..
        ${PROJECT_SOURCE_DIR}/Include
        ${STUDY_MANAGER_SRC}/Include
)

add_library(${PROJECT_NAME}
        ${${PROJECT_NAME}_SRCS}
        ${${PROJECT_NAME}_EXT_HDRS}
        ${${PROJECT_NAME}_MOC_HDRS}
        ${${PROJECT_NAME}_MOC_SRCS}
        ${${PROJECT_NAME}_INT_HDRS}
        ${${PROJECT_NAME}_UI_HDRS}
        ${${PROJECT_NAME}_RC_SRCS}
)

John

Attachment: MSVCPCHSupport.cmake
Description: Binary data

--

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

Reply via email to