diff --git a/Source/cmGlobalBorlandMakefileGenerator.cxx b/Source/cmGlobalBorlandMakefileGenerator.cxx index 950d44009..6c209522d 100644 --- a/Source/cmGlobalBorlandMakefileGenerator.cxx +++ b/Source/cmGlobalBorlandMakefileGenerator.cxx @@ -49,7 +49,6 @@ cmLocalGenerator *cmGlobalBorlandMakefileGenerator::CreateLocalGenerator() lg->SetUnixCD(false); lg->SetMakeCommandEscapeTargetTwice(true); lg->SetBorlandMakeCurlyHack(true); - lg->SetNoMultiOutputMultiDepRules(true); return lg; } diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index dfa6cc9d1..9213ad669 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -92,7 +92,6 @@ cmLocalUnixMakefileGenerator3::cmLocalUnixMakefileGenerator3() this->SkipAssemblySourceRules = false; this->MakeCommandEscapeTargetTwice = false; this->BorlandMakeCurlyHack = false; - this->NoMultiOutputMultiDepRules = false; } //---------------------------------------------------------------------------- @@ -600,7 +599,6 @@ const std::string &cmLocalUnixMakefileGenerator3::GetHomeRelativeOutputPath() return this->HomeRelativeOutputPath; } - //---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator3 @@ -619,30 +617,6 @@ cmLocalUnixMakefileGenerator3 comment); return; } - std::vector outputs(1, target); - this->WriteMakeRule(os, comment, - outputs, depends, commands, - symbolic, in_help); -} - -//---------------------------------------------------------------------------- -void -cmLocalUnixMakefileGenerator3 -::WriteMakeRule(std::ostream& os, - const char* comment, - const std::vector& outputs, - const std::vector& depends, - const std::vector& commands, - bool symbolic, - bool in_help) -{ - // Make sure there is an output. - if(outputs.empty()) - { - cmSystemTools::Error("No outputs for WriteMakeRule! called with comment: ", - comment); - return; - } std::string replace; @@ -661,17 +635,7 @@ cmLocalUnixMakefileGenerator3 } // Construct the left hand side of the rule. - std::string tgt; - { - const char* sep = ""; - for (std::vector::const_iterator i = outputs.begin(); - i != outputs.end(); ++i) - { - tgt += sep; - tgt += this->Convert(*i,HOME_OUTPUT,MAKERULE); - sep = " "; - } - } + std::string tgt = this->Convert(target, HOME_OUTPUT, MAKERULE); const char* space = ""; if(tgt.size() == 1) @@ -697,19 +661,6 @@ cmLocalUnixMakefileGenerator3 // No dependencies. The commands will always run. os << cmMakeSafe(tgt) << space << ":\n"; } - else if(this->NoMultiOutputMultiDepRules && outputs.size() >= 2) - { - // Borland make does not understand multiple dependency rules when - // there are multiple outputs, so write them all on one line. - os << cmMakeSafe(tgt) << space << ":"; - for(std::vector::const_iterator dep = depends.begin(); - dep != depends.end(); ++dep) - { - replace = this->Convert(*dep, HOME_OUTPUT, MAKERULE); - os << " " << cmMakeSafe(replace); - } - os << "\n"; - } else { // Split dependencies into multiple rule lines. This allows for @@ -738,8 +689,7 @@ cmLocalUnixMakefileGenerator3 // Add the output to the local help if requested. if(in_help) { - this->LocalHelp.insert(this->LocalHelp.end(), - outputs.begin(), outputs.end()); + this->LocalHelp.push_back(target); } } @@ -1758,8 +1708,6 @@ cmLocalUnixMakefileGenerator3 //---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator3::CheckMultipleOutputs(bool verbose) { - // Nothing populates multiple output pairs anymore, but we need to - // honor it when working in a build tree generated by an older CMake. cmMakefile* mf = this->Makefile; // Get the string listing the multiple output pairs. diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 7c8e27f49..4f2e4a035 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -61,13 +61,6 @@ public: const std::vector& commands, bool symbolic, bool in_help = false); - void WriteMakeRule(std::ostream& os, - const char* comment, - const std::vector& outputs, - const std::vector& depends, - const std::vector& commands, - bool symbolic, - bool in_help = false); // write the main variables used by the makefiles void WriteMakeVariables(std::ostream& makefileStream); @@ -161,9 +154,6 @@ public: void SetBorlandMakeCurlyHack(bool b) { this->BorlandMakeCurlyHack = b; } - void SetNoMultiOutputMultiDepRules(bool b) - { this->NoMultiOutputMultiDepRules = b; } - // used in writing out Cmake files such as WriteDirectoryInformation static void WriteCMakeArgument(std::ostream& os, const char* s); @@ -348,7 +338,6 @@ private: bool PassMakeflags; bool MakeCommandEscapeTargetTwice; bool BorlandMakeCurlyHack; - bool NoMultiOutputMultiDepRules; //========================================================================== std::string HomeRelativeOutputPath; diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index cdda36c52..e55f6512e 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -765,9 +765,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules } // Write the build rule. - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, - outputs, depends, commands, false); - + this->WriteMakeRule(*this->BuildFileStream, 0, outputs, + depends, commands, false); // Write the main driver rule to build everything in this target. this->WriteTargetDriverRule(targetFullPath, relink); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 7ed0c106a..4ece016bf 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -766,8 +766,8 @@ cmMakefileTargetGenerator } // Write the rule. - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, - outputs, depends, commands, false); + this->WriteMakeRule(*this->BuildFileStream, 0, outputs, + depends, commands, false); bool do_preprocess_rules = lang_has_preprocessor && this->LocalGenerator->GetCreatePreprocessedSourceRules(); @@ -988,6 +988,57 @@ void cmMakefileTargetGenerator::WriteTargetCleanRules() depends, commands, true); } +//---------------------------------------------------------------------------- +void cmMakefileTargetGenerator::WriteMakeRule( + std::ostream& os, + const char* comment, + const std::vector& outputs, + const std::vector& depends, + const std::vector& commands, + bool symbolic, + bool in_help) +{ + if (outputs.size() == 0) + { + return; + } + + // We always attach the actual commands to the first output. + this->LocalGenerator->WriteMakeRule(os, comment, outputs[0], depends, + commands, symbolic, in_help); + + // For single outputs, we are done. + if (outputs.size() == 1) + { + return; + } + + // For multiple outputs, make the extra ones depend on the first one. + std::vector const output_depends(1, outputs[0]); + for (std::vector::const_iterator o = outputs.begin()+1; + o != outputs.end(); ++o) + { + // Touch the extra output so "make" knows that it was updated, + // but only if the output was acually created. + std::string const out = this->Convert(*o, cmLocalGenerator::HOME_OUTPUT, + cmLocalGenerator::SHELL); + std::vector output_commands; + if (!symbolic) + { + output_commands.push_back("@$(CMAKE_COMMAND) -E touch_nocreate " + out); + } + this->LocalGenerator->WriteMakeRule(os, 0, *o, output_depends, + output_commands, symbolic, in_help); + + if (!symbolic) + { + // At build time, remove the first output if this one does not exist + // so that "make" will rerun the real commands that create this one. + MultipleOutputPairsType::value_type p(*o, outputs[0]); + this->MultipleOutputPairs.insert(p); + } + } +} //---------------------------------------------------------------------------- void cmMakefileTargetGenerator::WriteTargetDependRules() @@ -1008,6 +1059,25 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() this->LocalGenerator-> WriteDependLanguageInfo(*this->InfoFileStream,*this->Target); + // Store multiple output pairs in the depend info file. + if(!this->MultipleOutputPairs.empty()) + { + *this->InfoFileStream + << "\n" + << "# Pairs of files generated by the same build rule.\n" + << "set(CMAKE_MULTIPLE_OUTPUT_PAIRS\n"; + for(MultipleOutputPairsType::const_iterator pi = + this->MultipleOutputPairs.begin(); + pi != this->MultipleOutputPairs.end(); ++pi) + { + *this->InfoFileStream + << " " << this->LocalGenerator->EscapeForCMake(pi->first) + << " " << this->LocalGenerator->EscapeForCMake(pi->second) + << "\n"; + } + *this->InfoFileStream << " )\n\n"; + } + // Store list of targets linked directly or transitively. { *this->InfoFileStream @@ -1234,9 +1304,8 @@ void cmMakefileTargetGenerator symbolic = sf->GetPropertyAsBool("SYMBOLIC"); } } - this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, - outputs, depends, commands, - symbolic); + this->WriteMakeRule(*this->BuildFileStream, 0, outputs, + depends, commands, symbolic); // If the rule has changed make sure the output is rebuilt. if(!symbolic) diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index e31e0863a..f62c51ddf 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -222,6 +222,16 @@ protected: // Set of extra output files to be driven by the build. std::set ExtraFiles; + typedef std::map MultipleOutputPairsType; + MultipleOutputPairsType MultipleOutputPairs; + void WriteMakeRule(std::ostream& os, + const char* comment, + const std::vector& outputs, + const std::vector& depends, + const std::vector& commands, + bool symbolic, + bool in_help = false); + // Target name info. std::string TargetNameOut; std::string TargetNameSO;