Overriding command "somename" silently overwrites command "_somename"
void cmState::AddScriptedCommand(std::string const& name, Command command)
{
std::string sName = cmSystemTools::LowerCase(name);
// if the command already exists, give a new name to the old command.
if (Command oldCmd = this->GetCommandByExactName(sName)) {
this->ScriptedCommands["_" + sName] = oldCmd;
}
this->ScriptedCommands[sName] = std::move(command);
}
This code silently overwrites this->ScriptedCommands["_" + sName]
with oldCmd
without warning or error. This may cause issues which are very hard to debug.
One straightforward workaround would be to add a warning or error for the case when this->ScriptedCommands["_" + sName]
already defines a command.
A better solution might be not to define rename the original commands at all, but make the them accessible inside the overriding functions or macros by other means, e.g. via cmake_command(INVOKE_OVERRIDDEN)
or similar.
PS: Please note that overriding commands is an undocumented feature.