ENH: another step to the next generator still not optimized yet

This commit is contained in:
Ken Martin 2005-05-18 13:46:00 -04:00
parent aa73e653aa
commit 78b5cca6e3
5 changed files with 154 additions and 31 deletions

View File

@ -152,7 +152,19 @@ void cmGlobalUnixMakefileGenerator3::WriteMainMakefile()
for (i = 0; i < m_LocalGenerators.size(); ++i) for (i = 0; i < m_LocalGenerators.size(); ++i)
{ {
lg = static_cast<cmLocalUnixMakefileGenerator3 *>(m_LocalGenerators[i]); lg = static_cast<cmLocalUnixMakefileGenerator3 *>(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<cmLocalUnixMakefileGenerator3 *>(m_LocalGenerators[0]); lg = static_cast<cmLocalUnixMakefileGenerator3 *>(m_LocalGenerators[0]);
@ -427,15 +439,17 @@ void cmGlobalUnixMakefileGenerator3
// Check the build system in this directory. // Check the build system in this directory.
depends.push_back("cmake_check_build_system"); depends.push_back("cmake_check_build_system");
commands.push_back(lg->GetRecursiveMakeCall("build.make","depend")); commands.push_back(lg->GetRecursiveMakeCall("Makefile","all/all"));
commands.push_back(lg->GetRecursiveMakeCall("build.make","requires"));
commands.push_back(lg->GetRecursiveMakeCall("build.make",0));
// Write the rule. // Write the rule.
lg->WriteMakeRule(makefileStream, "The main all target", "all", depends, commands); lg->WriteMakeRule(makefileStream, "The main all target", "all", depends, commands);
// write the clean // Write and empty all/all:
commands.clear(); 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)); commands.push_back(lg->GetRecursiveMakeCall("clean.make",0));
lg->WriteMakeRule(makefileStream, "default clean target", "clean", depends, commands); lg->WriteMakeRule(makefileStream, "default clean target", "clean", depends, commands);
} }
@ -444,10 +458,11 @@ void cmGlobalUnixMakefileGenerator3
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void void
cmGlobalUnixMakefileGenerator3 cmGlobalUnixMakefileGenerator3
::WriteConvenienceRules(std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3 *lg) ::WriteConvenienceRules(std::ostream& ruleFileStream,
cmLocalUnixMakefileGenerator3 *lg,
bool exclude)
{ {
std::vector<std::string> depends; std::vector<std::string> depends;
std::vector<std::string> tgt_depends;
std::vector<std::string> commands; std::vector<std::string> commands;
std::string localName; std::string localName;
std::string makeTargetName; std::string makeTargetName;
@ -484,37 +499,129 @@ cmGlobalUnixMakefileGenerator3
if((t->second.GetType() == cmTarget::EXECUTABLE) || if((t->second.GetType() == cmTarget::EXECUTABLE) ||
(t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(t->second.GetType() == cmTarget::SHARED_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. // Add a rule to build the target by name.
localName = lg->GetRelativeTargetDirectory(t->second); localName = lg->GetRelativeTargetDirectory(t->second);
commands.clear(); commands.clear();
if (t->second.GetType() != cmTarget::UTILITY)
{
makeTargetName = localName; makeTargetName = localName;
makeTargetName += "/depend"; makeTargetName += "/depend";
commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str())); commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str()));
makeTargetName = localName; makeTargetName = localName;
makeTargetName += "/requires"; makeTargetName += "/requires";
commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str())); commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str()));
}
makeTargetName = localName; makeTargetName = localName;
makeTargetName += "/build"; makeTargetName += "/build";
commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str())); commands.push_back(lg->GetRecursiveMakeCall("build.make",makeTargetName.c_str()));
// Write the rule. // 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 the all/all dependency
if (!exclude && t->second.IsInAll())
{
depends.clear();
depends.push_back(localName);
commands.clear();
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); localName.c_str(), depends, commands);
// Add a target with the canonical name (no prefix, suffix or path). // Add a target with the canonical name (no prefix, suffix or path).
if(localName != t->second.GetName())
{
commands.clear(); commands.clear();
tgt_depends.clear(); depends.clear();
tgt_depends.push_back(localName); depends.push_back(localName);
lg->WriteMakeRule(ruleFileStream, "Convenience name for target.", lg->WriteMakeRule(ruleFileStream, "Convenience name for target.",
t->second.GetName(), tgt_depends, commands); t->second.GetName(), depends, commands);
}
} }
} }
} }
//----------------------------------------------------------------------------
void
cmGlobalUnixMakefileGenerator3
::AppendGlobalTargetDepends(std::vector<std::string>& depends,
const cmTarget& target)
{
// Keep track of dependencies already listed.
std::set<cmStdString> 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<cmStdString>& tutils = target.GetUtilities();
for(std::set<cmStdString>::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<std::string>& 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<cmLocalUnixMakefileGenerator3 *>(m_LocalGenerators[i]);
std::string tgtName = lg3->GetRelativeTargetDirectory(*result);
tgtName += "/all";
depends.push_back(tgtName);
return;
}
}
}

