Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmSubdirCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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 "cmSubdirCommand.h"
13
14 // cmSubdirCommand
15 bool cmSubdirCommand
16 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
17 {
18   if(args.size() < 1 )
19     {
20     this->SetError("called with incorrect number of arguments");
21     return false;
22     }
23   bool res = true;
24   bool excludeFromAll = false;
25   bool preorder = false;
26
27   for(std::vector<std::string>::const_iterator i = args.begin();
28       i != args.end(); ++i)
29     {
30     if(*i == "EXCLUDE_FROM_ALL")
31       {
32       excludeFromAll = true;
33       continue;
34       }
35     if(*i == "PREORDER")
36       {
37       preorder = true;
38       continue;
39       }
40
41     // if they specified a relative path then compute the full
42     std::string srcPath =
43       std::string(this->Makefile->GetCurrentDirectory()) +
44         "/" + i->c_str();
45     if (cmSystemTools::FileIsDirectory(srcPath.c_str()))
46       {
47       std::string binPath =
48         std::string(this->Makefile->GetCurrentOutputDirectory()) +
49         "/" + i->c_str();
50       this->Makefile->AddSubDirectory(srcPath.c_str(), binPath.c_str(),
51                                   excludeFromAll, preorder, false);
52       }
53     // otherwise it is a full path
54     else if ( cmSystemTools::FileIsDirectory(i->c_str()) )
55       {
56       // we must compute the binPath from the srcPath, we just take the last
57       // element from the source path and use that
58       std::string binPath =
59         std::string(this->Makefile->GetCurrentOutputDirectory()) +
60         "/" + cmSystemTools::GetFilenameName(i->c_str());
61       this->Makefile->AddSubDirectory(i->c_str(), binPath.c_str(),
62                                   excludeFromAll, preorder, false);
63       }
64     else
65       {
66       std::string error = "Incorrect SUBDIRS command. Directory: ";
67       error += *i + " does not exist.";
68       this->SetError(error.c_str());
69       res = false;
70       }
71     }
72   return res;
73 }
74