CMake/Source/cmaketest.cxx

94 lines
2.6 KiB
C++
Raw Normal View History

2001-06-22 01:52:54 +04:00
#include "cmaketest.h"
#include "cmSystemTools.h"
// 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]);
}
/**
* Run an executable command and put the stdout in output.
*/
std::string output;
// change to the tests directory and run cmake
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
cmSystemTools::ChangeDirectory(argv[2]);
std::string ccmd = CMAKE_COMMAND;
ccmd += " ";
ccmd += argv[1];
if (!cmSystemTools::RunCommand(ccmd.c_str(), output))
{
2001-06-22 17:27:11 +04:00
std::cerr << "Error: cmake execution failed\n";
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;
}
// now build the test
2001-06-27 17:17:12 +04:00
std::string makeCommand = MAKEPROGRAM;
makeCommand += " ";
makeCommand += argv[3];
#ifdef _WIN32
makeCommand += ".dsw /MAKE \"ALL_BUILD - Release\" /REBUILD";
#endif
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;
if(cmSystemTools::FileExists(argv[3]))
2001-06-22 01:52:54 +04:00
{
2001-06-27 17:17:12 +04:00
fullPath = cmSystemTools::CollapseFullPath(argv[3]);
}
std::string tryPath = argv[3];
tryPath += cmSystemTools::GetExecutableExtension();
if(cmSystemTools::FileExists(tryPath.c_str()))
{
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
}
// try the release extension
tryPath = "Release/";
tryPath += cmSystemTools::GetFilenameName(argv[3]);
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());
}
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());
return 0;
}