ENH: Introducing new policy to construct more unique object file names. This should allow multiple sources with the same file name but different FULL paths to be added to a single target.

This commit is contained in:
Brad King 2006-03-13 15:19:03 -05:00
parent 4f9efe7502
commit 2b316f169c

View File

@ -919,13 +919,22 @@ cmLocalUnixMakefileGenerator3
std::string& std::string&
cmLocalUnixMakefileGenerator3::CreateSafeUniqueObjectFileName(const char* sin) cmLocalUnixMakefileGenerator3::CreateSafeUniqueObjectFileName(const char* sin)
{ {
if ( m_Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES") ) // Look for an existing mapped name for this object file.
{
std::map<cmStdString,cmStdString>::iterator it = std::map<cmStdString,cmStdString>::iterator it =
m_UniqueObjectNamesMap.find(sin); m_UniqueObjectNamesMap.find(sin);
// If no entry exists create one.
if(it == m_UniqueObjectNamesMap.end()) if(it == m_UniqueObjectNamesMap.end())
{ {
// Start with the original name.
std::string ssin = sin; std::string ssin = sin;
// Avoid relative paths that go up the tree.
cmSystemTools::ReplaceString(ssin, "../", "__/");
// Mangle the name if necessary.
if(m_Makefile->IsOn("CMAKE_MANGLE_OBJECT_FILE_NAMES"))
{
bool done; bool done;
int cc = 0; int cc = 0;
char rpstr[100]; char rpstr[100];
@ -953,14 +962,15 @@ cmLocalUnixMakefileGenerator3::CreateSafeUniqueObjectFileName(const char* sin)
sprintf(rpstr, "_p%d_", cc++); sprintf(rpstr, "_p%d_", cc++);
} }
while ( !done ); while ( !done );
m_UniqueObjectNamesMap[sin] = ssin;
} }
// Insert the newly mapped object file name.
std::map<cmStdString, cmStdString>::value_type e(sin, ssin);
it = m_UniqueObjectNamesMap.insert(e).first;
} }
else
{ // Return the map entry.
m_UniqueObjectNamesMap[sin] = sin; return it->second;
}
return m_UniqueObjectNamesMap[sin];
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -1486,32 +1496,40 @@ cmLocalUnixMakefileGenerator3
const cmSourceFile& source, const cmSourceFile& source,
std::string* nameWithoutTargetDir) std::string* nameWithoutTargetDir)
{ {
// If the full path to the source file includes this directory, // If the source file is located below the current binary directory
// we want to use the relative path for the filename of the // then use that relative path for the object file name.
// object file. Otherwise, we will use just the filename std::string objectName =
// portion. cmSystemTools::RelativePath(m_Makefile->GetCurrentOutputDirectory(),
std::string objectName; source.GetFullPath().c_str());
if((cmSystemTools::GetFilenamePath( if(objectName.empty() || objectName[0] == '.')
source.GetFullPath()).find(
m_Makefile->GetCurrentDirectory()) == 0)
|| (cmSystemTools::GetFilenamePath(
source.GetFullPath()).find(
m_Makefile->GetStartOutputDirectory()) == 0))
{ {
objectName = source.GetSourceName(); // 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 =
cmSystemTools::RelativePath(m_Makefile->GetCurrentDirectory(),
source.GetFullPath().c_str());
if(!relFromSource.empty() && relFromSource[0] != '.')
{
objectName = relFromSource;
} }
else
{
objectName = cmSystemTools::GetFilenameName(source.GetSourceName());
} }
// Append the object file extension. // 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);
}
objectName += objectName +=
m_GlobalGenerator->GetLanguageOutputExtensionFromExtension( m_GlobalGenerator->GetLanguageOutputExtensionFromExtension(
source.GetSourceExtension().c_str()); source.GetSourceExtension().c_str());
// Convert to a safe name. // Convert to a safe name.
objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str()); objectName = this->CreateSafeUniqueObjectFileName(objectName.c_str());
// Prepend the target directory. // Prepend the target directory.
std::string obj = this->GetTargetDirectory(target); std::string obj = this->GetTargetDirectory(target);
obj += "/"; obj += "/";