Add option of storing output to the variable
This commit is contained in:
parent
930bed0f71
commit
c41c7a6a9a
|
@ -28,9 +28,28 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
|
||||||
std::string arguments;
|
std::string arguments;
|
||||||
bool doingargs = false;
|
bool doingargs = false;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
std::string variable;
|
||||||
|
bool havevariable = false;
|
||||||
|
std::string e_command;
|
||||||
for(size_t i=0; i < args.size(); ++i)
|
for(size_t i=0; i < args.size(); ++i)
|
||||||
{
|
{
|
||||||
if(doingargs)
|
if(args[i] == "OUTPUT_VARIABLE")
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
doingargs = false;
|
||||||
|
havevariable = true;
|
||||||
|
}
|
||||||
|
else if ( havevariable )
|
||||||
|
{
|
||||||
|
if ( variable.size() > 0 )
|
||||||
|
{
|
||||||
|
this->SetError("called with incorrect number of arguments");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
variable = args[i];
|
||||||
|
count ++;
|
||||||
|
}
|
||||||
|
else if(doingargs)
|
||||||
{
|
{
|
||||||
arguments += args[i];
|
arguments += args[i];
|
||||||
arguments += " ";
|
arguments += " ";
|
||||||
|
@ -65,6 +84,15 @@ bool cmExecProgramCommand::InitialPass(std::vector<std::string> const& args)
|
||||||
{
|
{
|
||||||
cmSystemTools::RunCommand(command.c_str(), output);
|
cmSystemTools::RunCommand(command.c_str(), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( variable.size() > 0 )
|
||||||
|
{
|
||||||
|
std::string::size_type first = output.find_first_not_of(" \n\t\r");
|
||||||
|
std::string::size_type last = output.find_last_not_of(" \n\t\r");
|
||||||
|
std::string coutput = std::string(output, first, last);
|
||||||
|
m_Makefile->AddDefinition(variable.c_str(), coutput.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
virtual const char* GetFullDocumentation()
|
virtual const char* GetFullDocumentation()
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
"EXEC_PROGRAM(Executable [Directory to run in] [ARGS arguments to executable])"
|
"EXEC_PROGRAM(Executable [Directory to run in] [ARGS arguments to executable] [OUTPUT_VARIABLE var])"
|
||||||
"The executable is run in the optionally specified Directory. The executable "
|
"The executable is run in the optionally specified Directory. The executable "
|
||||||
"can include arguments if it is double quoted, but it is better to use the "
|
"can include arguments if it is double quoted, but it is better to use the "
|
||||||
"optional ARGS argument to specify arguments to the program. This is because "
|
"optional ARGS argument to specify arguments to the program. This is because "
|
||||||
|
|
Loading…
Reference in New Issue