diff options
author | Brad King <brad.king@kitware.com> | 2006-04-11 15:06:19 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2006-04-11 15:06:19 (GMT) |
commit | d5719f22c1dca3e100f1e3b5dfaa4fe7d26796a0 (patch) | |
tree | 714a99bed97290f96ff8f846fa6864cebbdc0a28 /Source/cmMakefileTargetGenerator.cxx | |
parent | b613cf0be806cc1d37d2b590f1a5ba7898236ae8 (diff) | |
download | CMake-d5719f22c1dca3e100f1e3b5dfaa4fe7d26796a0.zip CMake-d5719f22c1dca3e100f1e3b5dfaa4fe7d26796a0.tar.gz CMake-d5719f22c1dca3e100f1e3b5dfaa4fe7d26796a0.tar.bz2 |
ENH: Added support for multiple outputs generated by a single custom command. For Visual Studio generators the native tool provides support. For Xcode and Makefile generators a simple trick is used. The first output is considered primary and has the build rule attached. Other outputs simply depend on the first output with no build rule. During cmake_check_build_system CMake detects when a secondary output is missing and removes the primary output to make sure all outputs are regenerated. This approach always builds the custom command at the right time and only once even during parallel builds.
Diffstat (limited to 'Source/cmMakefileTargetGenerator.cxx')
-rw-r--r-- | Source/cmMakefileTargetGenerator.cxx | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 1f7c17f..f2d3dc0 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -18,6 +18,7 @@ #include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" +#include "cmGlobalUnixMakefileGenerator3.h" #include "cmLocalUnixMakefileGenerator3.h" #include "cmMakefile.h" #include "cmSourceFile.h" @@ -608,10 +609,15 @@ void cmMakefileTargetGenerator::WriteCustomCommands() this->GenerateCustomRuleFile(*cc); if (clean) { - this->CleanFiles.push_back - (this->Convert(cc->GetOutput(), - cmLocalGenerator::START_OUTPUT, - cmLocalGenerator::UNCHANGED)); + const std::vector<std::string>& outputs = cc->GetOutputs(); + for(std::vector<std::string>::const_iterator o = outputs.begin(); + o != outputs.end(); ++o) + { + this->CleanFiles.push_back + (this->Convert(o->c_str(), + cmLocalGenerator::START_OUTPUT, + cmLocalGenerator::UNCHANGED)); + } } } } @@ -621,17 +627,15 @@ void cmMakefileTargetGenerator::WriteCustomCommands() void cmMakefileTargetGenerator ::GenerateCustomRuleFile(const cmCustomCommand& cc) { - // Convert the output name to a relative path if possible. - std::string output = this->Convert(cc.GetOutput(), - cmLocalGenerator::START_OUTPUT); - // Collect the commands. std::vector<std::string> commands; - std::string preEcho = "Generating "; - preEcho += output; - this->LocalGenerator - ->AppendEcho(commands, preEcho.c_str(), - cmLocalUnixMakefileGenerator3::EchoGenerate); + std::string comment = this->LocalGenerator->ConstructComment(cc); + if(!comment.empty()) + { + this->LocalGenerator + ->AppendEcho(commands, comment.c_str(), + cmLocalUnixMakefileGenerator3::EchoGenerate); + } this->LocalGenerator->AppendCustomCommand(commands, cc); // Collect the dependencies. @@ -639,14 +643,30 @@ void cmMakefileTargetGenerator this->LocalGenerator->AppendCustomDepend(depends, cc); // Write the rule. - const char* comment = 0; - if(cc.GetComment() && *cc.GetComment()) + const std::vector<std::string>& outputs = cc.GetOutputs(); + std::vector<std::string>::const_iterator o = outputs.begin(); + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, + o->c_str(), depends, commands, + false); + + // If the rule has multiple outputs, add a rule for the extra + // outputs to just depend on the first output with no command. Also + // 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(); + cmGlobalUnixMakefileGenerator3* gg = + static_cast<cmGlobalUnixMakefileGenerator3*>(this->GlobalGenerator); + for(++o; o != outputs.end(); ++o) { - comment = cc.GetComment(); + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, + o->c_str(), depends, commands, + false); + gg->AddMultipleOutputPair(o->c_str(), depends[0].c_str()); } - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, comment, - cc.GetOutput(), depends, commands, - false); } //---------------------------------------------------------------------------- |