2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2005-03-18 18:39:21 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2005-03-18 18:39:21 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2005-03-18 18:39:21 +03:00
|
|
|
#include "cmAddSubDirectoryCommand.h"
|
|
|
|
|
|
|
|
// cmAddSubDirectoryCommand
|
2006-05-10 21:50:44 +04:00
|
|
|
bool cmAddSubDirectoryCommand::InitialPass
|
2008-01-23 18:28:26 +03:00
|
|
|
(std::vector<std::string> const& args, cmExecutionStatus &)
|
2005-03-18 18:39:21 +03:00
|
|
|
{
|
|
|
|
if(args.size() < 1 )
|
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2005-03-18 18:39:21 +03:00
|
|
|
// store the binpath
|
2005-09-12 21:46:16 +04:00
|
|
|
std::string srcArg = args[0];
|
|
|
|
std::string binArg;
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2007-03-12 17:26:59 +03:00
|
|
|
bool excludeFromAll = false;
|
2005-03-18 18:39:21 +03:00
|
|
|
|
|
|
|
// process the rest of the arguments looking for optional args
|
|
|
|
std::vector<std::string>::const_iterator i = args.begin();
|
|
|
|
++i;
|
|
|
|
for(;i != args.end(); ++i)
|
|
|
|
{
|
|
|
|
if(*i == "EXCLUDE_FROM_ALL")
|
|
|
|
{
|
2007-03-12 17:26:59 +03:00
|
|
|
excludeFromAll = true;
|
2005-03-18 18:39:21 +03:00
|
|
|
continue;
|
|
|
|
}
|
2015-01-16 01:13:44 +03:00
|
|
|
else if (binArg.empty())
|
2005-03-18 18:39:21 +03:00
|
|
|
{
|
2005-09-12 21:46:16 +04:00
|
|
|
binArg = *i;
|
2005-03-18 18:39:21 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-01 00:40:38 +04:00
|
|
|
// Compute the full path to the specified source directory.
|
|
|
|
// Interpret a relative path with respect to the current source directory.
|
|
|
|
std::string srcPath;
|
|
|
|
if(cmSystemTools::FileIsFullPath(srcArg.c_str()))
|
2005-03-18 18:39:21 +03:00
|
|
|
{
|
|
|
|
srcPath = srcArg;
|
|
|
|
}
|
2006-09-01 00:40:38 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
srcPath = this->Makefile->GetCurrentDirectory();
|
|
|
|
srcPath += "/";
|
|
|
|
srcPath += srcArg;
|
|
|
|
}
|
2014-10-15 16:54:05 +04:00
|
|
|
if(!cmSystemTools::FileIsDirectory(srcPath))
|
2006-09-01 00:40:38 +04:00
|
|
|
{
|
|
|
|
std::string error = "given source \"";
|
|
|
|
error += srcArg;
|
|
|
|
error += "\" which is not an existing directory.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(error);
|
2006-09-01 00:40:38 +04:00
|
|
|
return false;
|
|
|
|
}
|
2014-10-15 16:54:05 +04:00
|
|
|
srcPath = cmSystemTools::CollapseFullPath(srcPath);
|
2006-09-01 00:40:38 +04:00
|
|
|
|
|
|
|
// Compute the full path to the binary directory.
|
|
|
|
std::string binPath;
|
|
|
|
if(binArg.empty())
|
2005-03-18 18:39:21 +03:00
|
|
|
{
|
2006-09-01 00:40:38 +04:00
|
|
|
// No binary directory was specified. If the source directory is
|
|
|
|
// not a subdirectory of the current directory then it is an
|
|
|
|
// error.
|
2014-10-15 16:54:05 +04:00
|
|
|
if(!cmSystemTools::IsSubDirectory(srcPath,
|
2006-09-01 00:40:38 +04:00
|
|
|
this->Makefile->GetCurrentDirectory()))
|
2005-09-12 21:46:16 +04:00
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2006-09-01 00:40:38 +04:00
|
|
|
e << "not given a binary directory but the given source directory "
|
|
|
|
<< "\"" << srcPath << "\" is not a subdirectory of \""
|
|
|
|
<< this->Makefile->GetCurrentDirectory() << "\". "
|
|
|
|
<< "When specifying an out-of-tree source a binary directory "
|
|
|
|
<< "must be explicitly specified.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2006-09-01 00:40:38 +04:00
|
|
|
return false;
|
2005-09-12 21:46:16 +04:00
|
|
|
}
|
2006-09-01 00:40:38 +04:00
|
|
|
|
|
|
|
// Remove the CurrentDirectory from the srcPath and replace it
|
|
|
|
// with the CurrentOutputDirectory.
|
2013-03-12 19:47:49 +04:00
|
|
|
const char* src = this->Makefile->GetCurrentDirectory();
|
|
|
|
const char* bin = this->Makefile->GetCurrentOutputDirectory();
|
|
|
|
size_t srcLen = strlen(src);
|
|
|
|
size_t binLen = strlen(bin);
|
|
|
|
if(srcLen > 0 && src[srcLen-1] == '/')
|
|
|
|
{ --srcLen; }
|
|
|
|
if(binLen > 0 && bin[binLen-1] == '/')
|
|
|
|
{ --binLen; }
|
|
|
|
binPath = std::string(bin, binLen) + srcPath.substr(srcLen);
|
2005-09-12 21:46:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-01 00:40:38 +04:00
|
|
|
// Use the binary directory specified.
|
|
|
|
// Interpret a relative path with respect to the current binary directory.
|
|
|
|
if(cmSystemTools::FileIsFullPath(binArg.c_str()))
|
2005-09-12 21:46:16 +04:00
|
|
|
{
|
2006-09-01 00:40:38 +04:00
|
|
|
binPath = binArg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
binPath = this->Makefile->GetCurrentOutputDirectory();
|
|
|
|
binPath += "/";
|
|
|
|
binPath += binArg;
|
2005-09-12 21:46:16 +04:00
|
|
|
}
|
2005-03-18 18:39:21 +03:00
|
|
|
}
|
2014-10-15 16:54:05 +04:00
|
|
|
binPath = cmSystemTools::CollapseFullPath(binPath);
|
2006-09-01 00:40:38 +04:00
|
|
|
|
|
|
|
// Add the subdirectory using the computed full paths.
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddSubDirectory(srcPath, binPath,
|
2015-04-01 21:01:52 +03:00
|
|
|
excludeFromAll, true);
|
2005-03-18 18:39:21 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|