summaryrefslogtreecommitdiffstats
path: root/Source/cmCoreTryCompile.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmCoreTryCompile.cxx')
-rw-r--r--Source/cmCoreTryCompile.cxx109
1 files changed, 48 insertions, 61 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 1a46df0..e1cb0bb 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -1,6 +1,6 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
- Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
+ Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
@@ -56,7 +56,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
{
if ( argv.size() <= (i+1) )
{
- cmSystemTools::Error(
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
"OUTPUT_VARIABLE specified but there is no variable");
return -1;
}
@@ -92,7 +92,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
{
if ( argv.size() <= (i+1) )
{
- cmSystemTools::Error(
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
"COPY_FILE specified but there is no variable");
return -1;
}
@@ -120,13 +120,14 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
// only valid for srcfile signatures
if (compileFlags.size())
{
- cmSystemTools::Error(
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
"COMPILE_FLAGS specified on a srcdir type TRY_COMPILE");
return -1;
}
if (copyFile.size())
{
- cmSystemTools::Error("COPY_FILE specified on a srcdir type TRY_COMPILE");
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR,
+ "COPY_FILE specified on a srcdir type TRY_COMPILE");
return -1;
}
}
@@ -136,9 +137,10 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
// do not allow recursive try Compiles
if (this->BinaryDirectory == this->Makefile->GetHomeOutputDirectory())
{
- cmSystemTools::Error(
- "Attempt at a recursive or nested TRY_COMPILE in directory ",
- this->BinaryDirectory.c_str());
+ cmOStringStream e;
+ e << "Attempt at a recursive or nested TRY_COMPILE in directory\n"
+ << " " << this->BinaryDirectory << "\n";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return -1;
}
@@ -158,19 +160,22 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
FILE *fout = fopen(outFileName.c_str(),"w");
if (!fout)
{
- cmSystemTools::Error("Failed to create CMakeList file for ",
- outFileName.c_str());
- cmSystemTools::ReportLastSystemError("");
+ cmOStringStream e;
+ e << "Failed to open\n"
+ << " " << outFileName.c_str() << "\n"
+ << cmSystemTools::GetLastSystemError();
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return -1;
}
std::string source = argv[2];
- std::string ext = cmSystemTools::GetFilenameExtension(source);
+ std::string ext = cmSystemTools::GetFilenameLastExtension(source);
const char* lang =(this->Makefile->GetCMakeInstance()->GetGlobalGenerator()
->GetLanguageFromExtension(ext.c_str()));
const char* def = this->Makefile->GetDefinition("CMAKE_MODULE_PATH");
- fprintf(fout, "cmake_minimum_required(VERSION %u.%u)\n",
- cmVersion::GetMajorVersion(), cmVersion::GetMinorVersion());
+ fprintf(fout, "cmake_minimum_required(VERSION %u.%u.%u.%u)\n",
+ cmVersion::GetMajorVersion(), cmVersion::GetMinorVersion(),
+ cmVersion::GetPatchVersion(), cmVersion::GetTweakVersion());
if(def)
{
fprintf(fout, "SET(CMAKE_MODULE_PATH %s)\n", def);
@@ -178,7 +183,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
const char* rulesOverrideBase = "CMAKE_USER_MAKE_RULES_OVERRIDE";
std::string rulesOverrideLang =
- rulesOverrideBase + (lang ? std::string("_") + lang : "");
+ rulesOverrideBase + (lang ? std::string("_") + lang : std::string(""));
if(const char* rulesOverridePath =
this->Makefile->GetDefinition(rulesOverrideLang.c_str()))
{
@@ -198,10 +203,12 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
}
else
{
+ fclose(fout);
cmOStringStream err;
- err << "Unknown extension \"" << ext << "\" for file \""
- << source << "\". TRY_COMPILE only works for enabled languages.\n"
- << "Currently enabled languages are:";
+ err << "Unknown extension \"" << ext << "\" for file\n"
+ << " " << source << "\n"
+ << "try_compile() works only for enabled languages. "
+ << "Currently these are:\n ";
std::vector<std::string> langs;
this->Makefile->GetCMakeInstance()->GetGlobalGenerator()->
GetEnabledLanguages(langs);
@@ -210,9 +217,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
{
err << " " << *l;
}
- err << "\nSee PROJECT command for help enabling other languages.";
- cmSystemTools::Error(err.str().c_str());
- fclose(fout);
+ err << "\nSee project() command to enable other languages.";
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, err.str());
return -1;
}
std::string langFlags = "CMAKE_";
@@ -343,17 +349,15 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
copyFile.c_str()))
{
cmOStringStream emsg;
- emsg << "Could not COPY_FILE.\n"
- << " OutputFile: '" << this->OutputFile.c_str() << "'\n"
- << " copyFile: '" << copyFile.c_str() << "'\n";
-
- if (this->FindErrorMessage.size())
+ emsg << "Cannot copy output executable\n"
+ << " '" << this->OutputFile.c_str() << "'\n"
+ << "to destination specified by COPY_FILE:\n"
+ << " '" << copyFile.c_str() << "'\n";
+ if(!this->FindErrorMessage.empty())
{
- emsg << "\n";
- emsg << this->FindErrorMessage.c_str() << "\n";
+ emsg << this->FindErrorMessage.c_str();
}
-
- cmSystemTools::Error(emsg.str().c_str());
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, emsg.str());
return -1;
}
}
@@ -400,28 +404,18 @@ void cmCoreTryCompile::CleanupFiles(const char* binDir)
}
else
{
- if(!cmSystemTools::RemoveFile(fullPath.c_str()))
+ // Sometimes anti-virus software hangs on to new files so we
+ // cannot delete them immediately. Try a few times.
+ int tries = 5;
+ while(!cmSystemTools::RemoveFile(fullPath.c_str()) &&
+ --tries && cmSystemTools::FileExists(fullPath.c_str()))
+ {
+ cmSystemTools::Delay(500);
+ }
+ if(tries == 0)
{
- bool removed = false;
- int numAttempts = 0;
- // sometimes anti-virus software hangs on to
- // new files and we can not delete them, so try
- // 5 times with .5 second delay between tries.
- while(!removed && numAttempts < 5)
- {
- cmSystemTools::Delay(500);
- if(cmSystemTools::RemoveFile(fullPath.c_str()))
- {
- removed = true;
- }
- numAttempts++;
- }
- if(!removed)
- {
- std::string m = "Remove failed on file: ";
- m += fullPath;
- cmSystemTools::ReportLastSystemError(m.c_str());
- }
+ std::string m = "Remove failed on file: " + fullPath;
+ cmSystemTools::ReportLastSystemError(m.c_str());
}
}
}
@@ -470,18 +464,11 @@ void cmCoreTryCompile::FindOutputFile(const char* targetName)
}
cmOStringStream emsg;
- emsg << "Unable to find executable for " << this->GetName() << ": tried \"";
+ emsg << "Unable to find the executable at any of:\n";
for (unsigned int i = 0; i < searchDirs.size(); ++i)
{
- emsg << this->BinaryDirectory << searchDirs[i] << tmpOutputFile;
- if (i < searchDirs.size() - 1)
- {
- emsg << "\" and \"";
- }
- else
- {
- emsg << "\".";
- }
+ emsg << " " << this->BinaryDirectory << searchDirs[i]
+ << tmpOutputFile << "\n";
}
this->FindErrorMessage = emsg.str();
return;