Merge topic 'JOB_POOL_COMPILE-FileSet-property'

8e6eec8125 FILE_SET: add JOB_POOL_COMPILE property support

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12005
This commit is contained in:
Brad King
2026-05-05 14:55:32 +00:00
committed by Kitware Robot
11 changed files with 108 additions and 17 deletions

View File

@@ -545,6 +545,7 @@ Properties on File Sets
/prop_fs/COMPILE_DEFINITIONS
/prop_fs/COMPILE_OPTIONS
/prop_fs/CXX_SCAN_FOR_MODULES
/prop_fs/JOB_POOL_COMPILE
/prop_fs/INCLUDE_DIRECTORIES
/prop_fs/INDEPENDENT_FILES
/prop_fs/INTERFACE_COMPILE_DEFINITIONS

View File

@@ -0,0 +1,28 @@
JOB_POOL_COMPILE
----------------
.. versionadded:: 4.4
Ninja only: Pool used for compiling.
The number of parallel compile processes could be limited by defining
pools with the global :prop_gbl:`JOB_POOLS`
property and then specifying here the pool name.
This allows to override the :prop_sf:`JOB_POOL_COMPILE` and
:prop_tgt:`JOB_POOL_COMPILE` values for specific source files within a same
target.
For instance:
.. code-block:: cmake
set_property(FILE_SET my_fileset TYPE SOURCE PROPERTY JOB_POOL_COMPILE two_jobs)
This property is undefined by default.
See Also
^^^^^^^^
* :prop_sf:`JOB_POOL_COMPILE` source file property
* :prop_tgt:`JOB_POOL_COMPILE` target property

View File

@@ -19,3 +19,9 @@ For instance:
set_property(SOURCE main.cc PROPERTY JOB_POOL_COMPILE two_jobs)
This property is undefined by default.
See Also
^^^^^^^^
* :prop_fs:`JOB_POOL_COMPILE` file set property
* :prop_tgt:`JOB_POOL_COMPILE` target property

View File

@@ -15,3 +15,9 @@ For instance:
This property is initialized by the value of
:variable:`CMAKE_JOB_POOL_COMPILE`.
See Also
^^^^^^^^
* :prop_fs:`JOB_POOL_COMPILE` file set property
* :prop_sf:`JOB_POOL_COMPILE` source file property

View File

@@ -0,0 +1,5 @@
FILE_SET-JOB_POOL_COMPILE
-------------------------
* File sets gained the support of the :prop_fs:`JOB_POOL_COMPILE` file set
property.

View File

