mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-05 13:50:10 -05:00
ENH: add COPY_FILE argument to TRY_COMPILE, so the compiled executable can
be used e.g. for getting strings out of it. Alex
This commit is contained in:
@@ -90,6 +90,24 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
|
||||
}
|
||||
}
|
||||
|
||||
// look for COPY_FILE
|
||||
std::string copyFile;
|
||||
for (i = 3; i < argv.size(); ++i)
|
||||
{
|
||||
if (argv[i] == "COPY_FILE")
|
||||
{
|
||||
if ( argv.size() <= (i+1) )
|
||||
{
|
||||
cmSystemTools::Error(
|
||||
"COPY_FILE specified but there is no variable");
|
||||
return -1;
|
||||
}
|
||||
extraArgs += 2;
|
||||
copyFile = argv[i+1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// do we have a srcfile signature
|
||||
if (argv.size() - extraArgs == 3)
|
||||
{
|
||||
@@ -112,6 +130,11 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
|
||||
"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");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// make sure the binary directory exists
|
||||
cmSystemTools::MakeDirectory(this->BinaryDirectory.c_str());
|
||||
@@ -262,6 +285,15 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv)
|
||||
if (this->SrcFileSignature)
|
||||
{
|
||||
this->FindOutputFile(targetName);
|
||||
if ((res==0) && (copyFile.size()))
|
||||
{
|
||||
if(!cmSystemTools::CopyFileAlways(this->OutputFile.c_str(),
|
||||
copyFile.c_str()))
|
||||
{
|
||||
cmSystemTools::Error("Could not COPY_FILE");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user