packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmSourceGroupCommand.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 "cmSourceGroupCommand.h"
13
14 // cmSourceGroupCommand
15 bool cmSourceGroupCommand
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
24   std::string delimiter = "\\";
25   if(this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"))
26     {
27     delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
28     }
29
30   std::vector<std::string> folders =
31     cmSystemTools::tokenize(args[0], delimiter);
32
33   cmSourceGroup* sg = 0;
34   sg = this->Makefile->GetSourceGroup(folders);
35   if(!sg)
36     {
37     this->Makefile->AddSourceGroup(folders);
38     sg = this->Makefile->GetSourceGroup(folders);
39     }
40
41   if(!sg)
42     {
43     this->SetError("Could not create or find source group");
44     return false;
45     }
46   // If only two arguments are given, the pre-1.8 version of the
47   // command is being invoked.
48   if(args.size() == 2  && args[1] != "FILES")
49     {
50     sg->SetGroupRegex(args[1].c_str());
51     return true;
52     }
53
54   // Process arguments.
55   bool doingFiles = false;
56   for(unsigned int i=1; i < args.size(); ++i)
57     {
58     if(args[i] == "REGULAR_EXPRESSION")
59       {
60       // Next argument must specify the regex.
61       if(i+1 < args.size())
62         {
63         ++i;
64         sg->SetGroupRegex(args[i].c_str());
65         }
66       else
67         {
68         this->SetError("REGULAR_EXPRESSION argument given without a regex.");
69         return false;
70         }
71       doingFiles = false;
72       }
73     else if(args[i] == "FILES")
74       {
75       // Next arguments will specify files.
76       doingFiles = true;
77       }
78     else if(doingFiles)
79       {
80       // Convert name to full path and add to the group's list.
81       std::string src = args[i].c_str();
82       if(!cmSystemTools::FileIsFullPath(src.c_str()))
83         {
84         src = this->Makefile->GetCurrentDirectory();
85         src += "/";
86         src += args[i];
87         }
88       src = cmSystemTools::CollapseFullPath(src.c_str());
89       sg->AddGroupFile(src.c_str());
90       }
91     else
92       {
93       cmOStringStream err;
94       err << "Unknown argument \"" << args[i].c_str() << "\".  "
95           << "Perhaps the FILES keyword is missing.\n";
96       this->SetError(err.str().c_str());
97       return false;
98       }
99     }
100
101   return true;
102 }