Commit 157e2b4a authored by Andy Cedilnik's avatar Andy Cedilnik
Browse files

Add option of TRY_COMPILE to store the output of compilation so that if the...

Add option of TRY_COMPILE to store the output of compilation so that if the output fails you can display it or store it in the file
parent 92714311
......@@ -141,7 +141,8 @@ void cmGlobalGenerator::LocalGenerate()
}
int cmGlobalGenerator::TryCompile(const char *, const char *bindir,
const char *, const char *target)
const char *, const char *target,
std::string *output)
{
// now build the test
std::string makeCommand =
......@@ -157,7 +158,6 @@ int cmGlobalGenerator::TryCompile(const char *, const char *bindir,
/**
* Run an executable command and put the stdout in output.
*/
std::string output;
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ChangeDirectory(bindir);
......@@ -172,7 +172,8 @@ int cmGlobalGenerator::TryCompile(const char *, const char *bindir,
makeCommand += " all";
}
int retVal;
if (!cmSystemTools::RunCommand(makeCommand.c_str(), output, retVal, 0, false))
if (!cmSystemTools::RunCommand(makeCommand.c_str(), *output, retVal, 0, false))
{
cmSystemTools::Error("Generator: execution of make failed.");
// return to the original directory
......
......@@ -87,7 +87,8 @@ public:
* loaded commands, not as part of the usual build process.
*/
virtual int TryCompile(const char *srcdir, const char *bindir,
const char *projectName, const char *targetName);
const char *projectName, const char *targetName,
std::string *output);
///! Set the CMake instance
void SetCMakeInstance(cmake *cm) {
......
......@@ -1340,7 +1340,8 @@ void cmMakefile::ExpandSourceListArguments(
int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
const char *projectName, const char *targetName,
const std::vector<std::string> *cmakeArgs)
const std::vector<std::string> *cmakeArgs,
std::string *output)
{
// does the binary directory exist ? If not create it...
if (!cmSystemTools::FileIsDirectory(bindir))
......@@ -1409,7 +1410,8 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
int ret =
m_LocalGenerator->GetGlobalGenerator()->TryCompile(srcdir,bindir,
projectName,
targetName);
targetName,
output);
cmSystemTools::ChangeDirectory(cwd.c_str());
return ret;
......
......@@ -85,7 +85,8 @@ public:
*/
int TryCompile(const char *srcdir, const char *bindir,
const char *projectName, const char *targetName,
const std::vector<std::string> *cmakeArgs);
const std::vector<std::string> *cmakeArgs,
std::string *output);
/**
* Specify the makefile generator. This is platform/compiler
......
......@@ -33,7 +33,8 @@ int cmTryCompileCommand::CoreTryCompileCode(
std::string tmpString;
// do we have a srcfile signature
if (argv.size() == 3 || argv[3] == "CMAKE_FLAGS" || argv[3] == "COMPILE_DEFINITIONS")
if (argv.size() == 3 || argv[3] == "CMAKE_FLAGS" || argv[3] == "COMPILE_DEFINITIONS" ||
argv[3] == "OUTPUT_VARIABLE")
{
srcFileSignature = true;
}
......@@ -44,7 +45,8 @@ int cmTryCompileCommand::CoreTryCompileCode(
{
if (argv[i] == "CMAKE_FLAGS")
{
for (; i < argv.size() && argv[i] != "COMPILE_DEFINITIONS";
for (; i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" &&
argv[i] != "OUTPUT_VARIABLE";
++i)
{
cmakeFlags.push_back(argv[i]);
......@@ -53,6 +55,23 @@ int cmTryCompileCommand::CoreTryCompileCode(
}
}
// look for OUTPUT_VARIABLE and store them
std::string outputVariable;
for (i = 3; i < argv.size(); ++i)
{
if (argv[i] == "OUTPUT_VARIABLE")
{
if ( argv.size() <= (i+1) )
{
cmSystemTools::Error(
"OUTPUT_VARIABLE specified but there is no variable");
return -1;
}
outputVariable = argv[i+1];
break;
}
}
// look for COMPILE_DEFINITIONS and store them
std::vector<std::string> compileFlags;
for (i = 3; i < argv.size(); ++i)
......@@ -66,7 +85,8 @@ int cmTryCompileCommand::CoreTryCompileCode(
"COMPILE_FLAGS specified on a srcdir type TRY_COMPILE");
return -1;
}
for (i = i + 1; i < argv.size() && argv[i] != "CMAKE_FLAGS";
for (i = i + 1; i < argv.size() && argv[i] != "CMAKE_FLAGS" &&
argv[i] != "OUTPUT_VARIABLE";
++i)
{
compileFlags.push_back(argv[i]);
......@@ -144,12 +164,18 @@ int cmTryCompileCommand::CoreTryCompileCode(
}
}
std::string output;
// actually do the try compile now that everything is setup
int res = mf->TryCompile(sourceDirectory, binaryDirectory,
projectName, targetName, &cmakeFlags);
projectName, targetName, &cmakeFlags, &output);
// set the result var to the return value to indicate success or failure
mf->AddDefinition(argv[0].c_str(), (res == 0 ? "TRUE" : "FALSE"));
if ( outputVariable.size() > 0 )
{
mf->AddDefinition(outputVariable.c_str(), output.c_str());
}
// if They specified clean then we clean up what we can
if (srcFileSignature && clean)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment