summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-07-09 19:26:15 (GMT)
committerBrad King <brad.king@kitware.com>2013-07-15 13:16:36 (GMT)
commitc28715b16c7a71cd8ea0416277cc87ee9bc8eaa1 (patch)
tree5ac7556cea734d652fd2499d1c0323fc9419d5e3 /Source
parent448a67714825a6d3018a6974153de6771080a8e6 (diff)
downloadCMake-c28715b16c7a71cd8ea0416277cc87ee9bc8eaa1.zip
CMake-c28715b16c7a71cd8ea0416277cc87ee9bc8eaa1.tar.gz
CMake-c28715b16c7a71cd8ea0416277cc87ee9bc8eaa1.tar.bz2
try_compile: Add COPY_FILE_ERROR option to capture failure
When the COPY_FILE operation fails optionally capture the error message with a COPY_FILE_ERROR option instead of reporting the error immediately. This gives callers a chance to do something else or report the error. Teach the RunCMake.try_compile test to cover bad argument combinations involving COPY_FILE_ERROR. Teach the TryCompile test to cover the case of a COPY_FILE error message captured by COPY_FILE_ERROR.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCoreTryCompile.cxx46
-rw-r--r--Source/cmTryCompileCommand.h4
2 files changed, 45 insertions, 5 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 860417f..91b7215 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -32,18 +32,20 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
std::vector<std::string> compileDefs;
std::string outputVariable;
std::string copyFile;
+ std::string copyFileError;
std::vector<cmTarget*> targets;
std::string libsToLink = " ";
bool useOldLinkLibs = true;
char targetNameBuf[64];
bool didOutputVariable = false;
bool didCopyFile = false;
+ bool didCopyFileError = false;
bool useSources = argv[2] == "SOURCES";
std::vector<std::string> sources;
enum Doing { DoingNone, DoingCMakeFlags, DoingCompileDefinitions,
DoingLinkLibraries, DoingOutputVariable, DoingCopyFile,
- DoingSources };
+ DoingCopyFileError, DoingSources };
Doing doing = useSources? DoingSources : DoingNone;
for(size_t i=3; i < argv.size(); ++i)
{
@@ -74,6 +76,11 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
doing = DoingCopyFile;
didCopyFile = true;
}
+ else if(argv[i] == "COPY_FILE_ERROR")
+ {
+ doing = DoingCopyFileError;
+ didCopyFileError = true;
+ }
else if(doing == DoingCMakeFlags)
{
cmakeFlags.push_back(argv[i]);
@@ -121,6 +128,11 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
copyFile = argv[i].c_str();
doing = DoingNone;
}
+ else if(doing == DoingCopyFileError)
+ {
+ copyFileError = argv[i].c_str();
+ doing = DoingNone;
+ }
else if(doing == DoingSources)
{
sources.push_back(argv[i]);
@@ -149,6 +161,20 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
return -1;
}
+ if(didCopyFileError && copyFileError.empty())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "COPY_FILE_ERROR must be followed by a variable name");
+ return -1;
+ }
+
+ if(didCopyFileError && !didCopyFile)
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "COPY_FILE_ERROR may be used only with COPY_FILE");
+ return -1;
+ }
+
if(didOutputVariable && outputVariable.empty())
{
this->Makefile->IssueMessage(cmake::FATAL_ERROR,
@@ -444,6 +470,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
if (this->SrcFileSignature)
{
+ std::string copyFileErrorMessage;
this->FindOutputFile(targetName);
if ((res==0) && (copyFile.size()))
@@ -461,10 +488,23 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
{
emsg << this->FindErrorMessage.c_str();
}
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, emsg.str());
- return -1;
+ if(copyFileError.empty())
+ {
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, emsg.str());
+ return -1;
+ }
+ else
+ {
+ copyFileErrorMessage = emsg.str();
+ }
}
}
+
+ if(!copyFileError.empty())
+ {
+ this->Makefile->AddDefinition(copyFileError.c_str(),
+ copyFileErrorMessage.c_str());
+ }
}
return res;
}
diff --git a/Source/cmTryCompileCommand.h b/Source/cmTryCompileCommand.h
index 163756d..a20594c 100644
--- a/Source/cmTryCompileCommand.h
+++ b/Source/cmTryCompileCommand.h
@@ -69,14 +69,14 @@ public:
" [COMPILE_DEFINITIONS flags...]\n"
" [LINK_LIBRARIES libs...]\n"
" [OUTPUT_VARIABLE <var>]\n"
- " [COPY_FILE <fileName>])\n"
+ " [COPY_FILE <fileName> [COPY_FILE_ERROR <var>]])\n"
"Try building an executable from one or more source files. "
"In this form the user need only supply one or more source files "
"that include a definition for 'main'. "
"CMake will create a CMakeLists.txt file to build the source(s) "
"as an executable. "
"Specify COPY_FILE to get a copy of the linked executable at the "
- "given fileName."
+ "given fileName and optionally COPY_FILE_ERROR to capture any error."
"\n"
"In this version all files in bindir/CMakeFiles/CMakeTmp "
"will be cleaned automatically. For debugging, --debug-trycompile can "