| 261 | } |
| 262 | |
| 263 | void 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 |
no test coverage detected