ENH: Further centralized custom command dependency computation. Custom command dependencies in the source tree may now also be specified relative to the source directory.
This commit is contained in:
parent
18477b194c
commit
8340c0d186
|
@ -1620,8 +1620,7 @@ void cmLocalGenerator::AddLanguageFlags(std::string& flags,
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
std::string cmLocalGenerator::GetRealDependency(const char* inName,
|
std::string cmLocalGenerator::GetRealDependency(const char* inName,
|
||||||
const char* config,
|
const char* config)
|
||||||
bool* inLocal)
|
|
||||||
{
|
{
|
||||||
// Older CMake code may specify the dependency using the target
|
// Older CMake code may specify the dependency using the target
|
||||||
// output file rather than the target name. Such code would have
|
// output file rather than the target name. Such code would have
|
||||||
|
@ -1634,22 +1633,8 @@ std::string cmLocalGenerator::GetRealDependency(const char* inName,
|
||||||
name = cmSystemTools::GetFilenameWithoutLastExtension(name);
|
name = cmSystemTools::GetFilenameWithoutLastExtension(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for a CMake target in the current makefile.
|
// Look for a CMake target with the given name.
|
||||||
cmTarget* target = m_Makefile->FindTarget(name.c_str());
|
if(cmTarget* target = m_GlobalGenerator->FindTarget(0, name.c_str()))
|
||||||
|
|
||||||
// If no target was found in the current makefile search globally.
|
|
||||||
bool local = target?true:false;
|
|
||||||
if(inLocal)
|
|
||||||
{
|
|
||||||
*inLocal = local;
|
|
||||||
}
|
|
||||||
if(!local)
|
|
||||||
{
|
|
||||||
target = m_GlobalGenerator->FindTarget(0, name.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a target was found then get its real location.
|
|
||||||
if(target)
|
|
||||||
{
|
{
|
||||||
switch (target->GetType())
|
switch (target->GetType())
|
||||||
{
|
{
|
||||||
|
@ -1666,15 +1651,30 @@ std::string cmLocalGenerator::GetRealDependency(const char* inName,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case cmTarget::UTILITY:
|
case cmTarget::UTILITY:
|
||||||
|
// Depending on a utility target may not work but just trust
|
||||||
|
// the user to have given a valid name.
|
||||||
|
return inName;
|
||||||
case cmTarget::INSTALL_FILES:
|
case cmTarget::INSTALL_FILES:
|
||||||
case cmTarget::INSTALL_PROGRAMS:
|
case cmTarget::INSTALL_PROGRAMS:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The name was not that of a CMake target. The dependency should
|
// The name was not that of a CMake target. It must name a file.
|
||||||
// use the name as given.
|
if(cmSystemTools::FileIsFullPath(inName))
|
||||||
return inName;
|
{
|
||||||
|
// This is a full path. Return it as given.
|
||||||
|
return inName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Treat the name as relative to the source directory in which it
|
||||||
|
// was given.
|
||||||
|
name = m_Makefile->GetCurrentDirectory();
|
||||||
|
name += "/";
|
||||||
|
name += inName;
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
|
@ -137,12 +137,12 @@ public:
|
||||||
/** Translate a dependency as given in CMake code to the name to
|
/** Translate a dependency as given in CMake code to the name to
|
||||||
appear in a generated build file. If the given name is that of
|
appear in a generated build file. If the given name is that of
|
||||||
a CMake target it will be transformed to the real output
|
a CMake target it will be transformed to the real output
|
||||||
location of that target for the given configuration. Otherwise
|
location of that target for the given configuration. If the
|
||||||
the original name will be returned. If the local argument is
|
given name is the full path to a file it will be returned.
|
||||||
given it is set to indicate whethr the name is of a utility
|
Otherwise the name is treated as a relative path with respect to
|
||||||
target available in the same makefile. */
|
the source directory of this generator. This should only be
|
||||||
std::string GetRealDependency(const char* name, const char* config,
|
used for dependencies of custom commands. */
|
||||||
bool* local=0);
|
std::string GetRealDependency(const char* name, const char* config);
|
||||||
|
|
||||||
///! for existing files convert to output path and short path if spaces
|
///! for existing files convert to output path and short path if spaces
|
||||||
std::string ConvertToOutputForExisting(const char* p);
|
std::string ConvertToOutputForExisting(const char* p);
|
||||||
|
|
|
@ -2270,6 +2270,7 @@ cmLocalUnixMakefileGenerator3
|
||||||
::AppendTargetDepends(std::vector<std::string>& depends,
|
::AppendTargetDepends(std::vector<std::string>& depends,
|
||||||
cmTarget& target)
|
cmTarget& target)
|
||||||
{
|
{
|
||||||
|
// Static libraries never depend on anything for linking.
|
||||||
if(target.GetType() == cmTarget::STATIC_LIBRARY)
|
if(target.GetType() == cmTarget::STATIC_LIBRARY)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -2289,50 +2290,19 @@ cmLocalUnixMakefileGenerator3
|
||||||
// Don't emit the same library twice for this target.
|
// Don't emit the same library twice for this target.
|
||||||
if(emitted.insert(lib->first).second)
|
if(emitted.insert(lib->first).second)
|
||||||
{
|
{
|
||||||
// Add this dependency.
|
// Depend only on other CMake targets.
|
||||||
this->AppendAnyDepend(depends, lib->first.c_str());
|
if(cmTarget* tgt = m_GlobalGenerator->FindTarget(0, lib->first.c_str()))
|
||||||
|
{
|
||||||
|
if(const char* location =
|
||||||
|
tgt->GetLocation(m_ConfigurationName.c_str()))
|
||||||
|
{
|
||||||
|
depends.push_back(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
|
||||||
void
|
|
||||||
cmLocalUnixMakefileGenerator3
|
|
||||||
::AppendAnyDepend(std::vector<std::string>& depends, const char* name)
|
|
||||||
{
|
|
||||||
// There are a few cases for the name of the target:
|
|
||||||
// - CMake target.
|
|
||||||
// - Full path to a file: depend on it.
|
|
||||||
// - Other format (like -lm): no file on which to depend, do nothing.
|
|
||||||
|
|
||||||
// Lookup the real name of the dependency in case it is a CMake target.
|
|
||||||
bool local;
|
|
||||||
std::string dep = this->GetRealDependency(name,
|
|
||||||
m_ConfigurationName.c_str(),
|
|
||||||
&local);
|
|
||||||
if(dep == name)
|
|
||||||
{
|
|
||||||
if(local)
|
|
||||||
{
|
|
||||||
// The dependency is on a CMake utility target in the current
|
|
||||||
// makefile. Just depend on it directly.
|
|
||||||
depends.push_back(name);
|
|
||||||
}
|
|
||||||
else if(cmSystemTools::FileIsFullPath(name))
|
|
||||||
{
|
|
||||||
// This is a path to a file. Just trust the listfile author
|
|
||||||
// that it will be present or there is a rule to build it.
|
|
||||||
depends.push_back(cmSystemTools::CollapseFullPath(name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// The dependency is on a CMake target and has been transformed to
|
|
||||||
// the target's location on disk.
|
|
||||||
depends.push_back(dep);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
cmLocalUnixMakefileGenerator3
|
cmLocalUnixMakefileGenerator3
|
||||||
|
@ -2370,8 +2340,10 @@ cmLocalUnixMakefileGenerator3
|
||||||
for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
|
for(std::vector<std::string>::const_iterator d = cc.GetDepends().begin();
|
||||||
d != cc.GetDepends().end(); ++d)
|
d != cc.GetDepends().end(); ++d)
|
||||||
{
|
{
|
||||||
// Add this dependency.
|
// Lookup the real name of the dependency in case it is a CMake target.
|
||||||
this->AppendAnyDepend(depends, d->c_str());
|
std::string dep = this->GetRealDependency(d->c_str(),
|
||||||
|
m_ConfigurationName.c_str());
|
||||||
|
depends.push_back(dep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -327,7 +327,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 AppendAnyDepend(std::vector<std::string>& depends, const char* name);
|
|
||||||
void AppendRuleDepend(std::vector<std::string>& depends,
|
void AppendRuleDepend(std::vector<std::string>& depends,
|
||||||
const char* ruleFileName);
|
const char* ruleFileName);
|
||||||
void AppendCustomDepends(std::vector<std::string>& depends,
|
void AppendCustomDepends(std::vector<std::string>& depends,
|
||||||
|
|
Loading…
Reference in New Issue