Ninja: Ability to set description property of a build rule
This can be generalized to other generators of course, but personally I'm most interested in the Ninja generator.
I see in the CMake source code the following
void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
const std::string& config)
{
...
auto scanRule =
GetScanRule(scanRuleName, ppFileName, vars, responseFlag, flags,
rulePlaceholderExpander.get(), this->GetLocalGenerator(),
std::move(scanCommands), config);
scanRule.Comment =
cmStrCat("Rule for generating ", lang, " dependencies.");
if (compilationPreprocesses) {
scanRule.Description =
cmStrCat("Scanning $in for ", lang, " dependencies");
} else {
scanRule.Description =
cmStrCat("Building ", lang, " preprocessed $out");
}
and
void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile,
const std::string& config)
{
...
linkCmds.insert(linkCmds.begin(), "$PRE_LINK");
linkCmds.emplace_back("$POST_BUILD");
rule.Command =
this->GetLocalGenerator()->BuildCommandLine(linkCmds, config, config);
// Write the linker rule with response file if needed.
rule.Comment =
cmStrCat("Rule for linking ", this->TargetLinkLanguage(config), ' ',
this->GetVisibleTypeName(), '.');
rule.Description =
cmStrCat("Linking ", this->TargetLinkLanguage(config), ' ',
this->GetVisibleTypeName(), " $TARGET_FILE");
rule.Restat = "$RESTAT";
this->GetGlobalGenerator()->AddRule(rule);
}
What I want to do is customize these rules so that I can include information like $<CONFIG>
(if IS_MULTI_CONFIG is true) or ${CMAKE_BUILD_TYPE}
(if not) so that developers can more easily see which config in a multi-config build is building, ${CMAKE_SYSTEM_NAME}, to see which operating system target is being built, and ${CMAKE_SYSTEM_PROCESSOR} to see which target ISA is being built for.
A variable substitution strategy, like <OUTFILE>
to be substituted for the ninja $out
would be nice as well.
You might wonder why I would care about seeing which ${CMAKE_SYSTEM_NAME} or ${CMAKE_SYSTEM_PROCESSOR} my build is executing for, and the answer is straight forward in that my product builds with multiple different configurations, in serial. Such as Windows/x86_64, Linux/x86_64, Linux/AARCH64, in addition to using a combination of multi-config and single-config generators involved for each target platform/arch.
As such, having the target information in the actual build output goes a long way toward helping a developer quickly locate what's causing them problems.
Whether this is provided on a per object basis, or a per target basis, i guess isn't as important to me as it might be to someone else.