From b764c7c2731614147c3e4e6379c47df7a92bc3e3 Mon Sep 17 00:00:00 2001 From: Kaloyan Donev Date: Mon, 7 Feb 2022 09:01:32 +0200 Subject: VS: Add property to turn off Visual Studio compile batching Resolves: #23179 --- Auxiliary/vim/syntax/cmake.vim | 1 + Help/manual/cmake-properties.7.rst | 1 + Help/prop_tgt/VS_NO_COMPILE_BATCHING.rst | 21 +++++++++++++++ Help/release/dev/vs_buildcache_support.rst | 6 +++++ Source/cmVisualStudio10TargetGenerator.cxx | 4 ++- Tests/RunCMake/VS10Project/RunCMakeTest.cmake | 1 + .../VS10Project/VsNoCompileBatching-check.cmake | 31 ++++++++++++++++++++++ .../RunCMake/VS10Project/VsNoCompileBatching.cmake | 9 +++++++ 8 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 Help/prop_tgt/VS_NO_COMPILE_BATCHING.rst create mode 100644 Help/release/dev/vs_buildcache_support.rst create mode 100644 Tests/RunCMake/VS10Project/VsNoCompileBatching-check.cmake create mode 100644 Tests/RunCMake/VS10Project/VsNoCompileBatching.cmake diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim index d5361bd..381d97c 100644 --- a/Auxiliary/vim/syntax/cmake.vim +++ b/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 diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index f4efd3c..566eeae 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/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 diff --git a/Help/prop_tgt/VS_NO_COMPILE_BATCHING.rst b/Help/prop_tgt/VS_NO_COMPILE_BATCHING.rst new file mode 100644 index 0000000..f8a9fa6 --- /dev/null +++ b/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) diff --git a/Help/release/dev/vs_buildcache_support.rst b/Help/release/dev/vs_buildcache_support.rst new file mode 100644 index 0000000..bdda675 --- /dev/null +++ b/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. diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 7b197fa..912210d 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -3298,7 +3298,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)"); diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake index 139dcc7..b19c1a8 100644 --- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake +++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake @@ -84,3 +84,4 @@ endif() run_cmake(VsDotnetTargetFramework) run_cmake(VsDotnetTargetFrameworkVersion) +run_cmake(VsNoCompileBatching) diff --git a/Tests/RunCMake/VS10Project/VsNoCompileBatching-check.cmake b/Tests/RunCMake/VS10Project/VsNoCompileBatching-check.cmake new file mode 100644 index 0000000..4002c3f --- /dev/null +++ b/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 "^ *([^<>]+)") + set(ofn_actual "${CMAKE_MATCH_1}") + if(NOT "${ofn_actual}" STREQUAL "${ofn_expect}") + set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has '${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 property.") + return() + endif() +endmacro() + +VsNoCompileBatching_check(foo "$(IntDir)") +VsNoCompileBatching_check(foo_NB "$(IntDir)%(filename).obj") +VsNoCompileBatching_check(foo_NB_OFF "$(IntDir)") diff --git a/Tests/RunCMake/VS10Project/VsNoCompileBatching.cmake b/Tests/RunCMake/VS10Project/VsNoCompileBatching.cmake new file mode 100644 index 0000000..c96edce --- /dev/null +++ b/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) -- cgit v0.12