2001-06-22 01:52:54 +04:00
|
|
|
#include "cmaketest.h"
|
|
|
|
#include "cmSystemTools.h"
|
2001-08-29 23:57:57 +04:00
|
|
|
#include "cmake.h"
|
|
|
|
#include "cmListFileCache.h"
|
2001-10-01 19:55:10 +04:00
|
|
|
#include "cmMakefileGenerator.h"
|
2001-11-28 18:51:28 +03:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2001-10-26 23:42:02 +04:00
|
|
|
#include "windows.h"
|
|
|
|
#endif
|
2001-06-22 01:52:54 +04:00
|
|
|
|
|
|
|
// this is a test driver program for cmake.
|
2001-06-29 17:53:09 +04:00
|
|
|
int main (int argc, char *argv[])
|
2001-06-22 01:52:54 +04:00
|
|
|
{
|
|
|
|
if (argc < 4)
|
|
|
|
{
|
2001-06-22 17:27:11 +04:00
|
|
|
std::cerr << "Usage: " << argv[0] << " test-src-dir test-bin-dir test-executable\n";
|
2001-06-22 01:52:54 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// does the directory exist ?
|
|
|
|
if (!cmSystemTools::FileIsDirectory(argv[2]))
|
|
|
|
{
|
|
|
|
cmSystemTools::MakeDirectory(argv[2]);
|
|
|
|
}
|
2001-08-24 00:00:46 +04:00
|
|
|
const char* sourceDirectory = argv[1];
|
|
|
|
const char* binaryDirectory = argv[2];
|
|
|
|
const char* executableName = argv[3];
|
|
|
|
const char* executableDirectory = "";
|
|
|
|
if(argc > 4)
|
|
|
|
{
|
|
|
|
executableDirectory = argv[4];
|
|
|
|
}
|
|
|
|
|
2001-06-22 01:52:54 +04:00
|
|
|
/**
|
|
|
|
* Run an executable command and put the stdout in output.
|
|
|
|
*/
|
|
|
|
std::string output;
|
|
|
|
|
|
|
|
// change to the tests directory and run cmake
|
2001-08-29 23:57:57 +04:00
|
|
|
// use the cmake object instead of calling cmake
|
2001-06-22 01:52:54 +04:00
|
|
|
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
|
2001-08-24 00:00:46 +04:00
|
|
|
cmSystemTools::ChangeDirectory(binaryDirectory);
|
2001-08-29 23:57:57 +04:00
|
|
|
cmake cm;
|
|
|
|
std::vector<std::string> args;
|
2001-11-15 02:12:22 +03:00
|
|
|
// make sure the same generator is used
|
2001-08-29 23:57:57 +04:00
|
|
|
// use this program as the cmake to be run, it should not
|
|
|
|
// be run that way but the cmake object requires a vailid path
|
|
|
|
std::string cmakeCommand = CMAKE_COMMAND;
|
2001-09-11 22:42:50 +04:00
|
|
|
if(cmakeCommand[0] == '\\' && cmakeCommand[1] == '\"')
|
|
|
|
{
|
|
|
|
cmakeCommand = cmakeCommand.substr(2, cmakeCommand.size()-4);
|
|
|
|
}
|
|
|
|
if(cmakeCommand[0] == '\"')
|
2001-08-29 23:57:57 +04:00
|
|
|
{
|
|
|
|
cmakeCommand = cmakeCommand.substr(1, cmakeCommand.size()-2);
|
|
|
|
}
|
|
|
|
args.push_back(cmakeCommand.c_str());
|
|
|
|
args.push_back(sourceDirectory);
|
2001-11-15 02:12:22 +03:00
|
|
|
std::string generator = "-G";
|
|
|
|
generator += CMAKE_GENERATOR;
|
|
|
|
args.push_back(generator);
|
|
|
|
|
2001-08-29 23:57:57 +04:00
|
|
|
if (cm.Generate(args) != 0)
|
2001-06-22 01:52:54 +04:00
|
|
|
{
|
2001-06-22 17:27:11 +04:00
|
|
|
std::cerr << "Error: cmake execution failed\n";
|
2001-06-22 01:52:54 +04:00
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
2001-08-29 23:57:57 +04:00
|
|
|
cmListFileCache::GetInstance()->ClearCache();
|
2001-06-22 01:52:54 +04:00
|
|
|
// now build the test
|
2001-06-27 17:17:12 +04:00
|
|
|
std::string makeCommand = MAKEPROGRAM;
|
2001-11-22 01:45:01 +03:00
|
|
|
if(makeCommand.size() == 0)
|
|
|
|
{
|
|
|
|
std::cerr << "Error: cmaketest does not have a valid MAKEPROGRAM\n";
|
|
|
|
}
|
2001-12-07 21:10:50 +03:00
|
|
|
makeCommand = cmSystemTools::EscapeSpaces(makeCommand.c_str());
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
cmSystemTools::ConvertToWindowsSlashes(makeCommand);
|
|
|
|
#endif
|
2001-11-15 02:12:22 +03:00
|
|
|
std::string lowerCaseCommand = makeCommand;
|
|
|
|
cmSystemTools::LowerCase(lowerCaseCommand);
|
|
|
|
// if msdev is the make program then do the following
|
|
|
|
if(lowerCaseCommand.find("msdev") != std::string::npos)
|
2001-10-26 23:42:02 +04:00
|
|
|
{
|
2001-11-15 02:12:22 +03:00
|
|
|
// if there are spaces in the makeCommand, assume a full path
|
|
|
|
// and convert it to a path with no spaces in it as the
|
|
|
|
// RunCommand does not like spaces
|
2001-11-22 01:45:01 +03:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2001-11-15 02:12:22 +03:00
|
|
|
if(makeCommand.find(' ') != std::string::npos)
|
2001-10-26 23:42:02 +04:00
|
|
|
{
|
2001-11-15 02:12:22 +03:00
|
|
|
char *buffer = new char[makeCommand.size()+1];
|
|
|
|
if(GetShortPathName(makeCommand.c_str(), buffer,
|
|
|
|
makeCommand.size()+1) != 0)
|
|
|
|
{
|
|
|
|
makeCommand = buffer;
|
|
|
|
}
|
2001-11-21 01:27:04 +03:00
|
|
|
delete [] buffer;\
|
2001-10-26 23:42:02 +04:00
|
|
|
}
|
2001-11-22 01:45:01 +03:00
|
|
|
#endif
|
2001-11-15 02:12:22 +03:00
|
|
|
makeCommand += " ";
|
|
|
|
makeCommand += executableName;
|
|
|
|
makeCommand += ".dsw /MAKE \"ALL_BUILD - Debug\" /REBUILD";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// assume a make sytle program
|
|
|
|
makeCommand += " all";
|
2001-10-26 23:42:02 +04:00
|
|
|
}
|
2001-06-27 17:17:12 +04:00
|
|
|
if (!cmSystemTools::RunCommand(makeCommand.c_str(), output))
|
2001-06-22 01:52:54 +04:00
|
|
|
{
|
2001-06-27 17:17:12 +04:00
|
|
|
std::cerr << "Error: " << makeCommand.c_str() << " execution failed\n";
|
2001-06-22 17:27:11 +04:00
|
|
|
std::cerr << output.c_str() << "\n";
|
2001-06-22 01:52:54 +04:00
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-06-27 17:17:12 +04:00
|
|
|
// now run the compiled test if we can find it
|
|
|
|
// See if the executable exists as written.
|
|
|
|
std::string fullPath;
|
2001-08-24 00:00:46 +04:00
|
|
|
if(cmSystemTools::FileExists(executableName))
|
2001-06-22 01:52:54 +04:00
|
|
|
{
|
2001-08-24 00:00:46 +04:00
|
|
|
fullPath = cmSystemTools::CollapseFullPath(executableName);
|
2001-06-27 17:17:12 +04:00
|
|
|
}
|
2001-08-24 00:00:46 +04:00
|
|
|
std::string tryPath = executableName;
|
2001-06-27 17:17:12 +04:00
|
|
|
tryPath += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
2001-08-29 23:57:57 +04:00
|
|
|
// try the Debug extension
|
|
|
|
tryPath = "Debug/";
|
2001-08-24 00:00:46 +04:00
|
|
|
tryPath += cmSystemTools::GetFilenameName(executableName);
|
2001-06-27 17:17:12 +04:00
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
|
|
|
tryPath += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
2001-08-24 00:00:46 +04:00
|
|
|
tryPath = executableDirectory;
|
|
|
|
tryPath += "/";
|
|
|
|
tryPath += executableName;
|
|
|
|
tryPath += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
|
|
|
tryPath = executableDirectory;
|
2001-08-29 23:57:57 +04:00
|
|
|
tryPath += "/Debug/";
|
2001-08-24 00:00:46 +04:00
|
|
|
tryPath += executableName;
|
|
|
|
tryPath += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
2001-10-03 23:49:52 +04:00
|
|
|
if(!cmSystemTools::FileExists(fullPath.c_str()))
|
|
|
|
{
|
|
|
|
std::cerr << "Could not find path to executable, perhaps it was not built: " <<
|
|
|
|
executableName << "\n";
|
|
|
|
std::cerr << "Error: " << fullPath.c_str() << " execution failed\n";
|
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
2001-12-07 22:31:28 +03:00
|
|
|
fullPath = cmSystemTools::EscapeSpaces(fullPath.c_str());
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
cmSystemTools::ConvertToWindowsSlashes(fullPath);
|
|
|
|
#endif
|
2001-06-27 17:17:12 +04:00
|
|
|
if (!cmSystemTools::RunCommand(fullPath.c_str(), output))
|
|
|
|
{
|
|
|
|
std::cerr << "Error: " << fullPath.c_str() << " execution failed\n";
|
2001-06-22 01:52:54 +04:00
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
2001-10-01 18:14:39 +04:00
|
|
|
cmMakefileGenerator::UnRegisterGenerators();
|
2001-06-22 01:52:54 +04:00
|
|
|
return 0;
|
|
|
|
}
|