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 "cmExecProgramCommand.h"
13 #include "cmSystemTools.h"
15 // cmExecProgramCommand
16 bool cmExecProgramCommand
17 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
21 this->SetError("called with incorrect number of arguments");
24 std::string arguments;
25 bool doingargs = false;
27 std::string output_variable;
28 bool haveoutput_variable = false;
29 std::string return_variable;
30 bool havereturn_variable = false;
31 for(size_t i=0; i < args.size(); ++i)
33 if(args[i] == "OUTPUT_VARIABLE")
37 havereturn_variable = false;
38 haveoutput_variable = true;
40 else if ( haveoutput_variable )
42 if ( output_variable.size() > 0 )
44 this->SetError("called with incorrect number of arguments");
47 output_variable = args[i];
48 haveoutput_variable = false;
51 else if(args[i] == "RETURN_VALUE")
55 haveoutput_variable = false;
56 havereturn_variable = true;
58 else if ( havereturn_variable )
60 if ( return_variable.size() > 0 )
62 this->SetError("called with incorrect number of arguments");
65 return_variable = args[i];
66 havereturn_variable = false;
69 else if(args[i] == "ARGS")
72 havereturn_variable = false;
73 haveoutput_variable = false;
87 command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str());
96 if(output_variable.size() > 0)
103 if(args.size() - count == 2)
105 cmSystemTools::MakeDirectory(args[1].c_str());
106 result = cmSystemTools::RunCommand(command.c_str(), output, retVal,
107 args[1].c_str(), verbose);
111 result = cmSystemTools::RunCommand(command.c_str(), output,
119 if ( output_variable.size() > 0 )
121 std::string::size_type first = output.find_first_not_of(" \n\t\r");
122 std::string::size_type last = output.find_last_not_of(" \n\t\r");
123 if(first == std::string::npos)
127 if(last == std::string::npos)
129 last = output.size()-1;
132 std::string coutput = std::string(output, first, last-first+1);
133 this->Makefile->AddDefinition(output_variable.c_str(), coutput.c_str());
136 if ( return_variable.size() > 0 )
139 sprintf(buffer, "%d", retVal);
140 this->Makefile->AddDefinition(return_variable.c_str(), buffer);