Преглед на файлове

Merge topic 'vs_buildcache_support'

b764c7c273 VS: Add property to turn off Visual Studio compile batching

Acked-by: Kitware Robot <[email protected]>
Merge-request: !6957
Brad King преди 3 години
родител
ревизия
25003baf50

+ 1 - 0
Auxiliary/vim/syntax/cmake.vim

@@ -381,6 +381,7 @@ syn keyword cmakeProperty contained
             \ VS_JUST_MY_CODE_DEBUGGING
             \ VS_KEYWORD
             \ VS_MOBILE_EXTENSIONS_VERSION
+            \ VS_NO_COMPILE_BATCHING
             \ VS_NO_SOLUTION_DEPLOY
             \ VS_PACKAGE_REFERENCES
             \ VS_PLATFORM_TOOLSET

+ 1 - 0
Help/manual/cmake-properties.7.rst

@@ -402,6 +402,7 @@ Properties on Targets
    /prop_tgt/VS_JUST_MY_CODE_DEBUGGING
    /prop_tgt/VS_KEYWORD
    /prop_tgt/VS_MOBILE_EXTENSIONS_VERSION
+   /prop_tgt/VS_NO_COMPILE_BATCHING
    /prop_tgt/VS_NO_SOLUTION_DEPLOY
    /prop_tgt/VS_PACKAGE_REFERENCES
    /prop_tgt/VS_PLATFORM_TOOLSET

+ 21 - 0
Help/prop_tgt/VS_NO_COMPILE_BATCHING.rst

@@ -0,0 +1,21 @@
+VS_NO_COMPILE_BATCHING
+----------------------
+
+.. versionadded:: 3.24
+
+Turn off compile batching for the target. Usually MSBuild calls the compiler
+with multiple c/cpp files and compiler starts subprocesses for each file to
+make the build parallel. If you want compiler to be invoked with one file at
+a time set VS_NO_COMPILE_BATCHING to ON. If this flag is set MSBuild will call
+compiler with one c/cpp file at a time. Useful when you want to use tool that
+replaces the compiler, for example some build caching tool.
+
+Example
+^^^^^^^
+
+This shows setting the variable for the target foo.
+
+.. code-block:: cmake
+
+  add_library(foo SHARED foo.cpp)
+  set_property(TARGET foo PROPERTY VS_NO_COMPILE_BATCHING ON)

+ 6 - 0
Help/release/dev/vs_buildcache_support.rst

@@ -0,0 +1,6 @@
+vs_buildcache_support
+---------------------
+
+* The :prop_tgt:`VS_NO_COMPILE_BATCHING` target property was added to
+  tell :ref:`Visual Studio Generators` whether to disable compiler parallelism
+  and call the compiler with one c/cpp file at a time.

+ 3 - 1
Source/cmVisualStudio10TargetGenerator.cxx

@@ -3309,7 +3309,9 @@ void cmVisualStudio10TargetGenerator::WriteClOptions(
   } else if (this->MSTools) {
     cmsys::RegularExpression clangToolset("v[0-9]+_clang_.*");
     const char* toolset = this->GlobalGenerator->GetPlatformToolset();
-    if (toolset && clangToolset.find(toolset)) {
+    cmValue noCompileBatching =
+      this->GeneratorTarget->GetProperty("VS_NO_COMPILE_BATCHING");
+    if (noCompileBatching.IsOn() || (toolset && clangToolset.find(toolset))) {
       e2.Element("ObjectFileName", "$(IntDir)%(filename).obj");
     } else {
       e2.Element("ObjectFileName", "$(IntDir)");

+ 1 - 0
Tests/RunCMake/VS10Project/RunCMakeTest.cmake

@@ -84,3 +84,4 @@ endif()
 
 run_cmake(VsDotnetTargetFramework)
 run_cmake(VsDotnetTargetFrameworkVersion)
+run_cmake(VsNoCompileBatching)

+ 31 - 0
Tests/RunCMake/VS10Project/VsNoCompileBatching-check.cmake

@@ -0,0 +1,31 @@
+macro(VsNoCompileBatching_check tgt ofn_expect)
+  set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/${tgt}.vcxproj")
+  if(NOT EXISTS "${vcProjectFile}")
+    set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not exist.")
+    return()
+  endif()
+
+  set(HAVE_OFN 0)
+
+  file(STRINGS "${vcProjectFile}" lines)
+  foreach(line IN LISTS lines)
+    if(line MATCHES "^ *<ObjectFileName>([^<>]+)</ObjectFileName>")
+      set(ofn_actual "${CMAKE_MATCH_1}")
+      if(NOT "${ofn_actual}" STREQUAL "${ofn_expect}")
+        set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has <ObjectFileName> '${ofn_actual}', not '${ofn_expect}'.")
+        return()
+      endif()
+      set(HAVE_OFN 1)
+      break()
+    endif()
+  endforeach()
+
+  if(NOT HAVE_OFN)
+    set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <ObjectFileName> property.")
+    return()
+  endif()
+endmacro()
+
+VsNoCompileBatching_check(foo "$(IntDir)")
+VsNoCompileBatching_check(foo_NB "$(IntDir)%(filename).obj")
+VsNoCompileBatching_check(foo_NB_OFF "$(IntDir)")

+ 9 - 0
Tests/RunCMake/VS10Project/VsNoCompileBatching.cmake

@@ -0,0 +1,9 @@
+enable_language(CXX)
+
+add_library(foo foo.cpp)
+
+add_library(foo_NB foo.cpp)
+set_property(TARGET foo_NB PROPERTY VS_NO_COMPILE_BATCHING ON)
+
+add_library(foo_NB_OFF foo.cpp)
+set_property(TARGET foo_NB_OFF PROPERTY VS_NO_COMPILE_BATCHING OFF)