diff options
Diffstat (limited to 'Source/cmSourceFileLocation.cxx')
-rw-r--r-- | Source/cmSourceFileLocation.cxx | 161 |
1 files changed, 92 insertions, 69 deletions
diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index 5a8578b..1c2454e 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -16,28 +16,57 @@ #include "cmGlobalGenerator.h" #include "cmSystemTools.h" +#include "assert.h" + //---------------------------------------------------------------------------- -cmSourceFileLocation -::cmSourceFileLocation(cmMakefile const* mf, const char* name): Makefile(mf) +cmSourceFileLocation::cmSourceFileLocation() + : Makefile(0), AmbiguousDirectory(true), AmbiguousExtension(true) { - this->AmbiguousDirectory = !cmSystemTools::FileIsFullPath(name); - this->AmbiguousExtension = true; - this->Directory = cmSystemTools::GetFilenamePath(name); - this->Name = cmSystemTools::GetFilenameName(name); - this->UpdateExtension(name); + } //---------------------------------------------------------------------------- -void cmSourceFileLocation::Update(const char* name) +cmSourceFileLocation::cmSourceFileLocation(const cmSourceFileLocation& loc) + : Makefile(loc.Makefile) { - if(this->AmbiguousDirectory) + this->AmbiguousDirectory = loc.AmbiguousDirectory; + this->AmbiguousExtension = loc.AmbiguousExtension; + this->Directory = loc.Directory; + this->Name = loc.Name; +} + +//---------------------------------------------------------------------------- +cmSourceFileLocation& +cmSourceFileLocation::operator=(const cmSourceFileLocation& loc) +{ + if(this == &loc) { - this->UpdateDirectory(name); + return *this; } - if(this->AmbiguousExtension) + this->Makefile = loc.Makefile; + this->AmbiguousDirectory = loc.AmbiguousDirectory; + this->AmbiguousExtension = loc.AmbiguousExtension; + this->Directory = loc.Directory; + this->Name = loc.Name; + this->UpdateExtension(this->Name); + return *this; +} + +//---------------------------------------------------------------------------- +cmSourceFileLocation +::cmSourceFileLocation(cmMakefile const* mf, const std::string& name) + : Makefile(mf) +{ + this->AmbiguousDirectory = !cmSystemTools::FileIsFullPath(name.c_str()); + this->AmbiguousExtension = true; + this->Directory = cmSystemTools::GetFilenamePath(name); + if (cmSystemTools::FileIsFullPath(this->Directory.c_str())) { - this->UpdateExtension(name); + this->Directory + = cmSystemTools::CollapseFullPath(this->Directory.c_str()); } + this->Name = cmSystemTools::GetFilenameName(name); + this->UpdateExtension(name); } //---------------------------------------------------------------------------- @@ -58,6 +87,7 @@ void cmSourceFileLocation::Update(cmSourceFileLocation const& loc) //---------------------------------------------------------------------------- void cmSourceFileLocation::DirectoryUseSource() { + assert(this->Makefile); if(this->AmbiguousDirectory) { this->Directory = @@ -70,6 +100,7 @@ void cmSourceFileLocation::DirectoryUseSource() //---------------------------------------------------------------------------- void cmSourceFileLocation::DirectoryUseBinary() { + assert(this->Makefile); if(this->AmbiguousDirectory) { this->Directory = @@ -80,8 +111,9 @@ void cmSourceFileLocation::DirectoryUseBinary() } //---------------------------------------------------------------------------- -void cmSourceFileLocation::UpdateExtension(const char* name) +void cmSourceFileLocation::UpdateExtension(const std::string& name) { + assert(this->Makefile); // Check the extension. std::string ext = cmSystemTools::GetFilenameLastExtension(name); if(!ext.empty()) { ext = ext.substr(1); } @@ -92,7 +124,7 @@ void cmSourceFileLocation::UpdateExtension(const char* name) cmMakefile const* mf = this->Makefile; const std::vector<std::string>& srcExts = mf->GetSourceExtensions(); const std::vector<std::string>& hdrExts = mf->GetHeaderExtensions(); - if(gg->GetLanguageFromExtension(ext.c_str()) || + if(!gg->GetLanguageFromExtension(ext.c_str()).empty() || std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end() || std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end()) { @@ -136,21 +168,11 @@ void cmSourceFileLocation::UpdateExtension(const char* name) } //---------------------------------------------------------------------------- -void cmSourceFileLocation::UpdateDirectory(const char* name) -{ - // If a full path was given we know the directory. - if(cmSystemTools::FileIsFullPath(name)) - { - this->Directory = cmSystemTools::GetFilenamePath(name); - this->AmbiguousDirectory = false; - } -} - -//---------------------------------------------------------------------------- bool cmSourceFileLocation ::MatchesAmbiguousExtension(cmSourceFileLocation const& loc) const { + assert(this->Makefile); // This location's extension is not ambiguous but loc's extension // is. See if the names match as-is. if(this->Name == loc.Name) @@ -161,15 +183,16 @@ cmSourceFileLocation // Check if loc's name could possibly be extended to our name by // adding an extension. if(!(this->Name.size() > loc.Name.size() && - this->Name.substr(0, loc.Name.size()) == loc.Name && - this->Name[loc.Name.size()] == '.')) + this->Name[loc.Name.size()] == '.' && + cmHasLiteralPrefixImpl(this->Name.c_str(), + loc.Name.c_str(), loc.Name.size()))) { return false; } // Only a fixed set of extensions will be tried to match a file on // disk. One of these must match if loc refers to this source file. - std::string ext = this->Name.substr(loc.Name.size()+1); + std::string const& ext = this->Name.substr(loc.Name.size()+1); cmMakefile const* mf = this->Makefile; const std::vector<std::string>& srcExts = mf->GetSourceExtensions(); if(std::find(srcExts.begin(), srcExts.end(), ext) != srcExts.end()) @@ -187,36 +210,34 @@ cmSourceFileLocation //---------------------------------------------------------------------------- bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc) { - if(this->AmbiguousExtension && loc.AmbiguousExtension) + assert(this->Makefile); + if(this->AmbiguousExtension == loc.AmbiguousExtension) { - // Both extensions are ambiguous. Since only the old fixed set of - // extensions will be tried, the names must match at this point to - // be the same file. - if(this->Name != loc.Name) + // Both extensions are similarly ambiguous. Since only the old fixed set + // of extensions will be tried, the names must match at this point to be + // the same file. + if(this->Name.size() != loc.Name.size() || this->Name != loc.Name) { return false; } } - else if(this->AmbiguousExtension) + else { - // Only "this" extension is ambiguous. - if(!loc.MatchesAmbiguousExtension(*this)) + const cmSourceFileLocation* loc1; + const cmSourceFileLocation* loc2; + if(this->AmbiguousExtension) { - return false; + // Only "this" extension is ambiguous. + loc1 = &loc; + loc2 = this; } - } - else if(loc.AmbiguousExtension) - { - // Only "loc" extension is ambiguous. - if(!this->MatchesAmbiguousExtension(loc)) + else { - return false; + // Only "loc" extension is ambiguous. + loc1 = this; + loc2 = &loc; } - } - else - { - // Neither extension is ambiguous. - if(this->Name != loc.Name) + if(!loc1->MatchesAmbiguousExtension(*loc2)) { return false; } @@ -230,35 +251,37 @@ bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc) return false; } } - else if(this->AmbiguousDirectory && loc.AmbiguousDirectory && - this->Makefile == loc.Makefile) + else if(this->AmbiguousDirectory && loc.AmbiguousDirectory) { - // Both sides have directories relative to the same location. - if(this->Directory != loc.Directory) + if (this->Makefile == loc.Makefile) { + // Both sides have directories relative to the same location. + if(this->Directory != loc.Directory) + { + return false; + } + } + else + { + // Each side has a directory relative to a different location. + // This can occur when referencing a source file from a different + // directory. This is not yet allowed. + this->Makefile->IssueMessage( + cmake::INTERNAL_ERROR, + "Matches error: Each side has a directory relative to a different " + "location. This can occur when referencing a source file from a " + "different directory. This is not yet allowed." + ); return false; } } - else if(this->AmbiguousDirectory && loc.AmbiguousDirectory) - { - // Each side has a directory relative to a different location. - // This can occur when referencing a source file from a different - // directory. This is not yet allowed. - this->Makefile->IssueMessage( - cmake::INTERNAL_ERROR, - "Matches error: Each side has a directory relative to a different " - "location. This can occur when referencing a source file from a " - "different directory. This is not yet allowed." - ); - return false; - } else if(this->AmbiguousDirectory) { // Compare possible directory combinations. - std::string srcDir = + std::string const& srcDir = cmSystemTools::CollapseFullPath( this->Directory.c_str(), this->Makefile->GetCurrentDirectory()); - std::string binDir = + std::string const& binDir = cmSystemTools::CollapseFullPath( this->Directory.c_str(), this->Makefile->GetCurrentOutputDirectory()); if(srcDir != loc.Directory && @@ -270,10 +293,10 @@ bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc) else if(loc.AmbiguousDirectory) { // Compare possible directory combinations. - std::string srcDir = + std::string const& srcDir = cmSystemTools::CollapseFullPath( loc.Directory.c_str(), loc.Makefile->GetCurrentDirectory()); - std::string binDir = + std::string const& binDir = cmSystemTools::CollapseFullPath( loc.Directory.c_str(), loc.Makefile->GetCurrentOutputDirectory()); if(srcDir != this->Directory && |