@@ -1041,7 +1041,8 @@ void cmNinjaNormalTargetGenerator::WriteNvidiaDeviceLinkStatement(
vars["LINK_FLAGS"], frameworkPath, linkPath,
genTarget);
this->addPoolNinjaVariable("JOB_POOL_LINK", genTarget, nullptr, vars);
this->addPoolNinjaVariable("JOB_POOL_LINK", config, genTarget, nullptr,
vars);
vars["MANIFESTS"] = this->GetManifests(config);
@@ -1384,7 +1385,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
this->TargetLinkLanguage(config), "CURRENT", false);
}
this->addPoolNinjaVariable("JOB_POOL_LINK", gt, nullptr, vars);
this->addPoolNinjaVariable("JOB_POOL_LINK", config, gt, nullptr, vars);
this->UseLWYU = this->GetLocalGenerator()->AppendLWYUFlags(
vars["LINK_FLAGS"], this->GetGeneratorTarget(),

View File

@@ -1787,8 +1787,9 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
scanningFiles.ScanningOutput = cmStrCat(objectFileName, ".ddi");
}
this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
source, ppBuild.Variables);
this->addPoolNinjaVariable("JOB_POOL_COMPILE", config,
this->GetGeneratorTarget(), source,
ppBuild.Variables);
this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
ppBuild, commandLineLengthLimit);
@@ -1821,13 +1822,13 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
this->ConvertToOutputFormatForShell(targetSupportDir);
vars["OBJECT_FILE_DIR"] = this->ConvertToOutputFormatForShell(objectFileDir);
this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
source, vars);
this->addPoolNinjaVariable("JOB_POOL_COMPILE", config,
this->GetGeneratorTarget(), source, vars);
if (!pchSources.empty() && !source->GetProperty("SKIP_PRECOMPILE_HEADERS")) {
auto pchIt = pchSources.find(source->GetFullPath());
if (pchIt != pchSources.end()) {
this->addPoolNinjaVariable("JOB_POOL_PRECOMPILE_HEADER",
this->addPoolNinjaVariable("JOB_POOL_PRECOMPILE_HEADER", config,
this->GetGeneratorTarget(), nullptr, vars);
}
}
@@ -2024,8 +2025,9 @@ void cmNinjaTargetGenerator::WriteCxxModuleBmiBuildStatement(
scanningFiles.ScanningOutput = cmStrCat(bmiFileName, ".ddi");
}
this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
source, ppBuild.Variables);
this->addPoolNinjaVariable("JOB_POOL_COMPILE", config,
this->GetGeneratorTarget(), source,
ppBuild.Variables);
this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig),
ppBuild, commandLineLengthLimit);
@@ -2053,8 +2055,8 @@ void cmNinjaTargetGenerator::WriteCxxModuleBmiBuildStatement(
this->ConvertToOutputFormatForShell(targetSupportDir);
vars["OBJECT_FILE_DIR"] = this->ConvertToOutputFormatForShell(bmiFileDir);
this->addPoolNinjaVariable("JOB_POOL_COMPILE", this->GetGeneratorTarget(),
source, vars);
this->addPoolNinjaVariable("JOB_POOL_COMPILE", config,
this->GetGeneratorTarget(), source, vars);
bmiBuild.RspFile = cmStrCat(bmiFileName, ".rsp");
@@ -2775,15 +2777,22 @@ void cmNinjaTargetGenerator::RemoveDepfileBinding(cmNinjaVars& vars) const
}
void cmNinjaTargetGenerator::addPoolNinjaVariable(
std::string const& pool_property, cmGeneratorTarget* target,
cmSourceFile const* source, cmNinjaVars& vars)
std::string const& pool_property, std::string const& config,
cmGeneratorTarget* target, cmSourceFile const* source, cmNinjaVars& vars)
{
// First check the current source properties, then if not found, its target
// ones. Allows to override a target-wide compile pool with a source-specific
// one.
// First check file set properties, then if not found the current source
// properties, then if not found, its target ones. Allows to override a
// target-wide compile pool with file set-specific or source-specific one.
cmValue pool = {};
if (source) {
pool = source->GetProperty(pool_property);
cmGeneratorFileSet const* fileSet =
target->GetFileSetForSource(config, source);
if (fileSet) {
pool = fileSet->GetProperty(pool_property);
}
if (!pool) {
pool = source->GetProperty(pool_property);
}
}
if (!pool) {
pool = target->GetProperty(pool_property);

View File

@@ -247,6 +247,7 @@ protected:
/// @param source may be nullptr.
void addPoolNinjaVariable(std::string const& pool_property,
std::string const& config,
cmGeneratorTarget* target,
cmSourceFile const* source, cmNinjaVars& vars);

View File

@@ -0,0 +1,17 @@
set(log "${RunCMake_BINARY_DIR}/FileSetJobPool-build/build.ninja")
file(READ "${log}" build_file)
if(NOT "${build_file}" MATCHES "pool = file_set_compile_pool")
string(CONCAT RunCMake_TEST_FAILED "Log file:\n ${log}\n" "does not have expected line: pool = file_set_compile_pool")
endif()
if(NOT "${build_file}" MATCHES "pool = target_link_pool")
string(CONCAT RunCMake_TEST_FAILED "Log file:\n ${log}\n" "does not have expected line: pool = target_link_pool")
endif()
# Even though `source_file_compile_pool` and `target_compile_pool` were defined as the target's compile jobs pool,
# since the file set property overrides it with `file_set_compile_pool` pool, the source file compile job
# and the target compile job pool should not exist in the generated Ninja file.
if("${build_file}" MATCHES "pool = source_file_compile_pool")
string(CONCAT RunCMake_TEST_FAILED "Log file:\n ${log}\n" "have unexpected line: pool = source_file_compile_pool")
endif()
if("${build_file}" MATCHES "pool = target_compile_pool")
string(CONCAT RunCMake_TEST_FAILED "Log file:\n ${log}\n" "have unexpected line: pool = target_compile_pool")
endif()

View File

@@ -0,0 +1,16 @@
set_property(GLOBAL PROPERTY JOB_POOLS source_file_compile_tool=2 file_set_compile_pool=2
target_compile_pool=4 target_link_pool=1)
enable_language(C)
set_property(SOURCE hello.c PROPERTY JOB_POOL_COMPILE "source_file_compile_pool")
add_executable(hello)
target_sources(hello PRIVATE FILE_SET SOURCES FILES hello.c)
set_property(FILE_SET SOURCES TARGET hello PROPERTY JOB_POOL_COMPILE "file_set_compile_pool")
set_property(TARGET hello PROPERTY JOB_POOL_COMPILE "target_compile_pool")
set_property(TARGET hello PROPERTY JOB_POOL_LINK "target_link_pool")
include(CheckNoPrefixSubDir.cmake)

View File

@@ -121,6 +121,7 @@ run_cmake_with_options(CustomCommandDepfileAsOutput -DCMAKE_BUILD_TYPE=Debug)
run_cmake_with_options(CustomCommandDepfileAsByproduct -DCMAKE_BUILD_TYPE=Debug)
run_cmake(CustomCommandJobPool)
run_cmake(SourceFileJobPool)
run_cmake(FileSetJobPool)
run_cmake(JobPoolUsesTerminal)
run_cmake(RspFileC)