[Bf-blender-cvs] [3c231c38103] master: cmake/msvc: Add ninja support for precompiled headers

Ray Molenkamp noreply at git.blender.org
Thu Jun 6 16:26:21 CEST 2019


Commit: 3c231c381032e37bd6e8b37c890ea9b326ba265a
Author: Ray Molenkamp
Date:   Thu Jun 6 08:26:15 2019 -0600
Branches: master
https://developer.blender.org/rB3c231c381032e37bd6e8b37c890ea9b326ba265a

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.

===================================================================

M	build_files/cmake/macros.cmake

===================================================================

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()



More information about the Bf-blender-cvs mailing list