2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2002-09-19 17:48:39 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2002-09-19 17:48:39 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2002-09-19 17:48:39 +04:00
|
|
|
#include "cmTryRunCommand.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2002-09-19 17:48:39 +04:00
|
|
|
#include "cmTryCompileCommand.h"
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2002-09-19 17:48:39 +04:00
|
|
|
|
ENH: merge CMake-CrossCompileBasic to HEAD
-add a RESULT_VARIABLE to INCLUDE()
-add CMAKE_TOOLCHAIN_FILE for specifiying your (potentially crosscompiling) toolchain
-have TRY_RUN() complain if you try to use it in crosscompiling mode (which were compiled but cannot run on this system)
-use CMAKE_EXECUTABLE_SUFFIX in TRY_RUN(), probably TRY_RUN won't be able to
run the executables if they have a different suffix because they are
probably crosscompiled, but nevertheless it should be able to find them
-make several cmake variables presettable by the user: CMAKE_C/CXX_COMPILER, CMAKE_C/CXX_OUTPUT_EXTENSION, CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_INFO_FILE
-support prefix for GNU toolchains (arm-elf-gcc, arm-elf-ar, arm-elf-strip etc.)
-move ranlib on OSX from the file command to a command in executed in cmake_install.cmake
-add support for stripping during install in cmake_install.cmake
-split out cl.cmake from Windows-cl.cmake, first (very incomplete) step to support MS crosscompiling tools
-remove stdio.h from the simple C program which checks if the compiler works, since this may not exist for some embedded platforms
-create a new CMakeFindBinUtils.cmake which collects the search fro ar, ranlib, strip, ld, link, install_name_tool and other tools like these
-add support for CMAKE_FIND_ROOT_PATH for all FIND_XXX commands, which is a
list of directories which will be prepended to all search directories, right
now as a cmake variable, turning it into a global cmake property may need
some more work
-remove cmTestTestHandler::TryExecutable(), it's unused
-split cmFileCommand::HandleInstall() into slightly smaller functions
Alex
2007-05-17 21:20:44 +04:00
|
|
|
// cmTryRunCommand
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv,
|
|
|
|
cmExecutionStatus&)
|
2002-09-19 17:48:39 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argv.size() < 4) {
|
2002-09-19 17:48:39 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2002-09-19 17:48:39 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Makefile->GetCMakeInstance()->GetWorkingMode() ==
|
|
|
|
cmake::FIND_PACKAGE_MODE) {
|
|
|
|
this->Makefile->IssueMessage(
|
|
|
|
cmake::FATAL_ERROR,
|
|
|
|
"The TRY_RUN() command is not supported in --find-package mode.");
|
2011-09-15 18:28:35 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-09-15 18:28:35 +04:00
|
|
|
|
2008-01-23 18:28:26 +03:00
|
|
|
// build an arg list for TryCompile and extract the runArgs,
|
2002-09-19 17:48:39 +04:00
|
|
|
std::vector<std::string> tryCompile;
|
2007-06-01 19:16:29 +04:00
|
|
|
|
|
|
|
this->CompileResultVariable = "";
|
|
|
|
this->RunResultVariable = "";
|
|
|
|
this->OutputVariable = "";
|
|
|
|
this->RunOutputVariable = "";
|
|
|
|
this->CompileOutputVariable = "";
|
|
|
|
|
2002-09-19 17:48:39 +04:00
|
|
|
std::string runArgs;
|
2002-09-20 16:09:03 +04:00
|
|
|
unsigned int i;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (i = 1; i < argv.size(); ++i) {
|
|
|
|
if (argv[i] == "ARGS") {
|
2002-09-19 17:48:39 +04:00
|
|
|
++i;
|
|
|
|
while (i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" &&
|
2016-05-16 17:34:04 +03:00
|
|
|
argv[i] != "CMAKE_FLAGS" && argv[i] != "LINK_LIBRARIES") {
|
2002-09-19 17:48:39 +04:00
|
|
|
runArgs += " ";
|
|
|
|
runArgs += argv[i];
|
|
|
|
++i;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (i < argv.size()) {
|
2002-09-19 17:48:39 +04:00
|
|
|
tryCompile.push_back(argv[i]);
|
2011-09-15 18:20:33 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
if (argv[i] == "OUTPUT_VARIABLE") {
|
|
|
|
if (argv.size() <= (i + 1)) {
|
2004-09-22 22:42:05 +04:00
|
|
|
cmSystemTools::Error(
|
2006-03-10 21:54:57 +03:00
|
|
|
"OUTPUT_VARIABLE specified but there is no variable");
|
2004-09-22 22:42:05 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
i++;
|
|
|
|
this->OutputVariable = argv[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (argv[i] == "RUN_OUTPUT_VARIABLE") {
|
|
|
|
if (argv.size() <= (i + 1)) {
|
2007-06-01 19:16:29 +04:00
|
|
|
cmSystemTools::Error(
|
|
|
|
"RUN_OUTPUT_VARIABLE specified but there is no variable");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
i++;
|
|
|
|
this->RunOutputVariable = argv[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (argv[i] == "COMPILE_OUTPUT_VARIABLE") {
|
|
|
|
if (argv.size() <= (i + 1)) {
|
2007-06-01 19:16:29 +04:00
|
|
|
cmSystemTools::Error(
|
|
|
|
"COMPILE_OUTPUT_VARIABLE specified but there is no variable");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
i++;
|
|
|
|
this->CompileOutputVariable = argv[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-06-01 19:16:29 +04:00
|
|
|
tryCompile.push_back(argv[i]);
|
2002-09-19 17:48:39 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
|
|
|
// although they could be used together, don't allow it, because
|
|
|
|
// using OUTPUT_VARIABLE makes crosscompiling harder
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->OutputVariable.size() && (!this->RunOutputVariable.empty() ||
|
|
|
|
!this->CompileOutputVariable.empty())) {
|
2007-06-01 19:16:29 +04:00
|
|
|
cmSystemTools::Error(
|
|
|
|
"You cannot use OUTPUT_VARIABLE together with COMPILE_OUTPUT_VARIABLE "
|
|
|
|
"or RUN_OUTPUT_VARIABLE. Please use only COMPILE_OUTPUT_VARIABLE and/or "
|
|
|
|
"RUN_OUTPUT_VARIABLE.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
|
|
|
bool captureRunOutput = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->OutputVariable.empty()) {
|
2007-06-01 19:16:29 +04:00
|
|
|
captureRunOutput = true;
|
|
|
|
tryCompile.push_back("OUTPUT_VARIABLE");
|
|
|
|
tryCompile.push_back(this->OutputVariable);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!this->CompileOutputVariable.empty()) {
|
2007-06-01 19:16:29 +04:00
|
|
|
tryCompile.push_back("OUTPUT_VARIABLE");
|
|
|
|
tryCompile.push_back(this->CompileOutputVariable);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!this->RunOutputVariable.empty()) {
|
2007-06-01 19:16:29 +04:00
|
|
|
captureRunOutput = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
|
|
|
this->RunResultVariable = argv[0];
|
|
|
|
this->CompileResultVariable = argv[1];
|
|
|
|
|
2002-09-19 17:48:39 +04:00
|
|
|
// do the try compile
|
2016-02-19 21:23:48 +03:00
|
|
|
int res = this->TryCompileCode(tryCompile, true);
|
2007-05-24 16:56:14 +04:00
|
|
|
|
2002-09-19 17:48:39 +04:00
|
|
|
// now try running the command if it compiled
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!res) {
|
|
|
|
if (this->OutputFile.empty()) {
|
2007-05-24 19:27:51 +04:00
|
|
|
cmSystemTools::Error(this->FindErrorMessage.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-06-01 19:16:29 +04:00
|
|
|
// "run" it and capture the output
|
|
|
|
std::string runOutputContents;
|
2015-03-28 21:18:38 +03:00
|
|
|
if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING") &&
|
2016-05-16 17:34:04 +03:00
|
|
|
!this->Makefile->IsDefinitionSet("CMAKE_CROSSCOMPILING_EMULATOR")) {
|
2016-06-27 23:44:16 +03:00
|
|
|
this->DoNotRunExecutable(runArgs, argv[3], captureRunOutput
|
|
|
|
? &runOutputContents
|
|
|
|
: CM_NULLPTR);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-06-01 19:16:29 +04:00
|
|
|
this->RunExecutable(runArgs, &runOutputContents);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
|
|
|
// now put the output into the variables
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->RunOutputVariable.empty()) {
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(this->RunOutputVariable,
|
2007-06-01 19:16:29 +04:00
|
|
|
runOutputContents.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->OutputVariable.empty()) {
|
2007-05-24 19:27:51 +04:00
|
|
|
// if the TryCompileCore saved output in this outputVariable then
|
|
|
|
// prepend that output to this output
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* compileOutput =
|
|
|
|
this->Makefile->GetDefinition(this->OutputVariable);
|
|
|
|
if (compileOutput) {
|
2007-06-01 19:16:29 +04:00
|
|
|
runOutputContents = std::string(compileOutput) + runOutputContents;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(this->OutputVariable,
|
2007-06-01 19:16:29 +04:00
|
|
|
runOutputContents.c_str());
|
2002-09-19 17:48:39 +04:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
2007-05-24 16:56:14 +04:00
|
|
|
// if we created a directory etc, then cleanup after ourselves
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Makefile->GetCMakeInstance()->GetDebugTryCompile()) {
|
2007-05-24 19:27:51 +04:00
|
|
|
this->CleanupFiles(this->BinaryDirectory.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2002-09-19 17:48:39 +04:00
|
|
|
return true;
|
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
|
|
|
void cmTryRunCommand::RunExecutable(const std::string& runArgs,
|
|
|
|
std::string* out)
|
|
|
|
{
|
|
|
|
int retVal = -1;
|
2015-03-28 21:18:38 +03:00
|
|
|
|
|
|
|
std::string finalCommand;
|
|
|
|
const std::string emulator =
|
2016-05-16 17:34:04 +03:00
|
|
|
this->Makefile->GetSafeDefinition("CMAKE_CROSSCOMPILING_EMULATOR");
|
|
|
|
if (!emulator.empty()) {
|
2015-03-28 21:18:38 +03:00
|
|
|
std::vector<std::string> emulatorWithArgs;
|
|
|
|
cmSystemTools::ExpandListArgument(emulator, emulatorWithArgs);
|
2016-05-16 17:34:04 +03:00
|
|
|
finalCommand +=
|
|
|
|
cmSystemTools::ConvertToRunCommandPath(emulatorWithArgs[0].c_str());
|
2015-03-28 21:18:38 +03:00
|
|
|
finalCommand += " ";
|
|
|
|
for (std::vector<std::string>::const_iterator ei =
|
2016-05-16 17:34:04 +03:00
|
|
|
emulatorWithArgs.begin() + 1;
|
|
|
|
ei != emulatorWithArgs.end(); ++ei) {
|
2015-03-28 21:18:38 +03:00
|
|
|
finalCommand += "\"";
|
|
|
|
finalCommand += *ei;
|
|
|
|
finalCommand += "\"";
|
|
|
|
finalCommand += " ";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
finalCommand +=
|
|
|
|
cmSystemTools::ConvertToRunCommandPath(this->OutputFile.c_str());
|
|
|
|
if (!runArgs.empty()) {
|
2007-06-01 19:16:29 +04:00
|
|
|
finalCommand += runArgs;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
int timeout = 0;
|
2016-06-27 23:44:16 +03:00
|
|
|
bool worked = cmSystemTools::RunSingleCommand(
|
|
|
|
finalCommand.c_str(), out, out, &retVal, CM_NULLPTR,
|
|
|
|
cmSystemTools::OUTPUT_NONE, timeout);
|
2007-06-01 19:16:29 +04:00
|
|
|
// set the run var
|
|
|
|
char retChar[1000];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (worked) {
|
2007-06-01 19:16:29 +04:00
|
|
|
sprintf(retChar, "%i", retVal);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2007-06-01 19:16:29 +04:00
|
|
|
strcpy(retChar, "FAILED_TO_RUN");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddCacheDefinition(this->RunResultVariable, retChar,
|
2016-05-16 17:34:04 +03:00
|
|
|
"Result of TRY_RUN", cmState::INTERNAL);
|
2007-06-01 19:16:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This is only used when cross compiling. Instead of running the
|
|
|
|
executable, two cache variables are created which will hold the results
|
2011-09-15 18:20:33 +04:00
|
|
|
the executable would have produced.
|
2007-06-01 19:16:29 +04:00
|
|
|
*/
|
2011-09-15 18:20:33 +04:00
|
|
|
void cmTryRunCommand::DoNotRunExecutable(const std::string& runArgs,
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& srcFile,
|
|
|
|
std::string* out)
|
2007-06-01 19:16:29 +04:00
|
|
|
{
|
2007-07-31 22:52:01 +04:00
|
|
|
// copy the executable out of the CMakeFiles/ directory, so it is not
|
|
|
|
// removed at the end of TRY_RUN and the user can run it manually
|
|
|
|
// on the target platform.
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string copyDest = this->Makefile->GetHomeOutputDirectory();
|
2007-09-17 18:53:20 +04:00
|
|
|
copyDest += cmake::GetCMakeFilesDirectory();
|
2007-07-31 22:52:01 +04:00
|
|
|
copyDest += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
copyDest += cmSystemTools::GetFilenameWithoutExtension(this->OutputFile);
|
2007-07-31 22:52:01 +04:00
|
|
|
copyDest += "-";
|
|
|
|
copyDest += this->RunResultVariable;
|
2014-03-11 03:04:11 +04:00
|
|
|
copyDest += cmSystemTools::GetFilenameExtension(this->OutputFile);
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::CopyFileAlways(this->OutputFile, copyDest);
|
2007-07-31 22:52:01 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string resultFileName = this->Makefile->GetHomeOutputDirectory();
|
2007-07-31 22:52:01 +04:00
|
|
|
resultFileName += "/TryRunResults.cmake";
|
|
|
|
|
|
|
|
std::string detailsString = "For details see ";
|
|
|
|
detailsString += resultFileName;
|
2007-06-01 19:16:29 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string internalRunOutputName =
|
|
|
|
this->RunResultVariable + "__TRYRUN_OUTPUT";
|
2007-06-01 19:16:29 +04:00
|
|
|
bool error = false;
|
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
if (this->Makefile->GetDefinition(this->RunResultVariable) == CM_NULLPTR) {
|
2007-06-01 19:16:29 +04:00
|
|
|
// if the variables doesn't exist, create it with a helpful error text
|
|
|
|
// and mark it as advanced
|
|
|
|
std::string comment;
|
2007-07-31 22:52:01 +04:00
|
|
|
comment += "Run result of TRY_RUN(), indicates whether the executable "
|
|
|
|
"would have been able to run on its target platform.\n";
|
|
|
|
comment += detailsString;
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddCacheDefinition(this->RunResultVariable,
|
2007-06-01 19:16:29 +04:00
|
|
|
"PLEASE_FILL_OUT-FAILED_TO_RUN",
|
2016-05-16 17:34:04 +03:00
|
|
|
comment.c_str(), cmState::STRING);
|
2007-06-01 19:16:29 +04:00
|
|
|
|
2015-04-06 11:52:45 +03:00
|
|
|
cmState* state = this->Makefile->GetState();
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* existingValue =
|
|
|
|
state->GetCacheEntryValue(this->RunResultVariable);
|
|
|
|
if (existingValue) {
|
2015-04-06 11:52:45 +03:00
|
|
|
state->SetCacheEntryProperty(this->RunResultVariable, "ADVANCED", "1");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
|
|
|
error = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
2007-07-23 18:47:23 +04:00
|
|
|
// is the output from the executable used ?
|
2016-06-27 23:44:16 +03:00
|
|
|
if (out != CM_NULLPTR) {
|
|
|
|
if (this->Makefile->GetDefinition(internalRunOutputName) == CM_NULLPTR) {
|
2007-06-01 19:16:29 +04:00
|
|
|
// if the variables doesn't exist, create it with a helpful error text
|
|
|
|
// and mark it as advanced
|
|
|
|
std::string comment;
|
2016-05-16 17:34:04 +03:00
|
|
|
comment +=
|
|
|
|
"Output of TRY_RUN(), contains the text, which the executable "
|
|
|
|
"would have printed on stdout and stderr on its target platform.\n";
|
2007-07-31 22:52:01 +04:00
|
|
|
comment += detailsString;
|
2007-06-01 19:16:29 +04:00
|
|
|
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddCacheDefinition(internalRunOutputName,
|
2007-06-01 19:16:29 +04:00
|
|
|
"PLEASE_FILL_OUT-NOTFOUND",
|
2016-05-16 17:34:04 +03:00
|
|
|
comment.c_str(), cmState::STRING);
|
2015-04-06 11:52:45 +03:00
|
|
|
cmState* state = this->Makefile->GetState();
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* existing = state->GetCacheEntryValue(internalRunOutputName);
|
|
|
|
if (existing) {
|
|
|
|
state->SetCacheEntryProperty(internalRunOutputName, "ADVANCED", "1");
|
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
|
|
|
error = true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (error) {
|
2007-07-23 21:13:29 +04:00
|
|
|
static bool firstTryRun = true;
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ofstream file(resultFileName.c_str(),
|
2016-05-16 17:34:04 +03:00
|
|
|
firstTryRun ? std::ios::out : std::ios::app);
|
|
|
|
if (file) {
|
|
|
|
if (firstTryRun) {
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2007-07-23 21:13:29 +04:00
|
|
|
file << "# This file was generated by CMake because it detected "
|
|
|
|
"TRY_RUN() commands\n"
|
|
|
|
"# in crosscompiling mode. It will be overwritten by the next "
|
|
|
|
"CMake run.\n"
|
|
|
|
"# Copy it to a safe location, set the variables to "
|
|
|
|
"appropriate values\n"
|
|
|
|
"# and use it then to preset the CMake cache (using -C).\n\n";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-23 21:13:29 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string comment = "\n";
|
2007-07-23 21:13:29 +04:00
|
|
|
comment += this->RunResultVariable;
|
2007-08-01 19:59:51 +04:00
|
|
|
comment += "\n indicates whether the executable would have been able "
|
2007-08-02 01:10:22 +04:00
|
|
|
"to run on its\n"
|
|
|
|
" target platform. If so, set ";
|
2007-07-31 22:52:01 +04:00
|
|
|
comment += this->RunResultVariable;
|
|
|
|
comment += " to\n"
|
2007-08-01 19:59:51 +04:00
|
|
|
" the exit code (in many cases 0 for success), otherwise "
|
2007-07-31 22:52:01 +04:00
|
|
|
"enter \"FAILED_TO_RUN\".\n";
|
2016-06-27 23:44:16 +03:00
|
|
|
if (out != CM_NULLPTR) {
|
2007-07-23 21:13:29 +04:00
|
|
|
comment += internalRunOutputName;
|
2016-05-16 17:34:04 +03:00
|
|
|
comment +=
|
|
|
|
"\n contains the text the executable "
|
|
|
|
"would have printed on stdout and stderr.\n"
|
|
|
|
" If the executable would not have been able to run, set ";
|
2007-07-31 22:52:01 +04:00
|
|
|
comment += internalRunOutputName;
|
|
|
|
comment += " empty.\n"
|
2007-08-01 19:59:51 +04:00
|
|
|
" Otherwise check if the output is evaluated by the "
|
2007-07-31 22:52:01 +04:00
|
|
|
"calling CMake code. If so,\n"
|
2007-08-01 19:59:51 +04:00
|
|
|
" check what the source file would have printed when "
|
|
|
|
"called with the given arguments.\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-31 22:52:01 +04:00
|
|
|
comment += "The ";
|
|
|
|
comment += this->CompileResultVariable;
|
|
|
|
comment += " variable holds the build result for this TRY_RUN().\n\n"
|
|
|
|
"Source file : ";
|
|
|
|
comment += srcFile + "\n";
|
|
|
|
comment += "Executable : ";
|
|
|
|
comment += copyDest + "\n";
|
|
|
|
comment += "Run arguments : ";
|
|
|
|
comment += runArgs;
|
|
|
|
comment += "\n";
|
2015-05-16 08:30:33 +03:00
|
|
|
comment += " Called from: " + this->Makefile->FormatListFileStack();
|
2007-07-23 21:13:29 +04:00
|
|
|
cmsys::SystemTools::ReplaceString(comment, "\n", "\n# ");
|
|
|
|
file << comment << "\n\n";
|
|
|
|
|
2013-08-22 13:30:19 +04:00
|
|
|
file << "set( " << this->RunResultVariable << " \n \""
|
2014-03-11 03:04:11 +04:00
|
|
|
<< this->Makefile->GetDefinition(this->RunResultVariable)
|
2007-07-30 22:46:57 +04:00
|
|
|
<< "\"\n CACHE STRING \"Result from TRY_RUN\" FORCE)\n\n";
|
2007-07-23 21:13:29 +04:00
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
if (out != CM_NULLPTR) {
|
2013-08-22 13:30:19 +04:00
|
|
|
file << "set( " << internalRunOutputName << " \n \""
|
2014-03-11 03:04:11 +04:00
|
|
|
<< this->Makefile->GetDefinition(internalRunOutputName)
|
2007-07-30 22:46:57 +04:00
|
|
|
<< "\"\n CACHE STRING \"Output from TRY_RUN\" FORCE)\n\n";
|
2007-07-23 18:47:23 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
file.close();
|
|
|
|
}
|
2007-07-23 21:13:29 +04:00
|
|
|
firstTryRun = false;
|
2007-07-23 18:47:23 +04:00
|
|
|
|
2007-06-01 19:16:29 +04:00
|
|
|
std::string errorMessage = "TRY_RUN() invoked in cross-compiling mode, "
|
|
|
|
"please set the following cache variables "
|
2010-07-02 18:58:00 +04:00
|
|
|
"appropriately:\n";
|
2007-06-01 19:16:29 +04:00
|
|
|
errorMessage += " " + this->RunResultVariable + " (advanced)\n";
|
2016-06-27 23:44:16 +03:00
|
|
|
if (out != CM_NULLPTR) {
|
2007-06-01 19:16:29 +04:00
|
|
|
errorMessage += " " + internalRunOutputName + " (advanced)\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-07-31 22:52:01 +04:00
|
|
|
errorMessage += detailsString;
|
2007-06-01 19:16:29 +04:00
|
|
|
cmSystemTools::Error(errorMessage.c_str());
|
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
|
2016-06-27 23:44:16 +03:00
|
|
|
if (out != CM_NULLPTR) {
|
2014-03-11 03:04:11 +04:00
|
|
|
(*out) = this->Makefile->GetDefinition(internalRunOutputName);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-06-01 19:16:29 +04:00
|
|
|
}
|