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

Method DoNotRunExecutable

Source/cmTryRunCommand.cxx:303–537  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

301 the executable would have produced.
302*/
303void 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

Callers 1

TryRunCodeMethod · 0.95

Calls 10

c_strMethod · 0.80
FormatListFileStackMethod · 0.80
cmStrCatFunction · 0.70
ErrorClass · 0.70
GetDefinitionMethod · 0.45
AddCacheDefinitionMethod · 0.45
GetStateMethod · 0.45
GetCacheEntryValueMethod · 0.45
SetCacheEntryPropertyMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected