summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2002-09-20 17:15:56 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2002-09-20 17:15:56 (GMT)
commit157e2b4ac3a067107561d4ccc2b08ea3555cce44 (patch)
treeaf1a9357c08c2b99ebeabd787e3b5f19bb56e062
parent92714311c992a924a249bf9f27820f0512af7013 (diff)
downloadCMake-157e2b4ac3a067107561d4ccc2b08ea3555cce44.zip
CMake-157e2b4ac3a067107561d4ccc2b08ea3555cce44.tar.gz
CMake-157e2b4ac3a067107561d4ccc2b08ea3555cce44.tar.bz2
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
-rw-r--r--Source/cmGlobalGenerator.cxx7
-rw-r--r--Source/cmGlobalGenerator.h3
-rw-r--r--Source/cmMakefile.cxx6
-rw-r--r--Source/cmMakefile.h3
-rw-r--r--Source/cmTryCompileCommand.cxx34
5 files changed, 42 insertions, 11 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 3bb4082..9a46ab0 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -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
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 4f994fb..226a67b 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -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) {
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 106d373..92fe82e 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -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;
diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h
index 56b5080..959677b 100644
--- a/Source/cmMakefile.h
+++ b/Source/cmMakefile.h
@@ -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
diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx
index 9e243a5..cf54a09 100644
--- a/Source/cmTryCompileCommand.cxx
+++ b/Source/cmTryCompileCommand.cxx
@@ -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)