diff options
Diffstat (limited to 'Source/cmLocalGenerator.cxx')
-rw-r--r-- | Source/cmLocalGenerator.cxx | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index a73fbce..e604320 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -2081,3 +2081,120 @@ cmLocalGenerator } } } + +//---------------------------------------------------------------------------- +std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName(const char* sin) +{ + // Look for an existing mapped name for this object file. + std::map<cmStdString,cmStdString>::iterator it = + this->UniqueObjectNamesMap.find(sin); + + // If no entry exists create one. + if(it == this->UniqueObjectNamesMap.end()) + { + // Start with the original name. + std::string ssin = sin; + + // Avoid full paths by removing leading slashes. + std::string::size_type pos = 0; + for(;pos < ssin.size() && ssin[pos] == '/'; ++pos); + ssin = ssin.substr(pos); + + // Avoid full paths by removing colons. + cmSystemTools::ReplaceString(ssin, ":", "_"); + + // Avoid relative paths that go up the tree. + cmSystemTools::ReplaceString(ssin, "../", "__/"); + + // Avoid spaces. + cmSystemTools::ReplaceString(ssin, " ", "_"); + + // Mangle the name if necessary. + if(this->Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES")) + { + bool done; + int cc = 0; + char rpstr[100]; + sprintf(rpstr, "_p_"); + cmSystemTools::ReplaceString(ssin, "+", rpstr); + std::string sssin = sin; + do + { + done = true; + for ( it = this->UniqueObjectNamesMap.begin(); + it != this->UniqueObjectNamesMap.end(); + ++ it ) + { + if ( it->second == ssin ) + { + done = false; + } + } + if ( done ) + { + break; + } + sssin = ssin; + cmSystemTools::ReplaceString(ssin, "_p_", rpstr); + sprintf(rpstr, "_p%d_", cc++); + } + while ( !done ); + } + + // Insert the newly mapped object file name. + std::map<cmStdString, cmStdString>::value_type e(sin, ssin); + it = this->UniqueObjectNamesMap.insert(e).first; + } + + // Return the map entry. + return it->second; +} + +//---------------------------------------------------------------------------- +std::string +cmLocalGenerator::GetObjectFileNameWithoutTarget(const cmSourceFile& source) +{ + // If the source file is located below the current binary directory + // then use that relative path for the object file name. + std::string objectName = this->Convert(source.GetFullPath().c_str(), + START_OUTPUT); + if(cmSystemTools::FileIsFullPath(objectName.c_str()) || + objectName.empty() || objectName[0] == '.') + { + // If the source file is located below the current source + // directory then use that relative path for the object file name. + // Otherwise just use the relative path from the current binary + // directory. + std::string relFromSource = this->Convert(source.GetFullPath().c_str(), + START); + if(!cmSystemTools::FileIsFullPath(relFromSource.c_str()) && + !relFromSource.empty() && relFromSource[0] != '.') + { + objectName = relFromSource; + } + } + + // Replace the original source file extension with the object file + // extension. + std::string::size_type dot_pos = objectName.rfind("."); + if(dot_pos != std::string::npos) + { + objectName = objectName.substr(0, dot_pos); + } + if ( source.GetPropertyAsBool("KEEP_EXTENSION") ) + { + if ( !source.GetSourceExtension().empty() ) + { + objectName += "." + source.GetSourceExtension(); + } + } + else + { + objectName += + this->GlobalGenerator->GetLanguageOutputExtensionFromExtension( + source.GetSourceExtension().c_str()); + } + + // Convert to a safe name. + return this->CreateSafeUniqueObjectFileName(objectName.c_str()); +} |