BUG: Fix automatic computation of binary path to work for subdirectories of out of source directories. This addresses bug#3592.

This commit is contained in:
Brad King 2006-08-31 16:40:38 -04:00
parent 409f70bc91
commit e09dd5db09
1 changed files with 59 additions and 47 deletions

View File

@ -53,64 +53,76 @@ bool cmAddSubDirectoryCommand::InitialPass
} }
} }
// check for relative arguments // Compute the full path to the specified source directory.
std::string binPath = binArg; // Interpret a relative path with respect to the current source directory.
std::string srcPath = std::string(this->Makefile->GetCurrentDirectory()) + std::string srcPath;
"/" + srcArg; if(cmSystemTools::FileIsFullPath(srcArg.c_str()))
// if the path does not exist then the arg was relative
if (!cmSystemTools::FileIsDirectory(srcPath.c_str()))
{ {
srcPath = srcArg; srcPath = srcArg;
if (!cmSystemTools::FileIsDirectory(srcPath.c_str()))
{
std::string error = "Incorrect ADD_SUBDIRECTORY command. Directory: ";
error += srcArg + " does not exists.";
this->SetError(error.c_str());
return false;
}
} }
// at this point srcPath has the full path to the source directory
// now we need to compute the binPath if it was not provided
srcPath = cmSystemTools::CollapseFullPath(srcPath.c_str());
// if the argument was provided then use it
if (binArg.size())
{
if (!cmSystemTools::FileIsFullPath(binPath.c_str()))
{
binPath = std::string(this->Makefile->GetCurrentOutputDirectory()) +
"/" + binArg.c_str();
}
}
// otherwise compute the binPath from the srcPath
else else
{ {
// we try to remove the CurrentDirectory from the srcPath and srcPath = this->Makefile->GetCurrentDirectory();
// replace it with the CurrentOutputDirectory. This may not really work srcPath += "/";
// because the source dir they provided may not be "in" the source srcPath += srcArg;
// tree. This is an error if this happens. }
// try replacing the home dir with the home output dir if(!cmSystemTools::FileIsDirectory(srcPath.c_str()))
binPath = srcPath; {
if(!cmSystemTools::FindLastString(binPath.c_str(), std::string error = "given source \"";
this->Makefile->GetHomeDirectory())) error += srcArg;
error += "\" which is not an existing directory.";
this->SetError(error.c_str());
return false;
}
srcPath = cmSystemTools::CollapseFullPath(srcPath.c_str());
// Compute the full path to the binary directory.
std::string binPath;
if(binArg.empty())
{
// No binary directory was specified. If the source directory is
// not a subdirectory of the current directory then it is an
// error.
if(!cmSystemTools::FindLastString(srcPath.c_str(),
this->Makefile->GetCurrentDirectory()))
{ {
this->SetError("A full source directory was specified that is not " cmOStringStream e;
"in the source tree but no binary directory was " e << "not given a binary directory but the given source directory "
"specified. If you specify an out of tree source " << "\"" << srcPath << "\" is not a subdirectory of \""
"directory then you must provide the binary " << this->Makefile->GetCurrentDirectory() << "\". "
"directory as well."); << "When specifying an out-of-tree source a binary directory "
<< "must be explicitly specified.";
this->SetError(e.str().c_str());
return false; return false;
} }
// Remove the CurrentDirectory from the srcPath and replace it
// with the CurrentOutputDirectory.
binPath = srcPath;
cmSystemTools::ReplaceString(binPath, cmSystemTools::ReplaceString(binPath,
this->Makefile->GetHomeDirectory(), this->Makefile->GetCurrentDirectory(),
this->Makefile->GetHomeOutputDirectory()); this->Makefile->GetCurrentOutputDirectory());
} }
else
// now we have all the arguments {
// Use the binary directory specified.
// Interpret a relative path with respect to the current binary directory.
if(cmSystemTools::FileIsFullPath(binArg.c_str()))
{
binPath = binArg;
}
else
{
binPath = this->Makefile->GetCurrentOutputDirectory();
binPath += "/";
binPath += binArg;
}
}
binPath = cmSystemTools::CollapseFullPath(binPath.c_str());
// Add the subdirectory using the computed full paths.
this->Makefile->AddSubDirectory(srcPath.c_str(), binPath.c_str(), this->Makefile->AddSubDirectory(srcPath.c_str(), binPath.c_str(),
intoplevel, false, true); intoplevel, false, true);
return true; return true;
} }