1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmAddSubDirectoryCommand.cxx,v $
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
&)
25 this->SetError("called with incorrect number of arguments");
30 std::string srcArg
= args
[0];
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();
38 for(;i
!= args
.end(); ++i
)
40 if(*i
== "EXCLUDE_FROM_ALL")
42 excludeFromAll
= true;
45 else if (!binArg
.size())
51 this->SetError("called with incorrect number of arguments");
56 // Compute the full path to the specified source directory.
57 // Interpret a relative path with respect to the current source directory.
59 if(cmSystemTools::FileIsFullPath(srcArg
.c_str()))
65 srcPath
= this->Makefile
->GetCurrentDirectory();
69 if(!cmSystemTools::FileIsDirectory(srcPath
.c_str()))
71 std::string error
= "given source \"";
73 error
+= "\" which is not an existing directory.";
74 this->SetError(error
.c_str());
77 srcPath
= cmSystemTools::CollapseFullPath(srcPath
.c_str());
79 // Compute the full path to the binary directory.
83 // No binary directory was specified. If the source directory is
84 // not a subdirectory of the current directory then it is an
86 if(!cmSystemTools::FindLastString(srcPath
.c_str(),
87 this->Makefile
->GetCurrentDirectory()))
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());
99 // Remove the CurrentDirectory from the srcPath and replace it
100 // with the CurrentOutputDirectory.
102 cmSystemTools::ReplaceString(binPath
,
103 this->Makefile
->GetCurrentDirectory(),
104 this->Makefile
->GetCurrentOutputDirectory());
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);