View File

@ -66,7 +66,14 @@ protected:
void WriteAllRules(cmLocalUnixMakefileGenerator3 *lg, void WriteAllRules(cmLocalUnixMakefileGenerator3 *lg,
std::ostream& makefileStream); std::ostream& makefileStream);
void WriteConvenienceRules(std::ostream& ruleFileStream, cmLocalUnixMakefileGenerator3 *); void WriteConvenienceRules(std::ostream& ruleFileStream,
cmLocalUnixMakefileGenerator3 *,
bool exclude);
void AppendGlobalTargetDepends(std::vector<std::string>& depends,
const cmTarget& target);
void AppendAnyGlobalDepend(std::vector<std::string>& depends, const char* name);
}; };

View File

@ -61,18 +61,21 @@ void cmLocalUnixMakefileGenerator3::Generate()
this->ConfigureOutputPaths(); this->ConfigureOutputPaths();
// Generate the rule files for each target. // Generate the rule files for each target.
const cmTargets& targets = m_Makefile->GetTargets(); cmTargets& targets = m_Makefile->GetTargets();
for(cmTargets::const_iterator t = targets.begin(); t != targets.end(); ++t) std::string empty;
for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
{ {
if((t->second.GetType() == cmTarget::EXECUTABLE) || if((t->second.GetType() == cmTarget::EXECUTABLE) ||
(t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::STATIC_LIBRARY) ||
(t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) ||
(t->second.GetType() == cmTarget::MODULE_LIBRARY)) (t->second.GetType() == cmTarget::MODULE_LIBRARY))
{ {
t->second.TraceVSDependencies(empty, m_Makefile);
this->WriteTargetRuleFiles(t->second); this->WriteTargetRuleFiles(t->second);
} }
else if(t->second.GetType() == cmTarget::UTILITY) else if(t->second.GetType() == cmTarget::UTILITY)
{ {
t->second.TraceVSDependencies(empty, m_Makefile);
this->WriteUtilityRuleFiles(t->second); this->WriteUtilityRuleFiles(t->second);
} }
} }
@ -2327,7 +2330,6 @@ cmLocalUnixMakefileGenerator3
if(dir && *dir) if(dir && *dir)
{ {
// This is a CMake target somewhere in this project. // This is a CMake target somewhere in this project.
// Get the type of the library. If it does not have a type then // Get the type of the library. If it does not have a type then
// it is an executable. // it is an executable.
std::string typeVar = name; std::string typeVar = name;

View File

@ -144,6 +144,12 @@ public:
std::map<cmStdString, IntegrityCheckSet> &GetIntegrityCheckSet() std::map<cmStdString, IntegrityCheckSet> &GetIntegrityCheckSet()
{ return m_CheckDependFiles;} { return m_CheckDependFiles;}
void AppendTargetDepends(std::vector<std::string>& depends,
const cmTarget& target);
void AppendGlobalTargetDepends(std::vector<std::string>& depends,
const cmTarget& target);
protected: protected:
// write the target rules for the local Makefile into the stream // write the target rules for the local Makefile into the stream
@ -282,8 +288,6 @@ protected:
const char* GetSourceFileLanguage(const cmSourceFile& source); const char* GetSourceFileLanguage(const cmSourceFile& source);
std::string ConvertToQuotedOutputPath(const char* p); std::string ConvertToQuotedOutputPath(const char* p);
void AppendTargetDepends(std::vector<std::string>& depends,
const cmTarget& target);
void AppendAnyDepend(std::vector<std::string>& depends, const char* name, void AppendAnyDepend(std::vector<std::string>& depends, const char* name,
bool assume_unknown_is_file=false); bool assume_unknown_is_file=false);
void AppendRuleDepend(std::vector<std::string>& depends, void AppendRuleDepend(std::vector<std::string>& depends,

View File

@ -107,8 +107,11 @@ void cmTarget::TraceVSDependencies(std::string projFile,
} }
// add in the project file itself // add in the project file itself
if (projFile.size())
{
srcFilesToProcess.push(projFile); srcFilesToProcess.push(projFile);
srcFilesQueued.insert(projFile); srcFilesQueued.insert(projFile);
}
// add in the library depends for custom targets // add in the library depends for custom targets
if (this->GetType() == cmTarget::UTILITY) if (this->GetType() == cmTarget::UTILITY)
{ {