mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 07:11:52 +08:00
FASTBuild: allow disabling of caching / distribution
Compilation is complicated. Caching / distribution is even more complicated. Sometimes there are bugs (in compilers as well as in FASTBuild), so export the option to disable those features for CMake targets.
This commit is contained in:

committed by
Brad King

parent
1dfe9898e6
commit
a8e64742aa
@@ -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
|
||||
|
@@ -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
|
||||
-----
|
||||
|
||||
|
@@ -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
|
||||
|
19
Help/prop_tgt/FASTBUILD_CACHING.rst
Normal file
19
Help/prop_tgt/FASTBUILD_CACHING.rst
Normal file
@@ -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``.
|
19
Help/prop_tgt/FASTBUILD_DISTRIBUTION.rst
Normal file
19
Help/prop_tgt/FASTBUILD_DISTRIBUTION.rst
Normal file
@@ -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``.
|
@@ -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));
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -207,6 +207,8 @@ struct FastbuildObjectListNode : public FastbuildTargetBase
|
||||
std::string PCHOptions;
|
||||
|
||||
std::vector<std::string> CompilerInputFiles;
|
||||
bool AllowCaching = true;
|
||||
bool AllowDistribution = true;
|
||||
|
||||
std::set<std::string> ObjectOutputs;
|
||||
std::set<std::string> ObjectDepends;
|
||||
|
@@ -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}
|
||||
|
3
Tests/RunCMake/FASTBuild/CMakeLists.txt
Normal file
3
Tests/RunCMake/FASTBuild/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(${RunCMake_TEST})
|
||||
include(${RunCMake_TEST}.cmake)
|
2
Tests/RunCMake/FASTBuild/DisableCaching-check.cmake
Normal file
2
Tests/RunCMake/FASTBuild/DisableCaching-check.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(REGEX_TO_MATCH "AllowCaching = false")
|
||||
include(${RunCMake_SOURCE_DIR}/check.cmake)
|
2
Tests/RunCMake/FASTBuild/DisableCaching.cmake
Normal file
2
Tests/RunCMake/FASTBuild/DisableCaching.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
add_executable(main main.cpp)
|
||||
set_property(TARGET main PROPERTY FASTBUILD_CACHING OFF)
|
2
Tests/RunCMake/FASTBuild/DisableDistribution-check.cmake
Normal file
2
Tests/RunCMake/FASTBuild/DisableDistribution-check.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
set(REGEX_TO_MATCH "AllowDistribution = false")
|
||||
include(${RunCMake_SOURCE_DIR}/check.cmake)
|
2
Tests/RunCMake/FASTBuild/DisableDistribution.cmake
Normal file
2
Tests/RunCMake/FASTBuild/DisableDistribution.cmake
Normal file
@@ -0,0 +1,2 @@
|
||||
add_executable(main main.cpp)
|
||||
set_target_properties(main PROPERTIES FASTBUILD_DISTRIBUTION OFF)
|
4
Tests/RunCMake/FASTBuild/RunCMakeTest.cmake
Normal file
4
Tests/RunCMake/FASTBuild/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,4 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake(DisableCaching)
|
||||
run_cmake(DisableDistribution)
|
11
Tests/RunCMake/FASTBuild/check.cmake
Normal file
11
Tests/RunCMake/FASTBuild/check.cmake
Normal file
@@ -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()
|
4
Tests/RunCMake/FASTBuild/main.cpp
Normal file
4
Tests/RunCMake/FASTBuild/main.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user