ENH: Added cmMakefileTargetGenerator::GenerateExtraOutput to wrap up creation of rules to drive creation of extra outputs generated as side effects of another rule. Reimplemented generation of custom command multiple output rules to use it. Reimplemented soname symlink output dependencies to use it. Now if a symlink is deleted the library will be recreated with the symlink.

This commit is contained in:
Brad King 2007-03-09 11:29:15 -05:00
parent fb88335cdb
commit 31637efbfb
3 changed files with 44 additions and 36 deletions

View File

@ -653,26 +653,19 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
targetFullPathReal.c_str(), targetFullPathReal.c_str(),
depends, commands, false); depends, commands, false);
// The symlink names for the target should depend on the real target // Some targets have more than one output file. Create rules to
// so if the target version changes it rebuilds and recreates the // drive the build if any extra outputs are missing.
// symlinks. std::vector<std::string> extraOutputs;
if(targetFullPathSO != targetFullPathReal) if(targetNameSO != targetNameReal)
{ {
depends.clear(); this->GenerateExtraOutput(targetFullPathSO.c_str(),
commands.clear(); targetFullPathReal.c_str());
depends.push_back(targetFullPathReal.c_str());
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
targetFullPathSO.c_str(),
depends, commands, false);
} }
if(targetFullPath != targetFullPathSO) if(targetName != targetNameSO &&
targetName != targetNameReal)
{ {
depends.clear(); this->GenerateExtraOutput(targetFullPath.c_str(),
commands.clear(); targetFullPathReal.c_str());
depends.push_back(targetFullPathSO.c_str());
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
targetFullPath.c_str(),
depends, commands, false);
} }
// Write the main driver rule to build everything in this target. // Write the main driver rule to build everything in this target.

View File

@ -903,20 +903,8 @@ void cmMakefileTargetGenerator
symbolic); symbolic);
} }
// If the rule has multiple outputs, add a rule for the extra // Write rules to drive building any outputs beyond the first.
// outputs to just depend on the first output with no command. Also const char* in = o->c_str();
// register the extra outputs as paired with the first output so
// that the check-build-system step will remove the primary output
// if any extra outputs are missing, forcing the rule to regenerate
// all outputs.
depends.clear();
depends.push_back(*o);
commands.clear();
std::string emptyCommand = this->GlobalGenerator->GetEmptyCommandHack();
if(!emptyCommand.empty())
{
commands.push_back(emptyCommand);
}
for(++o; o != outputs.end(); ++o) for(++o; o != outputs.end(); ++o)
{ {
bool symbolic = false; bool symbolic = false;
@ -927,14 +915,36 @@ void cmMakefileTargetGenerator
symbolic = sf->GetPropertyAsBool("SYMBOLIC"); symbolic = sf->GetPropertyAsBool("SYMBOLIC");
} }
} }
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, this->GenerateExtraOutput(o->c_str(), in, symbolic);
o->c_str(), depends, commands,
symbolic);
this->GlobalGenerator->AddMultipleOutputPair(o->c_str(),
depends[0].c_str());
} }
} }
//----------------------------------------------------------------------------
void
cmMakefileTargetGenerator
::GenerateExtraOutput(const char* out, const char* in, bool symbolic)
{
// Add a rule to build the primary output if the extra output needs
// to be created.
std::vector<std::string> commands;
std::vector<std::string> depends;
std::string emptyCommand = this->GlobalGenerator->GetEmptyCommandHack();
if(!emptyCommand.empty())
{
commands.push_back(emptyCommand);
}
depends.push_back(in);
this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
out, depends, commands,
symbolic);
// Register the extra output as paired with the first output so that
// the check-build-system step will remove the primary output if any
// extra outputs are missing. This forces the rule to regenerate
// all outputs.
this->GlobalGenerator->AddMultipleOutputPair(out, in);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmMakefileTargetGenerator cmMakefileTargetGenerator

View File

@ -99,6 +99,11 @@ protected:
// write the build rule for a custom command // write the build rule for a custom command
void GenerateCustomRuleFile(const cmCustomCommand& cc); void GenerateCustomRuleFile(const cmCustomCommand& cc);
// write a rule to drive building of more than one output from
// another rule
void GenerateExtraOutput(const char* out, const char* in,
bool symbolic = false);
// write out the variable that lists the objects for this target // write out the variable that lists the objects for this target
void WriteObjectsVariable(std::string& variableName, void WriteObjectsVariable(std::string& variableName,
std::string& variableNameExternal); std::string& variableNameExternal);