ENH: Modified GetObjectFileNameWithoutTarget to use relative paths for object file names with sources above the current directory so long as the relative path conversion works.

This commit is contained in:
Brad King 2007-03-07 17:39:16 -05:00
parent 4036627487
commit b90e241a31

View File

@ -2461,21 +2461,20 @@ std::string& cmLocalGenerator::CreateSafeUniqueObjectFileName(const char* sin)
std::string std::string
cmLocalGenerator::GetObjectFileNameWithoutTarget(const cmSourceFile& source) cmLocalGenerator::GetObjectFileNameWithoutTarget(const cmSourceFile& source)
{ {
// If the source file is located below the current binary directory // Construct the object file name using the full path to the source
// then use that relative path for the object file name. // file which is its only unique identification. Convert the path
// to be relative to the current binary directory if possible.
std::string objectName = this->Convert(source.GetFullPath().c_str(), std::string objectName = this->Convert(source.GetFullPath().c_str(),
START_OUTPUT); START_OUTPUT);
if(cmSystemTools::FileIsFullPath(objectName.c_str()) || if(cmSystemTools::FileIsFullPath(objectName.c_str()) || objectName.empty())
objectName.empty() || objectName[0] == '.')
{ {
// If the source file is located below the current source // If the source file can be referenced as a relative path from
// directory then use that relative path for the object file name. // the source tree use that relative path to construct the object
// Otherwise just use the relative path from the current binary // name.
// directory.
std::string relFromSource = this->Convert(source.GetFullPath().c_str(), std::string relFromSource = this->Convert(source.GetFullPath().c_str(),
START); START);
if(!cmSystemTools::FileIsFullPath(relFromSource.c_str()) && if(!cmSystemTools::FileIsFullPath(relFromSource.c_str()) &&
!relFromSource.empty() && relFromSource[0] != '.') !relFromSource.empty())
{ {
objectName = relFromSource; objectName = relFromSource;
} }