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
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmAddSubDirectoryCommand::InitialPass(
|
|
|
|
std::vector<std::string> const& args, cmExecutionStatus&)
|
2005-03-18 18:39:21 +03:00
|
|
|
{
|
2016-09-16 00:59:29 +03:00
|
|
|
if (args.empty()) {
|
2005-03-18 18:39:21 +03:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (binArg.empty()) {
|
2005-09-12 21:46:16 +04:00
|
|
|
binArg = *i;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2005-03-18 18:39:21 +03:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2005-03-18 18:39:21 +03:00
|
|
|
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsFullPath(srcArg.c_str())) {
|
2005-03-18 18:39:21 +03:00
|
|
|
srcPath = srcArg;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-04-16 22:17:41 +03:00
|
|
|
srcPath = this->Makefile->GetCurrentSourceDirectory();
|
2006-09-01 00:40:38 +04:00
|
|
|
srcPath += "/";
|
|
|
|
srcPath += srcArg;
|
2016-05-16 17:34:04 +03: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;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
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;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (binArg.empty()) {
|
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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::IsSubDirectory(
|
|
|
|
srcPath, this->Makefile->GetCurrentSourceDirectory())) {
|
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 \""
|
2015-04-16 22:17:41 +03:00
|
|
|
<< this->Makefile->GetCurrentSourceDirectory() << "\". "
|
2006-09-01 00:40:38 +04:00
|
|
|
<< "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;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-09-01 00:40:38 +04:00
|
|
|
|
|
|
|
// Remove the CurrentDirectory from the srcPath and replace it
|
|
|
|
// with the CurrentOutputDirectory.
|
2015-04-16 22:17:41 +03:00
|
|
|
const char* src = this->Makefile->GetCurrentSourceDirectory();
|
2015-04-16 22:33:09 +03:00
|
|
|
const char* bin = this->Makefile->GetCurrentBinaryDirectory();
|
2013-03-12 19:47:49 +04:00
|
|
|
size_t srcLen = strlen(src);
|
|
|
|
size_t binLen = strlen(bin);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (srcLen > 0 && src[srcLen - 1] == '/') {
|
|
|
|
--srcLen;
|
2005-09-12 21:46:16 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (binLen > 0 && bin[binLen - 1] == '/') {
|
|
|
|
--binLen;
|
|
|
|
}
|
|
|
|
binPath = std::string(bin, binLen) + srcPath.substr(srcLen);
|
|
|
|
} 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.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsFullPath(binArg.c_str())) {
|
2006-09-01 00:40:38 +04:00
|
|
|
binPath = binArg;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-04-16 22:33:09 +03:00
|
|
|
binPath = this->Makefile->GetCurrentBinaryDirectory();
|
2006-09-01 00:40:38 +04:00
|
|
|
binPath += "/";
|
|
|
|
binPath += binArg;
|
2005-03-18 18:39:21 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +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.
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->AddSubDirectory(srcPath, binPath, excludeFromAll, true);
|
2005-03-18 18:39:21 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|