1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmSourceGroupCommand.cxx,v $
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.20 $
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 "cmSourceGroupCommand.h"
19 inline std::vector
<std::string
> tokenize(const std::string
& str
,
20 const std::string
& sep
)
22 std::vector
<std::string
> tokens
;
23 std::string::size_type tokend
= 0;
27 std::string::size_type tokstart
=str
.find_first_not_of(sep
, tokend
);
28 if (tokstart
==std::string::npos
)
30 break; // no more tokens
32 tokend
=str
.find_first_of(sep
,tokstart
);
33 if (tokend
==std::string::npos
)
35 tokens
.push_back(str
.substr(tokstart
));
39 tokens
.push_back(str
.substr(tokstart
,tokend
-tokstart
));
41 } while (tokend
!=std::string::npos
);
50 // cmSourceGroupCommand
51 bool cmSourceGroupCommand
52 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
56 this->SetError("called with incorrect number of arguments");
60 std::string delimiter
= "\\";
61 if(this->Makefile
->GetDefinition("SOURCE_GROUP_DELIMITER"))
63 delimiter
= this->Makefile
->GetDefinition("SOURCE_GROUP_DELIMITER");
66 std::vector
<std::string
> folders
= tokenize(args
[0], delimiter
);
68 cmSourceGroup
* sg
= 0;
69 sg
= this->Makefile
->GetSourceGroup(folders
);
72 this->Makefile
->AddSourceGroup(folders
);
73 sg
= this->Makefile
->GetSourceGroup(folders
);
78 this->SetError("Could not create or find source group");
81 // If only two arguments are given, the pre-1.8 version of the
82 // command is being invoked.
83 if(args
.size() == 2 && args
[1] != "FILES")
85 sg
->SetGroupRegex(args
[1].c_str());
90 bool doingFiles
= false;
91 for(unsigned int i
=1; i
< args
.size(); ++i
)
93 if(args
[i
] == "REGULAR_EXPRESSION")
95 // Next argument must specify the regex.
99 sg
->SetGroupRegex(args
[i
].c_str());
103 this->SetError("REGULAR_EXPRESSION argument given without a regex.");
108 else if(args
[i
] == "FILES")
110 // Next arguments will specify files.
115 // Convert name to full path and add to the group's list.
116 std::string src
= args
[i
].c_str();
117 if(!cmSystemTools::FileIsFullPath(src
.c_str()))
119 src
= this->Makefile
->GetCurrentDirectory();
123 src
= cmSystemTools::CollapseFullPath(src
.c_str());
124 sg
->AddGroupFile(src
.c_str());
129 err
<< "Unknown argument \"" << args
[i
].c_str() << "\". "
130 << "Perhaps the FILES keyword is missing.\n";
131 this->SetError(err
.str().c_str());