- CMake: use precompiled headers when compiling for msvc. This makes compilation about 40% faster.

pull/32/head
Alexander Gessler 2013-04-20 23:15:59 +02:00
parent f476634461
commit 4b748c2442
3 changed files with 33 additions and 5 deletions

View File

@ -27,6 +27,8 @@ endif()
INCLUDE (FindPkgConfig)
INCLUDE_DIRECTORIES( include )
INCLUDE (PrecompiledHeader)
# If this is an in-source build (CMAKE_SOURCE_DIR == CMAKE_BINARY_DIR),
# write the library/executable files to the respective directories in the
# source tree. During an out-of-source build, however, do not litter this

View File

@ -0,0 +1,25 @@
MACRO(ADD_MSVC_PRECOMPILED_HEADER PrecompiledHeader PrecompiledSource SourcesVar)
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}")
# Do not consider .c files
foreach(fname ${Sources})
GET_FILENAME_COMPONENT(fext ${fname} EXT)
if(fext STREQUAL ".cpp")
SET_SOURCE_FILES_PROPERTIES(${fname}
PROPERTIES COMPILE_FLAGS "/Yu\"${PrecompiledBinary}\" /FI\"${PrecompiledBinary}\" /Fp\"${PrecompiledBinary}\""
OBJECT_DEPENDS "${PrecompiledBinary}")
endif(fext STREQUAL ".cpp")
endforeach(fname)
ENDIF(MSVC)
# Add precompiled header to SourcesVar
LIST(APPEND ${SourcesVar} ${PrecompiledSource})
ENDMACRO(ADD_MSVC_PRECOMPILED_HEADER)

View File

@ -58,8 +58,6 @@ SET( PUBLIC_HEADERS
SET( Core_SRCS
Assimp.cpp
AssimpPCH.cpp
AssimpPCH.h
)
SET( Boost_SRCS
@ -620,7 +618,7 @@ else (UNZIP_FOUND)
SET (unzip_compile_SRCS ${unzip_SRCS})
endif (UNZIP_FOUND)
SET( assim_src
SET( assimp_src
# Assimp Files
${Core_SRCS}
${Common_SRCS}
@ -681,13 +679,16 @@ SET( assim_src
${PUBLIC_HEADERS}
${COMPILER_HEADERS}
)
ADD_MSVC_PRECOMPILED_HEADER("AssimpPCH.h" "AssimpPCH.cpp" assimp_src)
IF ( ASSIMP_BUILD_STATIC_LIB )
ADD_LIBRARY( assimp STATIC
${assim_src}
${assimp_src}
)
ELSE ( ASSIMP_BUILD_STATIC_LIB )
ADD_LIBRARY( assimp SHARED
${assim_src}
${assimp_src}
)
ENDIF ( ASSIMP_BUILD_STATIC_LIB )