diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index a3dcd6268..b55164f73 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -869,7 +869,8 @@ cmGlobalUnixMakefileGenerator3 if(emitted.insert(lib->first).second) { // Add this dependency. - this->AppendAnyGlobalDepend(depends, lib->first.c_str(), emitted); + this->AppendAnyGlobalDepend(depends, lib->first.c_str(), + emitted, target); } } } @@ -883,7 +884,7 @@ cmGlobalUnixMakefileGenerator3 if(emitted.insert(*util).second) { // Add this dependency. - this->AppendAnyGlobalDepend(depends, util->c_str(), emitted); + this->AppendAnyGlobalDepend(depends, util->c_str(), emitted, target); } } } @@ -893,41 +894,55 @@ cmGlobalUnixMakefileGenerator3 void cmGlobalUnixMakefileGenerator3 ::AppendAnyGlobalDepend(std::vector& depends, const char* name, - std::set& emitted) + std::set& emitted, cmTarget &target) { cmTarget *result; + cmLocalUnixMakefileGenerator3 *lg3; + + // first check the same dir as the current target + lg3 = static_cast + (target.GetMakefile()->GetLocalGenerator()); + result = target.GetMakefile()->FindTarget(name); // search each local generator until a match is found - unsigned int i; - for (i = 0; i < m_LocalGenerators.size(); ++i) + if (!result) { - // search all targets - result = m_LocalGenerators[i]->GetMakefile()->FindTarget(name); - // if a match was found then ... - if (result) + unsigned int i; + for (i = 0; i < m_LocalGenerators.size(); ++i) { - cmLocalUnixMakefileGenerator3 *lg3 = - static_cast(m_LocalGenerators[i]); - std::string tgtName = lg3->GetRelativeTargetDirectory(*result); - tgtName += "/all"; - depends.push_back(tgtName); - if(result->GetType() == cmTarget::STATIC_LIBRARY) + // search all targets + result = m_LocalGenerators[i]->GetMakefile()->FindTarget(name); + if (result) { - const cmTarget::LinkLibraries& tlibs = result->GetLinkLibraries(); - for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin(); - lib != tlibs.end(); ++lib) + lg3 = static_cast + (m_LocalGenerators[i]); + break; + } + } + } + + // if a match was found then ... + if (result) + { + std::string tgtName = lg3->GetRelativeTargetDirectory(*result); + tgtName += "/all"; + depends.push_back(tgtName); + if(result->GetType() == cmTarget::STATIC_LIBRARY) + { + const cmTarget::LinkLibraries& tlibs = result->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) { - // 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(), - emitted); - } + // Add this dependency. + this->AppendAnyGlobalDepend(depends, lib->first.c_str(), + emitted, *result); } } - return; } + return; } } diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index aebc086c4..f82f9dfa4 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -111,7 +111,9 @@ protected: void AppendGlobalTargetDepends(std::vector& depends, cmTarget& target); void AppendAnyGlobalDepend(std::vector& depends, - const char* name, std::set& emitted); + const char* name, + std::set& emitted, + cmTarget &target); // does this generator need a requires step for any of its targets bool NeedRequiresStep(cmLocalUnixMakefileGenerator3 *lg, const char *); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index beb1ef170..dcab4cbe9 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -701,7 +701,8 @@ void cmMakefile::AddUtilityCommand(const char* utilityName, bool all, cmTarget target; target.SetType(cmTarget::UTILITY, utilityName); target.SetInAll(all); - + target.SetMakefile(this); + // Store the custom command in the target. cmCustomCommand cc(output, depends, commandLines, 0); target.GetPostBuildCommands().push_back(cc); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index c1c68e983..bae1eb926 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -63,7 +63,8 @@ public: ///! Set the cmMakefile that owns this target void SetMakefile(cmMakefile *mf) { m_Makefile = mf; }; - + cmMakefile *GetMakefile() { return m_Makefile;}; + /** * Get the list of the custom commands for this target */