1
1
/*=========================================================================
3
Program: Insight Segmentation & Registration Toolkit
3
Program: CMake - Cross-Platform Makefile Generator
4
4
Module: $RCSfile: cmExecProgramCommand.cxx,v $
6
Date: $Date: 2001/09/20 19:08:22 $
7
Version: $Revision: 1.3 $
9
Copyright (c) 2001 Insight Consortium
12
Redistribution and use in source and binary forms, with or without
13
modification, are permitted provided that the following conditions are met:
15
* Redistributions of source code must retain the above copyright notice,
16
this list of conditions and the following disclaimer.
18
* Redistributions in binary form must reproduce the above copyright notice,
19
this list of conditions and the following disclaimer in the documentation
20
and/or other materials provided with the distribution.
22
* The name of the Insight Consortium, nor the names of any consortium members,
23
nor of any contributors, may be used to endorse or promote products derived
24
from this software without specific prior written permission.
26
* Modified source versions must be plainly marked as such, and must not be
27
misrepresented as being the original software.
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
30
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
33
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6
Date: $Date: 2004/07/07 21:09:55 $
7
Version: $Revision: 1.18.8.1 $
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.
40
16
=========================================================================*/
41
17
#include "cmExecProgramCommand.h"
42
18
#include "cmSystemTools.h"
44
20
// cmExecProgramCommand
45
bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
21
bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
47
std::vector<std::string> args = argsIn;
48
23
if(args.size() < 1 )
50
25
this->SetError("called with incorrect number of arguments");
28
std::string arguments;
29
bool doingargs = false;
31
std::string output_variable;
32
bool haveoutput_variable = false;
33
std::string return_variable;
34
bool havereturn_variable = false;
35
for(size_t i=0; i < args.size(); ++i)
37
if(args[i] == "OUTPUT_VARIABLE")
41
havereturn_variable = false;
42
haveoutput_variable = true;
44
else if ( haveoutput_variable )
46
if ( output_variable.size() > 0 )
48
this->SetError("called with incorrect number of arguments");
51
output_variable = args[i];
52
haveoutput_variable = false;
55
else if(args[i] == "RETURN_VALUE")
59
haveoutput_variable = false;
60
havereturn_variable = true;
62
else if ( havereturn_variable )
64
if ( return_variable.size() > 0 )
66
this->SetError("called with incorrect number of arguments");
69
return_variable = args[i];
70
havereturn_variable = false;
73
else if(args[i] == "ARGS")
76
havereturn_variable = false;
77
haveoutput_variable = false;
91
command = cmSystemTools::ConvertToRunCommandPath(args[0].c_str());
100
if(output_variable.size() > 0)
53
105
std::string output;
54
m_Makefile->ExpandVariablesInString(args[0]);
55
m_Makefile->ExpandVariablesInString(args[1]);
107
if(args.size() - count == 2)
58
109
cmSystemTools::MakeDirectory(args[1].c_str());
61
command += args[1].c_str();
63
command += args[0].c_str();
64
cmSystemTools::RunCommand(command.c_str(), output);
110
result = cmSystemTools::RunCommand(command.c_str(), output, retVal,
111
args[1].c_str(), verbose);
68
cmSystemTools::RunCommand(args[0].c_str(), output);
115
result = cmSystemTools::RunCommand(command.c_str(), output, retVal, 0, verbose);
122
if ( output_variable.size() > 0 )
124
std::string::size_type first = output.find_first_not_of(" \n\t\r");
125
std::string::size_type last = output.find_last_not_of(" \n\t\r");
126
if(first == std::string::npos)
130
if(last == std::string::npos)
132
last = output.size()-1;
135
std::string coutput = std::string(output, first, last-first+1);
136
m_Makefile->AddDefinition(output_variable.c_str(), coutput.c_str());
139
if ( return_variable.size() > 0 )
142
sprintf(buffer, "%d", retVal);
143
m_Makefile->AddDefinition(return_variable.c_str(), buffer);