KWSys Nightly Date Stamp
[cmake.git] / Source / cmAddSubDirectoryCommand.cxx
blob76009e936013d632fd77de1c44522fa072ac225a
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddSubDirectoryCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.11 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmAddSubDirectoryCommand.h"
19 // cmAddSubDirectoryCommand
20 bool cmAddSubDirectoryCommand::InitialPass
21 (std::vector<std::string> const& args, cmExecutionStatus &)
23 if(args.size() < 1 )
25 this->SetError("called with incorrect number of arguments");
26 return false;
29 // store the binpath
30 std::string srcArg = args[0];
31 std::string binArg;
33 bool excludeFromAll = false;
35 // process the rest of the arguments looking for optional args
36 std::vector<std::string>::const_iterator i = args.begin();
37 ++i;
38 for(;i != args.end(); ++i)
40 if(*i == "EXCLUDE_FROM_ALL")
42 excludeFromAll = true;
43 continue;
45 else if (!binArg.size())
47 binArg = *i;
49 else
51 this->SetError("called with incorrect number of arguments");
52 return false;
56 // Compute the full path to the specified source directory.
57 // Interpret a relative path with respect to the current source directory.
58 std::string srcPath;
59 if(cmSystemTools::FileIsFullPath(srcArg.c_str()))
61 srcPath = srcArg;
63 else
65 srcPath = this->Makefile->GetCurrentDirectory();
66 srcPath += "/";
67 srcPath += srcArg;
69 if(!cmSystemTools::FileIsDirectory(srcPath.c_str()))
71 std::string error = "given source \"";
72 error += srcArg;
73 error += "\" which is not an existing directory.";
74 this->SetError(error.c_str());
75 return false;
77 srcPath = cmSystemTools::CollapseFullPath(srcPath.c_str());
79 // Compute the full path to the binary directory.
80 std::string binPath;
81 if(binArg.empty())
83 // No binary directory was specified. If the source directory is
84 // not a subdirectory of the current directory then it is an
85 // error.
86 if(!cmSystemTools::FindLastString(srcPath.c_str(),
87 this->Makefile->GetCurrentDirectory()))
89 cmOStringStream e;
90 e << "not given a binary directory but the given source directory "
91 << "\"" << srcPath << "\" is not a subdirectory of \""
92 << this->Makefile->GetCurrentDirectory() << "\". "
93 << "When specifying an out-of-tree source a binary directory "
94 << "must be explicitly specified.";
95 this->SetError(e.str().c_str());
96 return false;
99 // Remove the CurrentDirectory from the srcPath and replace it
100 // with the CurrentOutputDirectory.
101 binPath = srcPath;
102 cmSystemTools::ReplaceString(binPath,
103 this->Makefile->GetCurrentDirectory(),
104 this->Makefile->GetCurrentOutputDirectory());
106 else
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()))
112 binPath = binArg;
114 else
116 binPath = this->Makefile->GetCurrentOutputDirectory();
117 binPath += "/";
118 binPath += binArg;
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);
127 return true;