From 3c231c381032e37bd6e8b37c890ea9b326ba265a Mon Sep 17 00:00:00 2001 From: Ray Molenkamp Date: Thu, 6 Jun 2019 08:26:15 -0600 Subject: 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. --- build_files/cmake/macros.cmake | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'build_files') 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() -- cgit v1.2.3