This is only used when cross compiling. Instead of running the executable, two cache variables are created which will hold the results the executable would have produced. */
| 301 | the executable would have produced. |
| 302 | */ |
| 303 | void TryRunCommandImpl::DoNotRunExecutable( |
| 304 | std::string const& runArgs, cm::optional<std::string> const& srcFile, |
| 305 | std::string const& compileResultVariable, std::string* out, |
| 306 | std::string* stdOut, std::string* stdErr, bool stdOutErrRequired) |
| 307 | { |
| 308 | // copy the executable out of the CMakeFiles/ directory, so it is not |
| 309 | // removed at the end of try_run() and the user can run it manually |
| 310 | // on the target platform. |
| 311 | std::string copyDest = |
| 312 | cmStrCat(this->Makefile->GetHomeOutputDirectory(), "/CMakeFiles/", |
| 313 | cmSystemTools::GetFilenameWithoutExtension(this->OutputFile), '-', |
| 314 | this->RunResultVariable, |
| 315 | cmSystemTools::GetFilenameExtension(this->OutputFile)); |
| 316 | cmSystemTools::CopyFileAlways(this->OutputFile, copyDest); |
| 317 | |
| 318 | std::string resultFileName = |
| 319 | cmStrCat(this->Makefile->GetHomeOutputDirectory(), "/TryRunResults.cmake"); |
| 320 | |
| 321 | std::string detailsString = cmStrCat("For details see ", resultFileName); |
| 322 | |
| 323 | std::string internalRunOutputName = |
| 324 | this->RunResultVariable + "__TRYRUN_OUTPUT"; |
| 325 | std::string internalRunOutputStdOutName = |
| 326 | this->RunResultVariable + "__TRYRUN_OUTPUT_STDOUT"; |
| 327 | std::string internalRunOutputStdErrName = |
| 328 | this->RunResultVariable + "__TRYRUN_OUTPUT_STDERR"; |
| 329 | bool error = false; |
| 330 | |
| 331 | if (!this->Makefile->GetDefinition(this->RunResultVariable)) { |
| 332 | // if the variables doesn't exist, create it with a helpful error text |
| 333 | // and mark it as advanced |
| 334 | std::string comment = |
| 335 | cmStrCat("Run result of try_run(), indicates whether the executable " |
| 336 | "would have been able to run on its target platform.\n", |
| 337 | detailsString); |
| 338 | this->Makefile->AddCacheDefinition(this->RunResultVariable, |
| 339 | "PLEASE_FILL_OUT-FAILED_TO_RUN", |
| 340 | comment, cmStateEnums::STRING); |
| 341 | |
| 342 | cmState* state = this->Makefile->GetState(); |
| 343 | cmValue existingValue = state->GetCacheEntryValue(this->RunResultVariable); |
| 344 | if (existingValue) { |
| 345 | state->SetCacheEntryProperty(this->RunResultVariable, "ADVANCED", "1"); |
| 346 | } |
| 347 | |
| 348 | error = true; |
| 349 | } |
| 350 | |
| 351 | // is the output from the executable used ? |
| 352 | if (stdOutErrRequired) { |
| 353 | if (!this->Makefile->GetDefinition(internalRunOutputStdOutName)) { |
| 354 | // if the variables doesn't exist, create it with a helpful error text |
| 355 | // and mark it as advanced |
| 356 | std::string comment = cmStrCat( |
| 357 | "Output of try_run(), contains the text, which the executable " |
| 358 | "would have printed on stdout on its target platform.\n", |
| 359 | detailsString); |
| 360 |
no test coverage detected