1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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 "cmSeparateArgumentsCommand.h"
14 // cmSeparateArgumentsCommand
15 bool cmSeparateArgumentsCommand
16 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
20 this->SetError("must be given at least one argument.");
26 enum Mode { ModeOld, ModeUnix, ModeWindows };
28 enum Doing { DoingNone, DoingVariable, DoingMode, DoingCommand };
29 Doing doing = DoingVariable;
30 for(unsigned int i=0; i < args.size(); ++i)
32 if(doing == DoingVariable)
37 else if(doing == DoingMode && args[i] == "UNIX_COMMAND")
42 else if(doing == DoingMode && args[i] == "WINDOWS_COMMAND")
47 else if(doing == DoingCommand)
55 e << "given unknown argument " << args[i];
56 this->SetError(e.str().c_str());
63 // Original space-replacement version of command.
64 if(const char* def = this->Makefile->GetDefinition(var.c_str()))
66 std::string value = def;
67 cmSystemTools::ReplaceString(value, " ", ";");
68 this->Makefile->AddDefinition(var.c_str(), value.c_str());
73 // Parse the command line.
74 std::vector<std::string> vec;
77 cmSystemTools::ParseUnixCommandLine(command.c_str(), vec);
79 else // if(mode == ModeWindows)
81 cmSystemTools::ParseWindowsCommandLine(command.c_str(), vec);
84 // Construct the result list value.
87 for(std::vector<std::string>::const_iterator vi = vec.begin();
88 vi != vec.end(); ++vi)
90 // Separate from the previous argument.
94 // Preserve semicolons.
95 for(std::string::const_iterator si = vi->begin();
96 si != vi->end(); ++si)
105 this->Makefile->AddDefinition(var.c_str(), value.c_str());