ENH: fix for relative paths

This commit is contained in:
Ken Martin 2004-12-03 09:05:07 -05:00
parent 82ec50f83f
commit b1c5f1a7ba
1 changed files with 26 additions and 5 deletions

View File

@ -1884,7 +1884,8 @@ cmSourceFile* cmMakefile::GetSource(const char* sourceName) const
for(std::vector<cmSourceFile*>::const_iterator i = m_SourceFiles.begin(); for(std::vector<cmSourceFile*>::const_iterator i = m_SourceFiles.begin();
i != m_SourceFiles.end(); ++i) i != m_SourceFiles.end(); ++i)
{ {
if ((*i)->GetSourceName() == sname && if (cmSystemTools::GetFilenameWithoutLastExtension((*i)->GetFullPath())
== sname &&
cmSystemTools::GetFilenamePath((*i)->GetFullPath()) == path && cmSystemTools::GetFilenamePath((*i)->GetFullPath()) == path &&
(ext.size() == 0 || (ext == (*i)->GetSourceExtension()))) (ext.size() == 0 || (ext == (*i)->GetSourceExtension())))
{ {
@ -1998,6 +1999,25 @@ cmSourceFile* cmMakefile::GetOrCreateSource(const char* sourceName,
m_HeaderFileExtensions.end()); m_HeaderFileExtensions.end());
file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), headerFile); file.SetName(name_no_ext.c_str(), path.c_str(), ext.c_str(), headerFile);
} }
else
{
std::string relPath = cmSystemTools::GetFilenamePath(sourceName);
if (relative && relPath.size())
{
// we need to keep the relative part of the filename
std::string fullPathLessRel = path;
std::string::size_type pos = fullPathLessRel.rfind(relPath);
if (pos == std::string::npos)
{
cmSystemTools::Error(
"CMake failed to properly look up relative cmSourceFile: ",
sourceName);
}
fullPathLessRel.erase(pos-1);
file.SetName(sourceName, fullPathLessRel.c_str(),
this->GetSourceExtensions(),
this->GetHeaderExtensions());
}
else else
{ {
file.SetName(cmSystemTools::GetFilenameName(src.c_str()).c_str(), file.SetName(cmSystemTools::GetFilenameName(src.c_str()).c_str(),
@ -2005,6 +2025,7 @@ cmSourceFile* cmMakefile::GetOrCreateSource(const char* sourceName,
this->GetSourceExtensions(), this->GetSourceExtensions(),
this->GetHeaderExtensions()); this->GetHeaderExtensions());
} }
}
// add the source file to the makefile // add the source file to the makefile
this->AddSource(file); this->AddSource(file);
src = file.GetFullPath(); src = file.GetFullPath();