diff options
author | Ray Molenkamp <github@lazydodo.com> | 2019-06-06 17:26:15 +0300 |
---|---|---|
committer | Ray Molenkamp <github@lazydodo.com> | 2019-06-06 17:26:15 +0300 |
commit | 3c231c381032e37bd6e8b37c890ea9b326ba265a (patch) | |
tree | 683a55ec25f6f43902e39e82c5341d2c332ab64e /build_files | |
parent | 87fde57b63887aa3082917eebcff5f3f069d610a (diff) |
cmake/msvc: Add ninja support for precompiled headers
Ninja was unable to see the dependency between the cpp
that generated the pch and the compile units that used
it. Explicitly managing this now makes precompiled headers
work with both msvc and clang, with both msbuild and ninja
based generators.
Diffstat (limited to 'build_files')
-rw-r--r-- | build_files/cmake/macros.cmake | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index d1894ad8f24..d7716913cf5 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -1222,9 +1222,24 @@ macro(WINDOWS_SIGN_TARGET target) endmacro() macro(blender_precompile_headers target cpp header) - if (MSVC AND NOT ${CMAKE_GENERATOR} STREQUAL "Ninja") + if (MSVC) + # get the name for the pch output file + get_filename_component( pchbase ${cpp} NAME_WE ) + set( pchfinal "${CMAKE_CURRENT_BINARY_DIR}/${pchbase}.pch" ) + + # mark the cpp as the one outputting the pch + set_property(SOURCE ${cpp} APPEND PROPERTY OBJECT_OUTPUTS "${pchfinal}") + + # get all sources for the target + get_target_property(sources ${target} SOURCES) + + # make all sources depend on the pch to enforce the build order + foreach(src ${sources}) + set_property(SOURCE ${src} APPEND PROPERTY OBJECT_DEPENDS "${pchfinal}") + endforeach() + target_sources(${target} PRIVATE ${cpp} ${header}) - set_target_properties(${target} PROPERTIES COMPILE_FLAGS "/Yu${header} /FI${header}") - set_source_files_properties(${cpp} PROPERTIES COMPILE_FLAGS "/Yc${header}") + set_target_properties(${target} PROPERTIES COMPILE_FLAGS "/Yu${header} /Fp${pchfinal} /FI${header}") + set_source_files_properties(${cpp} PROPERTIES COMPILE_FLAGS "/Yc${header} /Fp${pchfinal}") endif() endmacro() |