From 78b5cca6e31c2eb3fc684652ecb03b0558a41c8e Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Wed, 18 May 2005 13:46:00 -0400 Subject: [PATCH] ENH: another step to the next generator still not optimized yet --- Source/cmGlobalUnixMakefileGenerator3.cxx | 153 ++++++++++++++++++---- Source/cmGlobalUnixMakefileGenerator3.h | 9 +- Source/cmLocalUnixMakefileGenerator3.cxx | 8 +- Source/cmLocalUnixMakefileGenerator3.h | 8 +- Source/cmTarget.cxx | 7 +- 5 files changed, 154 insertions(+), 31 deletions(-) diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index 985e09262..a4441b3e7 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -152,7 +152,19 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile() for (i = 0; i < m_LocalGenerators.size(); ++i) { lg = static_cast(m_LocalGenerators[i]); - this->WriteConvenienceRules(makefileStream,lg); + // are any parents excluded + bool exclude = false; + cmLocalGenerator *lg3 = lg; + while (lg3) + { + if (lg3->GetExcludeAll()) + { + exclude = true; + break; + } + lg3 = lg3->GetParent(); + } + this->WriteConvenienceRules(makefileStream,lg,exclude); } lg = static_cast(m_LocalGenerators[0]); @@ -427,15 +439,17 @@ void cmGlobalUnixMakefileGenerator3 // Check the build system in this directory. depends.push_back("cmake_check_build_system"); - commands.push_back(lg->GetRecursiveMakeCall("build.make","depend")); - commands.push_back(lg->GetRecursiveMakeCall("build.make","requires")); - commands.push_back(lg->GetRecursiveMakeCall("build.make",0)); + commands.push_back(lg->GetRecursiveMakeCall("Makefile","all/all")); // Write the rule. lg->WriteMakeRule(makefileStream, "The main all target", "all", depends, commands); - // write the clean + // Write and empty all/all: commands.clear(); + lg->WriteMakeRule(makefileStream, "The main recursive all target", "all/all", + commands, commands); + + // write the clean commands.push_back(lg->GetRecursiveMakeCall("clean.make",0)); lg->WriteMakeRule(makefileStream, "default clean target", "clean", depends, commands); } @@ -444,10 +458,11 @@ void cmGlobalUnixMakefileGenerator3 //---------------------------------------------------------------------------- void cmGlobalUnixMakefileGenerator3 -::WriteConvenienceRules(std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3 *lg) +::WriteConvenienceRules(std::ostream& ruleFileStream, + cmLocalUnixMakefileGenerator3 *lg, + bool exclude) { std::vector depends; - std::vector tgt_depends; std::vector commands; std::string localName; std::string makeTargetName; @@ -484,37 +499,129 @@ cmGlobalUnixMakefileGenerator3 if((t->second.GetType() == cmTarget::EXECUTABLE) || (t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) || - (t->second.GetType() == cmTarget::MODULE_LIBRARY)) + (t->second.GetType() == cmTarget::MODULE_LIBRARY) || + (t->second.GetType() == cmTarget::UTILITY)) { // Add a rule to build the target by name. localName = lg->GetRelativeTargetDirectory(t->second); - + commands.clear(); - makeTargetName = localName; - makeTargetName += "/depend"; - commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str())); - makeTargetName = localName; - makeTargetName += "/requires"; - commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str())); + if (t->second.GetType() != cmTarget::UTILITY) + { + makeTargetName = localName; + makeTargetName += "/depend"; + commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str())); + makeTargetName = localName; + makeTargetName += "/requires"; + commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str())); + } makeTargetName = localName; makeTargetName += "/build"; commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str())); // Write the rule. - lg->WriteMakeRule(ruleFileStream, "Convenience name for target.", + localName += "/all"; + depends.clear(); + this->AppendGlobalTargetDepends(depends,t->second); + lg->WriteMakeRule(ruleFileStream, "All Build rule for target.", localName.c_str(), depends, commands); - - // Add a target with the canonical name (no prefix, suffix or path). - if(localName != t->second.GetName()) + + // add the all/all dependency + if (!exclude && t->second.IsInAll()) { + depends.clear(); + depends.push_back(localName); commands.clear(); - tgt_depends.clear(); - tgt_depends.push_back(localName); - lg->WriteMakeRule(ruleFileStream, "Convenience name for target.", - t->second.GetName(), tgt_depends, commands); + lg->WriteMakeRule(ruleFileStream, "All Build rule for target.", + "all/all", depends, commands); } + + // Write the rule. + commands.clear(); + commands.push_back(lg->GetRecursiveMakeCall("Makefile",localName.c_str())); + depends.clear(); + depends.push_back("cmake_check_build_system"); + localName = lg->GetRelativeTargetDirectory(t->second); + lg->WriteMakeRule(ruleFileStream, "Build rule for subir invocation for target.", + localName.c_str(), depends, commands); + + // Add a target with the canonical name (no prefix, suffix or path). + commands.clear(); + depends.clear(); + depends.push_back(localName); + lg->WriteMakeRule(ruleFileStream, "Convenience name for target.", + t->second.GetName(), depends, commands); } } } + +//---------------------------------------------------------------------------- +void +cmGlobalUnixMakefileGenerator3 +::AppendGlobalTargetDepends(std::vector& depends, + const cmTarget& target) +{ + // Keep track of dependencies already listed. + std::set emitted; + + // A target should not depend on itself. + emitted.insert(target.GetName()); + + // Loop over all library dependencies but not for static libs + if (target.GetType() != cmTarget::STATIC_LIBRARY) + { + const cmTarget::LinkLibraries& tlibs = target.GetLinkLibraries(); + for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin(); + lib != tlibs.end(); ++lib) + { + // Don't emit the same library twice for this target. + if(emitted.insert(lib->first).second) + { + // Add this dependency. + this->AppendAnyGlobalDepend(depends, lib->first.c_str()); + } + } + } + + // Loop over all utility dependencies. + const std::set& tutils = target.GetUtilities(); + for(std::set::const_iterator util = tutils.begin(); + util != tutils.end(); ++util) + { + // Don't emit the same utility twice for this target. + if(emitted.insert(*util).second) + { + // Add this dependency. + this->AppendAnyGlobalDepend(depends, util->c_str()); + } + } +} + + +//---------------------------------------------------------------------------- +void +cmGlobalUnixMakefileGenerator3 +::AppendAnyGlobalDepend(std::vector& depends, const char* name) +{ + cmTarget *result = 0; + + // search each local generator until a match is found + unsigned int i; + for (i = 0; i < m_LocalGenerators.size(); ++i) + { + // search all targets + result = m_LocalGenerators[i]->GetMakefile()->FindTarget(name); + // if a match was found then ... + if (result) + { + cmLocalUnixMakefileGenerator3 *lg3 = + static_cast(m_LocalGenerators[i]); + std::string tgtName = lg3->GetRelativeTargetDirectory(*result); + tgtName += "/all"; + depends.push_back(tgtName); + return; + } + } +} diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index b63d007e7..4bf5b4c8b 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -66,7 +66,14 @@ protected: void WriteAllRules(cmLocalUnixMakefileGenerator3 *lg, std::ostream& makefileStream); - void WriteConvenienceRules(std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3 *); + void WriteConvenienceRules(std::ostream& ruleFileStream, + cmLocalUnixMakefileGenerator3 *, + bool exclude); + + void AppendGlobalTargetDepends(std::vector& depends, + const cmTarget& target); + void AppendAnyGlobalDepend(std::vector& depends, const char* name); + }; diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index d496528df..4944d9916 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -61,18 +61,21 @@ void cmLocalUnixMakefileGenerator3::Generate() this->ConfigureOutputPaths(); // Generate the rule files for each target. - const cmTargets& targets = m_Makefile->GetTargets(); - for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t) + cmTargets& targets = m_Makefile->GetTargets(); + std::string empty; + for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t) { if((t->second.GetType() == cmTarget::EXECUTABLE) || (t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::MODULE_LIBRARY)) { + t->second.TraceVSDependencies(empty, m_Makefile); this->WriteTargetRuleFiles(t->second); } else if(t->second.GetType() == cmTarget::UTILITY) { + t->second.TraceVSDependencies(empty, m_Makefile); this->WriteUtilityRuleFiles(t->second); } } @@ -2327,7 +2330,6 @@ cmLocalUnixMakefileGenerator3 if(dir && *dir) { // This is a CMake target somewhere in this project. - // Get the type of the library. If it does not have a type then // it is an executable. std::string typeVar = name; diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 6dbbea878..a6de93edb 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -144,6 +144,12 @@ public: std::map &GetIntegrityCheckSet() { return m_CheckDependFiles;} + void AppendTargetDepends(std::vector& depends, + const cmTarget& target); + + void AppendGlobalTargetDepends(std::vector& depends, + const cmTarget& target); + protected: // write the target rules for the local Makefile into the stream @@ -282,8 +288,6 @@ protected: const char* GetSourceFileLanguage(const cmSourceFile& source); std::string ConvertToQuotedOutputPath(const char* p); - void AppendTargetDepends(std::vector& depends, - const cmTarget& target); void AppendAnyDepend(std::vector& depends, const char* name, bool assume_unknown_is_file=false); void AppendRuleDepend(std::vector& depends, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index f186c9962..ffdb483bb 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -107,8 +107,11 @@ void cmTarget::TraceVSDependencies(std::string projFile, } // add in the project file itself - srcFilesToProcess.push(projFile); - srcFilesQueued.insert(projFile); + if (projFile.size()) + { + srcFilesToProcess.push(projFile); + srcFilesQueued.insert(projFile); + } // add in the library depends for custom targets if (this->GetType() == cmTarget::UTILITY) {