From b1c5f1a7ba343178628dee6217d0059efa691522 Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Fri, 3 Dec 2004 09:05:07 -0500 Subject: [PATCH] ENH: fix for relative paths --- Source/cmMakefile.cxx | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 3187c4b2b..c6c8541ea 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1884,7 +1884,8 @@ cmSourceFile* cmMakefile::GetSource(const char* sourceName) const for(std::vector::const_iterator i = m_SourceFiles.begin(); i != m_SourceFiles.end(); ++i) { - if ((*i)->GetSourceName() == sname && + if (cmSystemTools::GetFilenameWithoutLastExtension((*i)->GetFullPath()) + == sname && cmSystemTools::GetFilenamePath((*i)->GetFullPath()) == path && (ext.size() == 0 || (ext == (*i)->GetSourceExtension()))) { @@ -2000,10 +2001,30 @@ cmSourceFile* cmMakefile::GetOrCreateSource(const char* sourceName, } else { - file.SetName(cmSystemTools::GetFilenameName(src.c_str()).c_str(), - path.c_str(), - this->GetSourceExtensions(), - this->GetHeaderExtensions()); + 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 + { + file.SetName(cmSystemTools::GetFilenameName(src.c_str()).c_str(), + path.c_str(), + this->GetSourceExtensions(), + this->GetHeaderExtensions()); + } } // add the source file to the makefile this->AddSource(file);