MCPcopy Create free account
hub / github.com/Kitware/CMake / RunExecutable

Method RunExecutable

Source/cmTryRunCommand.cxx:263–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

261}
262
263void TryRunCommandImpl::RunExecutable(std::string const& runArgs,
264 cm::optional<std::string> const& workDir,
265 std::string* out, std::string* stdOut,
266 std::string* stdErr)
267{
268 int retVal = -1;
269
270 std::string finalCommand;
271 std::string const& emulator =
272 this->Makefile->GetSafeDefinition("CMAKE_CROSSCOMPILING_EMULATOR");
273 if (!emulator.empty()) {
274 cmList emulatorWithArgs{ emulator };
275 finalCommand += cmStrCat(
276 cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0]), ' ',
277 cmWrap("\"", cmMakeRange(emulatorWithArgs).advance(1), "\"", " "), ' ');
278 }
279 finalCommand += cmSystemTools::ConvertToRunCommandPath(this->OutputFile);
280 if (!runArgs.empty()) {
281 finalCommand += runArgs;
282 }
283 bool worked = cmSystemTools::RunSingleCommand(
284 finalCommand, stdOut || stdErr ? stdOut : out,
285 stdOut || stdErr ? stdErr : out, &retVal,
286 workDir ? workDir->c_str() : nullptr, cmSystemTools::OUTPUT_NONE,
287 cmDuration::zero());
288 // set the run var
289 std::string retStr = worked ? std::to_string(retVal) : "FAILED_TO_RUN";
290 if (this->NoCache) {
291 this->Makefile->AddDefinition(this->RunResultVariable, retStr);
292 } else {
293 this->Makefile->AddCacheDefinition(this->RunResultVariable, retStr,
294 "Result of try_run()",
295 cmStateEnums::INTERNAL);
296 }
297}
298
299/* This is only used when cross compiling. Instead of running the
300 executable, two cache variables are created which will hold the results

Callers 1

TryRunCodeMethod · 0.95

Calls 9

cmWrapFunction · 0.85
cmMakeRangeFunction · 0.85
to_stringFunction · 0.85
c_strMethod · 0.80
cmStrCatFunction · 0.70
emptyMethod · 0.45
advanceMethod · 0.45
AddDefinitionMethod · 0.45
AddCacheDefinitionMethod · 0.45

Tested by

no test coverage detected