ENH: Implemented subdirectory rules for all target.
This commit is contained in:
parent
1e1b22bdbc
commit
914f28b06a
|
@ -90,7 +90,7 @@ void cmLocalUnixMakefileGenerator2::GenerateMakefile()
|
||||||
this->WriteAllRule(makefileStream);
|
this->WriteAllRule(makefileStream);
|
||||||
|
|
||||||
// Write the subdirectory driver rules.
|
// Write the subdirectory driver rules.
|
||||||
this->WriteSubdirRules(makefileStream);
|
this->WriteSubdirRules(makefileStream, "all");
|
||||||
|
|
||||||
// Write include statements to get rules for each target.
|
// Write include statements to get rules for each target.
|
||||||
this->WriteTargetIncludes(makefileStream);
|
this->WriteTargetIncludes(makefileStream);
|
||||||
|
@ -525,7 +525,7 @@ cmLocalUnixMakefileGenerator2
|
||||||
std::string::size_type rpos;
|
std::string::size_type rpos;
|
||||||
while((rpos = replace.find('\n', lpos)) != std::string::npos)
|
while((rpos = replace.find('\n', lpos)) != std::string::npos)
|
||||||
{
|
{
|
||||||
os << "# " << replace.substr(lpos, rpos-lpos);
|
os << "# " << replace.substr(lpos, rpos-lpos) << "\n";
|
||||||
lpos = rpos+1;
|
lpos = rpos+1;
|
||||||
}
|
}
|
||||||
os << "# " << replace.substr(lpos) << "\n";
|
os << "# " << replace.substr(lpos) << "\n";
|
||||||
|
@ -742,10 +742,16 @@ cmLocalUnixMakefileGenerator2
|
||||||
std::vector<std::string> no_depends;
|
std::vector<std::string> no_depends;
|
||||||
std::vector<std::string> commands;
|
std::vector<std::string> commands;
|
||||||
commands.push_back(runRule);
|
commands.push_back(runRule);
|
||||||
|
std::string preEcho = "Checking build system in ";
|
||||||
|
preEcho += m_Makefile->GetStartOutputDirectory();
|
||||||
|
preEcho += "...";
|
||||||
this->WriteMakeRule(makefileStream,
|
this->WriteMakeRule(makefileStream,
|
||||||
"Special rule to run CMake to check the build system "
|
"Special rule to run CMake to check the build system "
|
||||||
"integrity.",
|
"integrity.\n"
|
||||||
"Checking build system integrity...",
|
"No rule that depends on this can have "
|
||||||
|
"commands that come from listfiles\n"
|
||||||
|
"because they might be regenerated.",
|
||||||
|
preEcho.c_str(),
|
||||||
"cmake_check_build_system",
|
"cmake_check_build_system",
|
||||||
no_depends,
|
no_depends,
|
||||||
commands);
|
commands);
|
||||||
|
@ -904,12 +910,12 @@ cmLocalUnixMakefileGenerator2
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
cmLocalUnixMakefileGenerator2
|
cmLocalUnixMakefileGenerator2
|
||||||
::WriteSubdirRules(std::ostream& makefileStream)
|
::WriteSubdirRules(std::ostream& makefileStream, const char* pass)
|
||||||
{
|
{
|
||||||
// Write the section header.
|
// Write the section header.
|
||||||
this->WriteDivider(makefileStream);
|
this->WriteDivider(makefileStream);
|
||||||
makefileStream
|
makefileStream
|
||||||
<< "# Subdirectory driver targets.\n"
|
<< "# Subdirectory driver targets for " << pass << "\n"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
// Iterate through subdirectories. Only entries in which the
|
// Iterate through subdirectories. Only entries in which the
|
||||||
|
@ -925,19 +931,14 @@ cmLocalUnixMakefileGenerator2
|
||||||
{
|
{
|
||||||
if(i->second)
|
if(i->second)
|
||||||
{
|
{
|
||||||
// Construct the name of the subdirectory rule.
|
|
||||||
std::string tgt = this->GetSubdirTargetName(i->first.c_str());
|
|
||||||
|
|
||||||
// Add the subdirectory rule either for pre-order or post-order.
|
// Add the subdirectory rule either for pre-order or post-order.
|
||||||
if(m_Makefile->IsDirectoryPreOrder(i->first.c_str()))
|
if(m_Makefile->IsDirectoryPreOrder(i->first.c_str()))
|
||||||
{
|
{
|
||||||
this->WriteSubdirRule(makefileStream, tgt.c_str(), lastPre.c_str());
|
this->WriteSubdirRule(makefileStream, pass, i->first.c_str(), lastPre);
|
||||||
lastPre = tgt;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->WriteSubdirRule(makefileStream, tgt.c_str(), lastPost.c_str());
|
this->WriteSubdirRule(makefileStream, pass, i->first.c_str(), lastPost);
|
||||||
lastPost = tgt;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -955,32 +956,82 @@ cmLocalUnixMakefileGenerator2
|
||||||
{
|
{
|
||||||
post_depends.push_back(lastPost);
|
post_depends.push_back(lastPost);
|
||||||
}
|
}
|
||||||
this->WriteMakeRule(makefileStream,
|
std::string preComment = "Pre-order subdirectory driver target for ";
|
||||||
"Pre-order subdirectory driver target.", 0,
|
preComment += pass;
|
||||||
"all.subdirs.pre", pre_depends, no_commands);
|
std::string postComment = "Post-order subdirectory driver target for ";
|
||||||
this->WriteMakeRule(makefileStream,
|
postComment += pass;
|
||||||
"Post-order subdirectory driver target.", 0,
|
std::string preTarget = pass;
|
||||||
"all.subdirs.post", post_depends, no_commands);
|
preTarget += ".subdirs.pre";
|
||||||
|
std::string postTarget = pass;
|
||||||
|
postTarget += ".subdirs.post";
|
||||||
|
this->WriteMakeRule(makefileStream, preComment.c_str(), 0,
|
||||||
|
preTarget.c_str(), pre_depends, no_commands);
|
||||||
|
this->WriteMakeRule(makefileStream, postComment.c_str(), 0,
|
||||||
|
postTarget.c_str(), post_depends, no_commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
cmLocalUnixMakefileGenerator2
|
cmLocalUnixMakefileGenerator2
|
||||||
::WriteSubdirRule(std::ostream& makefileStream, const char* tgt,
|
::WriteSubdirRule(std::ostream& makefileStream, const char* pass,
|
||||||
const char* last)
|
const char* subdir, std::string& last)
|
||||||
{
|
{
|
||||||
// TODO: Generate commands to cd into subdir (CONTINUE HERE).
|
|
||||||
std::vector<std::string> depends;
|
std::vector<std::string> depends;
|
||||||
std::vector<std::string> no_commands;
|
std::vector<std::string> commands;
|
||||||
|
|
||||||
|
// Construct the name of the subdirectory rule.
|
||||||
|
std::string tgt = this->GetSubdirTargetName(pass, subdir);
|
||||||
|
|
||||||
|
if(m_WindowsShell)
|
||||||
|
{
|
||||||
|
// On Windows we must perform each step separately and then change
|
||||||
|
// back because the shell keeps the working directory between
|
||||||
|
// commands.
|
||||||
|
std::string cmd = "@cd ";
|
||||||
|
cmd += this->ConvertToOutputForExisting(subdir);
|
||||||
|
commands.push_back(cmd);
|
||||||
|
|
||||||
|
// Build the target for this pass.
|
||||||
|
commands.push_back(this->GetRecursiveMakeCall(pass));
|
||||||
|
|
||||||
|
// Change back to the starting directory.
|
||||||
|
std::string destFull = m_Makefile->GetStartOutputDirectory();
|
||||||
|
destFull += "/";
|
||||||
|
destFull += subdir;
|
||||||
|
std::string back =
|
||||||
|
cmSystemTools::RelativePath(destFull.c_str(),
|
||||||
|
m_Makefile->GetStartOutputDirectory());
|
||||||
|
cmd = "@cd ";
|
||||||
|
cmd += this->ConvertToOutputForExisting(back.c_str());
|
||||||
|
commands.push_back(cmd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// On UNIX we must construct a single shell command to change
|
||||||
|
// directory and build because make resets the directory between
|
||||||
|
// each command.
|
||||||
|
std::string cmd = "@cd ";
|
||||||
|
cmd += this->ConvertToOutputForExisting(subdir);
|
||||||
|
|
||||||
|
// Build the target for this pass.
|
||||||
|
cmd += " && ";
|
||||||
|
cmd += this->GetRecursiveMakeCall(pass);
|
||||||
|
|
||||||
|
// Add the command as a single line.
|
||||||
|
commands.push_back(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
// Depend on the last directory written out to enforce ordering.
|
// Depend on the last directory written out to enforce ordering.
|
||||||
if(last && *last)
|
if(last.size() > 0)
|
||||||
{
|
{
|
||||||
depends.push_back(last);
|
depends.push_back(last);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the rule.
|
// Write the rule.
|
||||||
this->WriteMakeRule(makefileStream, 0, 0, tgt, depends, no_commands);
|
this->WriteMakeRule(makefileStream, 0, 0, tgt.c_str(), depends, commands);
|
||||||
|
|
||||||
|
// This rule is now the last one written.
|
||||||
|
last = tgt;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -1456,10 +1507,11 @@ cmLocalUnixMakefileGenerator2
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
std::string
|
std::string
|
||||||
cmLocalUnixMakefileGenerator2
|
cmLocalUnixMakefileGenerator2
|
||||||
::GetSubdirTargetName(const char* subdir)
|
::GetSubdirTargetName(const char* pass, const char* subdir)
|
||||||
{
|
{
|
||||||
// Convert the subdirectory name to a valid make target name.
|
// Convert the subdirectory name to a valid make target name.
|
||||||
std::string s = "subdir_";
|
std::string s = pass;
|
||||||
|
s += "_";
|
||||||
s += subdir;
|
s += subdir;
|
||||||
|
|
||||||
// Replace "../" with 3 underscores. This allows one .. at the beginning.
|
// Replace "../" with 3 underscores. This allows one .. at the beginning.
|
||||||
|
@ -1771,7 +1823,7 @@ cmLocalUnixMakefileGenerator2
|
||||||
// On Windows we must perform each step separately and then jump
|
// On Windows we must perform each step separately and then jump
|
||||||
// back because the shell keeps the working directory between
|
// back because the shell keeps the working directory between
|
||||||
// commands.
|
// commands.
|
||||||
std::string cmd = "cd ";
|
std::string cmd = "@cd ";
|
||||||
cmd += this->ConvertToOutputForExisting(destination);
|
cmd += this->ConvertToOutputForExisting(destination);
|
||||||
commands.push_back(cmd);
|
commands.push_back(cmd);
|
||||||
|
|
||||||
|
@ -1785,7 +1837,7 @@ cmLocalUnixMakefileGenerator2
|
||||||
commands.push_back(this->GetRecursiveMakeCall(tgt.c_str()));
|
commands.push_back(this->GetRecursiveMakeCall(tgt.c_str()));
|
||||||
|
|
||||||
// Jump back to the starting directory.
|
// Jump back to the starting directory.
|
||||||
cmd = "cd ";
|
cmd = "@cd ";
|
||||||
cmd += this->ConvertToOutputForExisting(m_Makefile->GetStartOutputDirectory());
|
cmd += this->ConvertToOutputForExisting(m_Makefile->GetStartOutputDirectory());
|
||||||
commands.push_back(cmd);
|
commands.push_back(cmd);
|
||||||
}
|
}
|
||||||
|
@ -1793,7 +1845,7 @@ cmLocalUnixMakefileGenerator2
|
||||||
{
|
{
|
||||||
// On UNIX we must construct a single shell command to jump and
|
// On UNIX we must construct a single shell command to jump and
|
||||||
// build because make resets the directory between each command.
|
// build because make resets the directory between each command.
|
||||||
std::string cmd = "cd ";
|
std::string cmd = "@cd ";
|
||||||
cmd += this->ConvertToOutputForExisting(destination);
|
cmd += this->ConvertToOutputForExisting(destination);
|
||||||
|
|
||||||
// Check the build system in destination directory.
|
// Check the build system in destination directory.
|
||||||
|
|
|
@ -75,9 +75,9 @@ protected:
|
||||||
void WriteSpecialTargetsBottom(std::ostream& makefileStream);
|
void WriteSpecialTargetsBottom(std::ostream& makefileStream);
|
||||||
void WriteTargetIncludes(std::ostream& makefileStream);
|
void WriteTargetIncludes(std::ostream& makefileStream);
|
||||||
void WriteAllRule(std::ostream& makefileStream);
|
void WriteAllRule(std::ostream& makefileStream);
|
||||||
void WriteSubdirRules(std::ostream& makefileStream);
|
void WriteSubdirRules(std::ostream& makefileStream, const char* pass);
|
||||||
void WriteSubdirRule(std::ostream& makefileStream, const char* tgt,
|
void WriteSubdirRule(std::ostream& makefileStream, const char* pass,
|
||||||
const char* last);
|
const char* subdir, std::string& last);
|
||||||
void WriteRequiresRule(std::ostream& ruleFileStream, const cmTarget& target,
|
void WriteRequiresRule(std::ostream& ruleFileStream, const cmTarget& target,
|
||||||
const char* targetFullPath);
|
const char* targetFullPath);
|
||||||
void WriteExecutableRule(std::ostream& ruleFileStream,
|
void WriteExecutableRule(std::ostream& ruleFileStream,
|
||||||
|
@ -104,7 +104,7 @@ protected:
|
||||||
const char* extraLinkFlags);
|
const char* extraLinkFlags);
|
||||||
|
|
||||||
std::string GetTargetDirectory(const cmTarget& target);
|
std::string GetTargetDirectory(const cmTarget& target);
|
||||||
std::string GetSubdirTargetName(const char* subdir);
|
std::string GetSubdirTargetName(const char* pass, const char* subdir);
|
||||||
std::string GetObjectFileName(const cmTarget& target,
|
std::string GetObjectFileName(const cmTarget& target,
|
||||||
const cmSourceFile& source);
|
const cmSourceFile& source);
|
||||||
const char* GetSourceFileLanguage(const cmSourceFile& source);
|
const char* GetSourceFileLanguage(const cmSourceFile& source);
|
||||||
|
|
Loading…
Reference in New Issue