diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim index ad560c9834..b80d3e5529 100644 --- a/Auxiliary/vim/syntax/cmake.vim +++ b/Auxiliary/vim/syntax/cmake.vim @@ -206,6 +206,8 @@ syn keyword cmakeProperty contained \ EXPORT_PROPERTIES \ EXTERNAL_OBJECT \ EchoString + \ FASTBUILD_CACHING + \ FASTBUILD_DISTRIBUTION \ FAIL_REGULAR_EXPRESSION \ FIND_LIBRARY_USE_LIB32_PATHS \ FIND_LIBRARY_USE_LIB64_PATHS diff --git a/Help/generator/FASTBuild.rst b/Help/generator/FASTBuild.rst index 0a92e09cf7..cfcaf2621a 100644 --- a/Help/generator/FASTBuild.rst +++ b/Help/generator/FASTBuild.rst @@ -40,6 +40,17 @@ The following variables can be used to configure this generator: * :variable:`CMAKE_FASTBUILD_USE_LIGHTCACHE` * :variable:`CMAKE_FASTBUILD_VERBOSE_GENERATOR` +Target Properties +----------------- + +The following target properties can be used to fine-tune behavior on a +per-target basis: + +* :prop_tgt:`FASTBUILD_CACHING` – + disables caching for a specific target. +* :prop_tgt:`FASTBUILD_DISTRIBUTION` – + disables distributed compilation for a specific target. + Notes ----- diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 58f5e3bf2e..c0ee1cdfcb 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -226,6 +226,8 @@ Properties on Targets /prop_tgt/EXPORT_NAME /prop_tgt/EXPORT_NO_SYSTEM /prop_tgt/EXPORT_PROPERTIES + /prop_tgt/FASTBUILD_CACHING + /prop_tgt/FASTBUILD_DISTRIBUTION /prop_tgt/FOLDER /prop_tgt/Fortran_BUILDING_INTRINSIC_MODULES /prop_tgt/Fortran_FORMAT diff --git a/Help/prop_tgt/FASTBUILD_CACHING.rst b/Help/prop_tgt/FASTBUILD_CACHING.rst new file mode 100644 index 0000000000..6ef1dc0d95 --- /dev/null +++ b/Help/prop_tgt/FASTBUILD_CACHING.rst @@ -0,0 +1,19 @@ +FASTBUILD_CACHING +----------------- + +.. versionadded:: 4.2 + +A target property that controls whether caching is enabled for the given +target in the generated ``fbuild.bff``. + +If set to ``OFF``, the :generator:`FASTBuild` generator disables caching +features for this target. This is useful for targets that are known to be +unreliably cached or not worth caching. + +Example: + +.. code-block:: cmake + + set_property(TARGET my_target PROPERTY FASTBUILD_CACHING OFF) + +Defaults to ``ON``. diff --git a/Help/prop_tgt/FASTBUILD_DISTRIBUTION.rst b/Help/prop_tgt/FASTBUILD_DISTRIBUTION.rst new file mode 100644 index 0000000000..58d6df6746 --- /dev/null +++ b/Help/prop_tgt/FASTBUILD_DISTRIBUTION.rst @@ -0,0 +1,19 @@ +FASTBUILD_DISTRIBUTION +---------------------- + +.. versionadded:: 4.2 + +A target property that controls whether distribution is enabled for the given +target in the generated ``fbuild.bff``. + +If set to ``OFF``, the :generator:`FASTBuild` generator disables distributed +compilation for this target. This can be helpful for targets that are fast to +build locally or are incompatible with distributed execution. + +Example: + +.. code-block:: cmake + + set_property(TARGET my_target PROPERTY FASTBUILD_DISTRIBUTION OFF) + +Defaults to ``ON``. diff --git a/Source/cmFastbuildNormalTargetGenerator.cxx b/Source/cmFastbuildNormalTargetGenerator.cxx index a067569fa8..16d47df939 100644 --- a/Source/cmFastbuildNormalTargetGenerator.cxx +++ b/Source/cmFastbuildNormalTargetGenerator.cxx @@ -1220,6 +1220,13 @@ cmFastbuildNormalTargetGenerator::GenerateObjects() std::string const staticCheckOptions = ComputeCodeCheckOptions(srcFile); + auto const isDisabled = [this](char const* prop) { + auto const propValue = this->GeneratorTarget->GetProperty(prop); + return propValue && propValue.IsOff(); + }; + bool const disableCaching = isDisabled("FASTBUILD_CACHING"); + bool const disableDistribution = isDisabled("FASTBUILD_DISTRIBUTION"); + for (auto const& arch : this->GetArches()) { std::string const compileOptions = GetCompileOptions(srcFile, arch); @@ -1261,6 +1268,12 @@ cmFastbuildNormalTargetGenerator::GenerateObjects() if (!objectListNode.CompilerOptions.empty()) { continue; } + if (disableCaching) { + objectListNode.AllowCaching = false; + } + if (disableDistribution) { + objectListNode.AllowDistribution = false; + } objectListNode.CompilerOutputPath = objOutDirWithPossibleSubdir; LogMessage(cmStrCat("Output path: ", objectListNode.CompilerOutputPath)); diff --git a/Source/cmGlobalFastbuildGenerator.cxx b/Source/cmGlobalFastbuildGenerator.cxx index 0cdc1d6146..2a4854509e 100644 --- a/Source/cmGlobalFastbuildGenerator.cxx +++ b/Source/cmGlobalFastbuildGenerator.cxx @@ -1174,6 +1174,12 @@ void cmGlobalFastbuildGenerator::WriteObjectList( Quote(ObjectList.CompilerOutputExtension), 2); WriteVariable("CompilerOutputKeepBaseExtension", "true", 2); WriteArray("CompilerInputFiles", Wrap(ObjectList.CompilerInputFiles), 2); + if (!ObjectList.AllowCaching) { + WriteVariable("AllowCaching", "false", 2); + } + if (!ObjectList.AllowDistribution) { + WriteVariable("AllowDistribution", "false", 2); + } if (ObjectList.Hidden) { WriteVariable("Hidden", "true", 2); } diff --git a/Source/cmGlobalFastbuildGenerator.h b/Source/cmGlobalFastbuildGenerator.h index de44ad4398..1cb08b4ea8 100644 --- a/Source/cmGlobalFastbuildGenerator.h +++ b/Source/cmGlobalFastbuildGenerator.h @@ -207,6 +207,8 @@ struct FastbuildObjectListNode : public FastbuildTargetBase std::string PCHOptions; std::vector CompilerInputFiles; + bool AllowCaching = true; + bool AllowDistribution = true; std::set ObjectOutputs; std::set ObjectDepends; diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 740e7753f4..54b1f4c1ba 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -213,6 +213,9 @@ elseif(CMake_TEST_Qt5) set(ninja_test_with_qt_version 5) endif() endif() +if(CMAKE_GENERATOR MATCHES "FASTBuild") + add_RunCMake_test(FASTBuild) +endif() if(CMAKE_GENERATOR MATCHES "Ninja") set(Ninja_ARGS -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} diff --git a/Tests/RunCMake/FASTBuild/CMakeLists.txt b/Tests/RunCMake/FASTBuild/CMakeLists.txt new file mode 100644 index 0000000000..86d47a7d5b --- /dev/null +++ b/Tests/RunCMake/FASTBuild/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.10) +project(${RunCMake_TEST}) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/FASTBuild/DisableCaching-check.cmake b/Tests/RunCMake/FASTBuild/DisableCaching-check.cmake new file mode 100644 index 0000000000..109af9028e --- /dev/null +++ b/Tests/RunCMake/FASTBuild/DisableCaching-check.cmake @@ -0,0 +1,2 @@ +set(REGEX_TO_MATCH "AllowCaching = false") +include(${RunCMake_SOURCE_DIR}/check.cmake) diff --git a/Tests/RunCMake/FASTBuild/DisableCaching.cmake b/Tests/RunCMake/FASTBuild/DisableCaching.cmake new file mode 100644 index 0000000000..aa01e0f952 --- /dev/null +++ b/Tests/RunCMake/FASTBuild/DisableCaching.cmake @@ -0,0 +1,2 @@ +add_executable(main main.cpp) +set_property(TARGET main PROPERTY FASTBUILD_CACHING OFF) diff --git a/Tests/RunCMake/FASTBuild/DisableDistribution-check.cmake b/Tests/RunCMake/FASTBuild/DisableDistribution-check.cmake new file mode 100644 index 0000000000..19f68450ae --- /dev/null +++ b/Tests/RunCMake/FASTBuild/DisableDistribution-check.cmake @@ -0,0 +1,2 @@ +set(REGEX_TO_MATCH "AllowDistribution = false") +include(${RunCMake_SOURCE_DIR}/check.cmake) diff --git a/Tests/RunCMake/FASTBuild/DisableDistribution.cmake b/Tests/RunCMake/FASTBuild/DisableDistribution.cmake new file mode 100644 index 0000000000..419deb2767 --- /dev/null +++ b/Tests/RunCMake/FASTBuild/DisableDistribution.cmake @@ -0,0 +1,2 @@ +add_executable(main main.cpp) +set_target_properties(main PROPERTIES FASTBUILD_DISTRIBUTION OFF) diff --git a/Tests/RunCMake/FASTBuild/RunCMakeTest.cmake b/Tests/RunCMake/FASTBuild/RunCMakeTest.cmake new file mode 100644 index 0000000000..a4eaebe318 --- /dev/null +++ b/Tests/RunCMake/FASTBuild/RunCMakeTest.cmake @@ -0,0 +1,4 @@ +include(RunCMake) + +run_cmake(DisableCaching) +run_cmake(DisableDistribution) diff --git a/Tests/RunCMake/FASTBuild/check.cmake b/Tests/RunCMake/FASTBuild/check.cmake new file mode 100644 index 0000000000..70734e5137 --- /dev/null +++ b/Tests/RunCMake/FASTBuild/check.cmake @@ -0,0 +1,11 @@ +set(fbuild_bff "${RunCMake_TEST_BINARY_DIR}/fbuild.bff") + +if(NOT EXISTS "${fbuild_bff}") + set(RunCMake_TEST_FAILED "Generator output file is missing:\n ${fbuild_bff}") + return() +endif() +file(READ "${fbuild_bff}" fbuild_bff) + +if(NOT fbuild_bff MATCHES ${REGEX_TO_MATCH}) + set(RunCMake_TEST_FAILED "Regex '${REGEX_TO_MATCH}' not found in the generated file ${RunCMake_TEST_BINARY_DIR}/fbuild.bff") +endif() diff --git a/Tests/RunCMake/FASTBuild/main.cpp b/Tests/RunCMake/FASTBuild/main.cpp new file mode 100644 index 0000000000..f8b643afbf --- /dev/null +++ b/Tests/RunCMake/FASTBuild/main.cpp @@ -0,0 +1,4 @@ +int main() +{ + return 0; +}