1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmExecProgramCommand.cxx,v $
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.23 $
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 "cmExecProgramCommand.h"
18 #include "cmSystemTools.h"
20 // cmExecProgramCommand
21 bool cmExecProgramCommand
22 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
26 this->SetError("called with incorrect number of arguments");
29 std::string arguments
;
30 bool doingargs
= false;
32 std::string output_variable
;
33 bool haveoutput_variable
= false;
34 std::string return_variable
;
35 bool havereturn_variable
= false;
36 for(size_t i
=0; i
< args
.size(); ++i
)
38 if(args
[i
] == "OUTPUT_VARIABLE")
42 havereturn_variable
= false;
43 haveoutput_variable
= true;
45 else if ( haveoutput_variable
)
47 if ( output_variable
.size() > 0 )
49 this->SetError("called with incorrect number of arguments");
52 output_variable
= args
[i
];
53 haveoutput_variable
= false;
56 else if(args
[i
] == "RETURN_VALUE")
60 haveoutput_variable
= false;
61 havereturn_variable
= true;
63 else if ( havereturn_variable
)
65 if ( return_variable
.size() > 0 )
67 this->SetError("called with incorrect number of arguments");
70 return_variable
= args
[i
];
71 havereturn_variable
= false;
74 else if(args
[i
] == "ARGS")
77 havereturn_variable
= false;
78 haveoutput_variable
= false;
92 command
= cmSystemTools::ConvertToRunCommandPath(args
[0].c_str());
101 if(output_variable
.size() > 0)
108 if(args
.size() - count
== 2)
110 cmSystemTools::MakeDirectory(args
[1].c_str());
111 result
= cmSystemTools::RunCommand(command
.c_str(), output
, retVal
,
112 args
[1].c_str(), verbose
);
116 result
= cmSystemTools::RunCommand(command
.c_str(), output
,
124 if ( output_variable
.size() > 0 )
126 std::string::size_type first
= output
.find_first_not_of(" \n\t\r");
127 std::string::size_type last
= output
.find_last_not_of(" \n\t\r");
128 if(first
== std::string::npos
)
132 if(last
== std::string::npos
)
134 last
= output
.size()-1;
137 std::string coutput
= std::string(output
, first
, last
-first
+1);
138 this->Makefile
->AddDefinition(output_variable
.c_str(), coutput
.c_str());
141 if ( return_variable
.size() > 0 )
144 sprintf(buffer
, "%d", retVal
);
145 this->Makefile
->AddDefinition(return_variable
.c_str(), buffer
);