- enable use of precompiled headers for MSVC. Thanks to a small CMake script I recently found this could be done non-invasively.
Due to the VC++ 2015 headers being rather bloated (the average include size per source is 400-500kb) this provides a noticable compile speedup, although right now this only covers the game code, so there should be more room for improvement.
This commit is contained in:
parent
12129b0f07
commit
9cc873ecdd
2 changed files with 71 additions and 29 deletions
34
precompiled_headers.cmake
Normal file
34
precompiled_headers.cmake
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#
|
||||
# Christoph Heindl 2010
|
||||
# Precompiled Headers Demo
|
||||
# http://cheind.wordpress.com
|
||||
#
|
||||
|
||||
# Instructs the MSVC toolset to use the precompiled header PRECOMPILED_HEADER
|
||||
# for each source file given in the collection named by SOURCE_VARIABLE_NAME.
|
||||
function(enable_precompiled_headers PRECOMPILED_HEADER SOURCE_VARIABLE_NAME)
|
||||
if(MSVC)
|
||||
set(files ${${SOURCE_VARIABLE_NAME}})
|
||||
|
||||
# Generate precompiled header translation unit
|
||||
get_filename_component(pch_basename ${PRECOMPILED_HEADER} NAME_WE)
|
||||
set(pch_abs ${CMAKE_CURRENT_SOURCE_DIR}/${PRECOMPILED_HEADER})
|
||||
set(pch_unity ${CMAKE_CURRENT_BINARY_DIR}/${pch_basename}.cpp)
|
||||
FILE(WRITE ${pch_unity} "// Precompiled header unity generated by CMake\n")
|
||||
FILE(APPEND ${pch_unity} "#include <${pch_abs}>\n")
|
||||
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 ${files} )
|
||||
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(${SOURCE_VARIABLE_NAME} ${${SOURCE_VARIABLE_NAME}} ${pch_unity} PARENT_SCOPE)
|
||||
endif(MSVC)
|
||||
endfunction(enable_precompiled_headers)
|
||||
Loading…
Add table
Add a link
Reference in a new issue