Merge topic 'optimize-custom-command-dependencies'
2268c41
Optimize custom command full-path dependency lookupeccb39d
VS 6,7: Refactor local generators to avoid GetSourceFileWithOutput
This commit is contained in:
commit
7c9f0c664f
|
@ -573,22 +573,20 @@ cmLocalVisualStudio6Generator
|
||||||
|
|
||||||
// Add the rule with the given dependencies and commands.
|
// Add the rule with the given dependencies and commands.
|
||||||
const char* no_main_dependency = 0;
|
const char* no_main_dependency = 0;
|
||||||
this->Makefile->AddCustomCommandToOutput(output,
|
if(cmSourceFile* outsf =
|
||||||
depends,
|
this->Makefile->AddCustomCommandToOutput(
|
||||||
no_main_dependency,
|
output, depends, no_main_dependency,
|
||||||
origCommand.GetCommandLines(),
|
origCommand.GetCommandLines(), comment.c_str(),
|
||||||
comment.c_str(),
|
origCommand.GetWorkingDirectory()))
|
||||||
origCommand.GetWorkingDirectory());
|
{
|
||||||
|
target.AddSourceFile(outsf);
|
||||||
|
}
|
||||||
|
|
||||||
// Replace the dependencies with the output of this rule so that the
|
// Replace the dependencies with the output of this rule so that the
|
||||||
// next rule added will run after this one.
|
// next rule added will run after this one.
|
||||||
depends.clear();
|
depends.clear();
|
||||||
depends.push_back(output);
|
depends.push_back(output);
|
||||||
|
|
||||||
// Add a source file representing this output to the project.
|
|
||||||
cmSourceFile* outsf = this->Makefile->GetSourceFileWithOutput(output);
|
|
||||||
target.AddSourceFile(outsf);
|
|
||||||
|
|
||||||
// Free the fake output name.
|
// Free the fake output name.
|
||||||
delete [] output;
|
delete [] output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,11 +146,10 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets()
|
||||||
force += "/";
|
force += "/";
|
||||||
force += tgt.GetName();
|
force += tgt.GetName();
|
||||||
force += "_force";
|
force += "_force";
|
||||||
this->Makefile->AddCustomCommandToOutput(force.c_str(), no_depends,
|
|
||||||
no_main_dependency,
|
|
||||||
force_commands, " ", 0, true);
|
|
||||||
if(cmSourceFile* file =
|
if(cmSourceFile* file =
|
||||||
this->Makefile->GetSourceFileWithOutput(force.c_str()))
|
this->Makefile->AddCustomCommandToOutput(
|
||||||
|
force.c_str(), no_depends, no_main_dependency,
|
||||||
|
force_commands, " ", 0, true))
|
||||||
{
|
{
|
||||||
tgt.AddSourceFile(file);
|
tgt.AddSourceFile(file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,6 +150,7 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals)
|
||||||
this->Initialize();
|
this->Initialize();
|
||||||
this->CheckSystemVars = mf.CheckSystemVars;
|
this->CheckSystemVars = mf.CheckSystemVars;
|
||||||
this->ListFileStack = mf.ListFileStack;
|
this->ListFileStack = mf.ListFileStack;
|
||||||
|
this->OutputToSource = mf.OutputToSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
@ -1010,10 +1011,31 @@ cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs,
|
||||||
cc->SetEscapeOldStyle(escapeOldStyle);
|
cc->SetEscapeOldStyle(escapeOldStyle);
|
||||||
cc->SetEscapeAllowMakeVars(true);
|
cc->SetEscapeAllowMakeVars(true);
|
||||||
file->SetCustomCommand(cc);
|
file->SetCustomCommand(cc);
|
||||||
|
this->UpdateOutputToSourceMap(outputs, file);
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
cmMakefile::UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
|
||||||
|
cmSourceFile* source)
|
||||||
|
{
|
||||||
|
for(std::vector<std::string>::const_iterator o = outputs.begin();
|
||||||
|
o != outputs.end(); ++o)
|
||||||
|
{
|
||||||
|
this->UpdateOutputToSourceMap(*o, source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void
|
||||||
|
cmMakefile::UpdateOutputToSourceMap(std::string const& output,
|
||||||
|
cmSourceFile* source)
|
||||||
|
{
|
||||||
|
this->OutputToSource[output] = source;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmSourceFile*
|
cmSourceFile*
|
||||||
cmMakefile::AddCustomCommandToOutput(const char* output,
|
cmMakefile::AddCustomCommandToOutput(const char* output,
|
||||||
|
@ -1994,7 +2016,7 @@ cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name)
|
||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
|
cmSourceFile *cmMakefile::LinearGetSourceFileWithOutput(const char *cname)
|
||||||
{
|
{
|
||||||
std::string name = cname;
|
std::string name = cname;
|
||||||
std::string out;
|
std::string out;
|
||||||
|
@ -2030,6 +2052,25 @@ cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname)
|
||||||
|
{
|
||||||
|
std::string name = cname;
|
||||||
|
|
||||||
|
// If the queried path is not absolute we use the backward compatible
|
||||||
|
// linear-time search for an output with a matching suffix.
|
||||||
|
if(!cmSystemTools::FileIsFullPath(cname))
|
||||||
|
{
|
||||||
|
return LinearGetSourceFileWithOutput(cname);
|
||||||
|
}
|
||||||
|
// Otherwise we use an efficient lookup map.
|
||||||
|
OutputToSourceMap::iterator o = this->OutputToSource.find(name);
|
||||||
|
if (o != this->OutputToSource.end())
|
||||||
|
{
|
||||||
|
return (*o).second;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
cmSourceGroup* cmMakefile::GetSourceGroup(const std::vector<std::string>&name)
|
cmSourceGroup* cmMakefile::GetSourceGroup(const std::vector<std::string>&name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
|
|
||||||
#include <cmsys/auto_ptr.hxx>
|
#include <cmsys/auto_ptr.hxx>
|
||||||
#include <cmsys/RegularExpression.hxx>
|
#include <cmsys/RegularExpression.hxx>
|
||||||
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
|
# include <cmsys/hash_map.hxx>
|
||||||
|
#endif
|
||||||
|
|
||||||
class cmFunctionBlocker;
|
class cmFunctionBlocker;
|
||||||
class cmCommand;
|
class cmCommand;
|
||||||
|
@ -1039,6 +1042,26 @@ private:
|
||||||
|
|
||||||
bool GeneratingBuildSystem;
|
bool GeneratingBuildSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Old version of GetSourceFileWithOutput(const char*) kept for
|
||||||
|
* backward-compatibility. It implements a linear search and support
|
||||||
|
* relative file paths. It is used as a fall back by
|
||||||
|
* GetSourceFileWithOutput(const char*).
|
||||||
|
*/
|
||||||
|
cmSourceFile *LinearGetSourceFileWithOutput(const char *cname);
|
||||||
|
|
||||||
|
// A map for fast output to input look up.
|
||||||
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
|
typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap;
|
||||||
|
#else
|
||||||
|
typedef std::map<std::string, cmSourceFile*> OutputToSourceMap;
|
||||||
|
#endif
|
||||||
|
OutputToSourceMap OutputToSource;
|
||||||
|
|
||||||
|
void UpdateOutputToSourceMap(std::vector<std::string> const& outputs,
|
||||||
|
cmSourceFile* source);
|
||||||
|
void UpdateOutputToSourceMap(std::string const& output,
|
||||||
|
cmSourceFile* source);
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue