Build: Fixed VS always triggering a full build when PCH is enabled, even if only a source file was edited

(cherry picked from commit 9b1dfe5e5e)
(cherry picked from commit b64583b7c1)
This commit is contained in:
Shauren
2019-06-02 21:09:53 +02:00
parent 101f82855e
commit c4f1144754
2 changed files with 27 additions and 8 deletions

View File

@@ -2341,7 +2341,7 @@ function (cotire_setup_pch_file_inclusion _language _target _wholeTarget _prefix
endif()
endfunction()
function (cotire_setup_prefix_file_inclusion _language _target _prefixFile)
function (cotire_setup_prefix_file_inclusion _language _target _prefixFile _prefixFileWasGenerated)
set (_sourceFiles ${ARGN})
# force the inclusion of the prefix header for the given source files
set (_flags "")
@@ -2352,8 +2352,10 @@ function (cotire_setup_prefix_file_inclusion _language _target _prefixFile)
set_property (SOURCE ${_sourceFiles} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
# mark sources as cotired to prevent them from being used in another cotired target
set_source_files_properties(${_sourceFiles} PROPERTIES COTIRE_TARGET "${_target}")
# make object files generated from source files depend on prefix header
set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_prefixFile}")
if (_prefixFileWasGenerated)
# make object files generated from source files depend on prefix header
set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_prefixFile}")
endif()
endfunction()
function (cotire_get_first_set_property_value _propertyValueVar _type _object)
@@ -2866,9 +2868,21 @@ function (cotire_process_target_language _language _configurations _target _whol
if (_prefixFile)
# check for user provided prefix header files
get_property(_prefixHeaderFiles TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER_INIT)
set (_prefixFileWasGenerated TRUE)
if (_prefixHeaderFiles)
cotire_setup_prefix_generation_from_provided_command(
${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" _cmds ${_prefixHeaderFiles})
list (LENGTH _prefixHeaderFiles _numberOfprefixHeaderFiles)
# if there is only one header specified in COTIRE_${_language}_PREFIX_HEADER_INIT then use it directly
# this works around a bug/change that causes Visual Studio to always rebuild entire project
# even if only one source file changed
# custom commands in cmake are designed to be always "out of date" so generation always happens
# Visual Studio determines "out of date" status by last modification timestamp, not content
if (_numberOfprefixHeaderFiles GREATER 1 OR NOT CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
cotire_setup_prefix_generation_from_provided_command(
${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" _cmds ${_prefixHeaderFiles})
else()
list (GET _prefixHeaderFiles 0 _prefixFile)
set (_prefixFileWasGenerated FALSE)
endif()
else()
cotire_setup_prefix_generation_from_unity_command(
${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" "${_unityFile}" _cmds ${_unitySourceFiles})
@@ -2891,7 +2905,7 @@ function (cotire_process_target_language _language _configurations _target _whol
endif()
elseif (_prefixHeaderFiles)
# user provided prefix header must be included unconditionally
cotire_setup_prefix_file_inclusion(${_language} ${_target} "${_prefixFile}" ${_sourceFiles})
cotire_setup_prefix_file_inclusion(${_language} ${_target} "${_prefixFile}" ${_prefixFileWasGenerated} ${_sourceFiles})
endif()
endif()
# mark target as cotired for language
@@ -2995,7 +3009,7 @@ function (cotire_setup_unity_target_pch_usage _languages _target)
get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
if (_userPrefixFile AND _prefixFile)
# user provided prefix header must be included unconditionally by unity sources
cotire_setup_prefix_file_inclusion(${_language} ${_target} "${_prefixFile}" ${_unityFiles})
cotire_setup_prefix_file_inclusion(${_language} ${_target} "${_prefixFile}" TRUE ${_unityFiles})
endif()
endif()
endforeach()

View File

@@ -166,6 +166,11 @@ foreach(SCRIPT_MODULE ${SCRIPT_MODULE_LIST})
trinity-core-interface
PUBLIC
game)
target_include_directories(${SCRIPT_MODULE_PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(${SCRIPT_MODULE_PROJECT_NAME}
PROPERTIES
FOLDER
@@ -221,7 +226,7 @@ set_target_properties(scripts
# Generate precompiled header
if (USE_SCRIPTPCH)
list(APPEND ALL_SCRIPT_PROJECTS scripts ${DYNAMIC_SCRIPT_MODULE_PROJECTS})
add_cxx_pch("${ALL_SCRIPT_PROJECTS}" ${PRIVATE_PCH_HEADER} ${PRIVATE_PCH_SOURCE})
add_cxx_pch("${ALL_SCRIPT_PROJECTS}" ${PRIVATE_PCH_HEADER})
endif()
# Remove all shared libraries in the installl directory which