1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmAddSubDirectoryCommand.h"
14 // cmAddSubDirectoryCommand
15 bool cmAddSubDirectoryCommand::InitialPass
16 (std::vector<std::string> const& args, cmExecutionStatus &)
20 this->SetError("called with incorrect number of arguments");
25 std::string srcArg = args[0];
28 bool excludeFromAll = false;
30 // process the rest of the arguments looking for optional args
31 std::vector<std::string>::const_iterator i = args.begin();
33 for(;i != args.end(); ++i)
35 if(*i == "EXCLUDE_FROM_ALL")
37 excludeFromAll = true;
40 else if (!binArg.size())
46 this->SetError("called with incorrect number of arguments");
51 // Compute the full path to the specified source directory.
52 // Interpret a relative path with respect to the current source directory.
54 if(cmSystemTools::FileIsFullPath(srcArg.c_str()))
60 srcPath = this->Makefile->GetCurrentDirectory();
64 if(!cmSystemTools::FileIsDirectory(srcPath.c_str()))
66 std::string error = "given source \"";
68 error += "\" which is not an existing directory.";
69 this->SetError(error.c_str());
72 srcPath = cmSystemTools::CollapseFullPath(srcPath.c_str());
74 // Compute the full path to the binary directory.
78 // No binary directory was specified. If the source directory is
79 // not a subdirectory of the current directory then it is an
81 if(!cmSystemTools::IsSubDirectory(srcPath.c_str(),
82 this->Makefile->GetCurrentDirectory()))
85 e << "not given a binary directory but the given source directory "
86 << "\"" << srcPath << "\" is not a subdirectory of \""
87 << this->Makefile->GetCurrentDirectory() << "\". "
88 << "When specifying an out-of-tree source a binary directory "
89 << "must be explicitly specified.";
90 this->SetError(e.str().c_str());
94 // Remove the CurrentDirectory from the srcPath and replace it
95 // with the CurrentOutputDirectory.
96 const char* src = this->Makefile->GetCurrentDirectory();
97 const char* bin = this->Makefile->GetCurrentOutputDirectory();
98 size_t srcLen = strlen(src);
99 size_t binLen = strlen(bin);
100 if(srcLen > 0 && src[srcLen-1] == '/')
102 if(binLen > 0 && bin[binLen-1] == '/')
104 binPath = std::string(bin, binLen) + srcPath.substr(srcLen);
108 // Use the binary directory specified.
109 // Interpret a relative path with respect to the current binary directory.
110 if(cmSystemTools::FileIsFullPath(binArg.c_str()))
116 binPath = this->Makefile->GetCurrentOutputDirectory();
121 binPath = cmSystemTools::CollapseFullPath(binPath.c_str());
123 // Add the subdirectory using the computed full paths.
124 this->Makefile->AddSubDirectory(srcPath.c_str(), binPath.c_str(),
125 excludeFromAll, false, true);