2002-09-19 17:48:39 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2002-09-19 17:48:39 +04:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2002-09-19 17:48:39 +04:00
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "cmTryRunCommand.h"
|
|
|
|
#include "cmCacheManager.h"
|
|
|
|
#include "cmTryCompileCommand.h"
|
|
|
|
|
|
|
|
// cmExecutableCommand
|
|
|
|
bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv)
|
|
|
|
{
|
|
|
|
if(argv.size() < 4)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// build an arg list for TryCompile and extract the runArgs
|
|
|
|
std::vector<std::string> tryCompile;
|
2004-09-22 22:42:05 +04:00
|
|
|
std::string outputVariable;
|
2002-09-19 17:48:39 +04:00
|
|
|
std::string runArgs;
|
2002-09-20 16:09:03 +04:00
|
|
|
unsigned int i;
|
2002-09-19 17:48:39 +04:00
|
|
|
for (i = 1; i < argv.size(); ++i)
|
|
|
|
{
|
|
|
|
if (argv[i] == "ARGS")
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
while (i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" &&
|
|
|
|
argv[i] != "CMAKE_FLAGS")
|
|
|
|
{
|
|
|
|
runArgs += " ";
|
|
|
|
runArgs += argv[i];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i < argv.size())
|
|
|
|
{
|
|
|
|
tryCompile.push_back(argv[i]);
|
|
|
|
}
|
2004-09-22 22:42:05 +04:00
|
|
|
}
|
|
|
|
else
|
2002-09-19 17:48:39 +04:00
|
|
|
{
|
|
|
|
tryCompile.push_back(argv[i]);
|
2004-09-22 22:42:05 +04:00
|
|
|
if (argv[i] == "OUTPUT_VARIABLE")
|
|
|
|
{
|
|
|
|
if ( argv.size() <= (i+1) )
|
|
|
|
{
|
|
|
|
cmSystemTools::Error(
|
2005-02-10 07:00:16 +03:00
|
|
|
"OUTPUT_VARIABLE specified but there is no variable");
|
2004-09-22 22:42:05 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
outputVariable = argv[i+1];
|
|
|
|
}
|
2002-09-19 17:48:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// do the try compile
|
|
|
|
int res = cmTryCompileCommand::CoreTryCompileCode(m_Makefile, tryCompile, false);
|
|
|
|
|
|
|
|
// now try running the command if it compiled
|
2006-01-12 21:49:32 +03:00
|
|
|
std::string binaryDirectory = argv[2] + "/CMakeFiles/CMakeTmp";
|
2002-09-19 17:48:39 +04:00
|
|
|
if (!res)
|
|
|
|
{
|
2005-02-10 07:00:16 +03:00
|
|
|
int retVal = -1;
|
2002-09-19 17:48:39 +04:00
|
|
|
std::string output;
|
2005-06-21 22:20:30 +04:00
|
|
|
std::string command1 = binaryDirectory;
|
|
|
|
command1 += "/cmTryCompileExec";
|
|
|
|
command1 += cmSystemTools::GetExecutableExtension();
|
2002-09-19 17:48:39 +04:00
|
|
|
std::string fullPath;
|
2005-06-21 22:20:30 +04:00
|
|
|
if(cmSystemTools::FileExists(command1.c_str()))
|
2002-09-19 17:48:39 +04:00
|
|
|
{
|
2005-06-21 22:20:30 +04:00
|
|
|
fullPath = cmSystemTools::CollapseFullPath(command1.c_str());
|
2002-09-19 17:48:39 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-21 22:20:30 +04:00
|
|
|
std::string command2 = binaryDirectory;
|
|
|
|
command2 += "/Debug/cmTryCompileExec";
|
|
|
|
command2 += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(command2.c_str()))
|
2002-09-19 17:48:39 +04:00
|
|
|
{
|
2005-06-21 22:20:30 +04:00
|
|
|
fullPath = cmSystemTools::CollapseFullPath(command2.c_str());
|
2002-09-19 17:48:39 +04:00
|
|
|
}
|
2002-09-20 00:07:23 +04:00
|
|
|
else
|
|
|
|
{
|
2005-08-30 21:58:46 +04:00
|
|
|
std::string command3 = binaryDirectory;
|
|
|
|
command3 += "/Development/cmTryCompileExec";
|
|
|
|
command3 += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(command3.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(command3.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream emsg;
|
|
|
|
emsg << "Unable to find executable for TRY_RUN: tried \""
|
|
|
|
<< command1 << "\" and \""
|
|
|
|
<< command2 << "\" and \""
|
|
|
|
<< command3 << "\".";
|
|
|
|
cmSystemTools::Error(emsg.str().c_str());
|
|
|
|
}
|
2002-09-20 00:07:23 +04:00
|
|
|
}
|
2002-09-19 17:48:39 +04:00
|
|
|
}
|
2002-09-20 00:07:23 +04:00
|
|
|
if (fullPath.size() > 1)
|
2002-09-19 17:48:39 +04:00
|
|
|
{
|
|
|
|
std::string finalCommand = fullPath;
|
2004-06-24 00:34:38 +04:00
|
|
|
finalCommand = cmSystemTools::ConvertToRunCommandPath(fullPath.c_str());
|
2002-09-19 17:48:39 +04:00
|
|
|
if(runArgs.size())
|
|
|
|
{
|
|
|
|
finalCommand += runArgs;
|
|
|
|
}
|
2003-08-04 06:33:35 +04:00
|
|
|
int timeout = 0;
|
2005-02-10 07:00:16 +03:00
|
|
|
bool worked = cmSystemTools::RunSingleCommand(finalCommand.c_str(),
|
|
|
|
&output, &retVal,
|
|
|
|
0, false, timeout);
|
2004-09-22 22:42:05 +04:00
|
|
|
if(outputVariable.size())
|
|
|
|
{
|
|
|
|
// if the TryCompileCore saved output in this outputVariable then
|
|
|
|
// prepend that output to this output
|
2005-02-10 07:00:16 +03:00
|
|
|
const char* compileOutput
|
|
|
|
= m_Makefile->GetDefinition(outputVariable.c_str());
|
2004-09-22 22:42:05 +04:00
|
|
|
if(compileOutput)
|
|
|
|
{
|
|
|
|
output = std::string(compileOutput) + output;
|
|
|
|
}
|
|
|
|
m_Makefile->AddDefinition(outputVariable.c_str(), output.c_str());
|
|
|
|
}
|
2002-09-19 17:48:39 +04:00
|
|
|
// set the run var
|
|
|
|
char retChar[1000];
|
2005-02-10 07:00:16 +03:00
|
|
|
if(worked)
|
|
|
|
{
|
|
|
|
sprintf(retChar,"%i",retVal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(retChar, "FAILED_TO_RUN");
|
|
|
|
}
|
2002-09-20 23:01:00 +04:00
|
|
|
m_Makefile->AddCacheDefinition(argv[0].c_str(), retChar,
|
2005-02-10 07:00:16 +03:00
|
|
|
"Result of TRY_RUN",
|
|
|
|
cmCacheManager::INTERNAL);
|
2002-09-19 17:48:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we created a directory etc, then cleanup after ourselves
|
2002-09-20 00:07:23 +04:00
|
|
|
std::string cacheFile = binaryDirectory;
|
|
|
|
cacheFile += "/CMakeLists.txt";
|
|
|
|
cmListFileCache::GetInstance()->FlushCache(cacheFile.c_str());
|
2004-08-05 01:21:19 +04:00
|
|
|
if(!m_Makefile->GetCMakeInstance()->GetDebugTryCompile())
|
|
|
|
{
|
|
|
|
cmTryCompileCommand::CleanupFiles(binaryDirectory.c_str());
|
|
|
|
}
|
2002-09-19 17:48:39 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|