cmaketest.cxx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "cmaketest.h"
  2. #include "cmSystemTools.h"
  3. // this is a test driver program for cmake.
  4. main (int argc, char *argv[])
  5. {
  6. if (argc < 4)
  7. {
  8. std::cerr << "Usage: " << argv[0] << " test-src-dir test-bin-dir test-executable\n";
  9. return 1;
  10. }
  11. // does the directory exist ?
  12. if (!cmSystemTools::FileIsDirectory(argv[2]))
  13. {
  14. cmSystemTools::MakeDirectory(argv[2]);
  15. }
  16. /**
  17. * Run an executable command and put the stdout in output.
  18. */
  19. std::string output;
  20. // change to the tests directory and run cmake
  21. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  22. cmSystemTools::ChangeDirectory(argv[2]);
  23. std::string ccmd = CMAKE_COMMAND;
  24. ccmd += " ";
  25. ccmd += argv[1];
  26. if (!cmSystemTools::RunCommand(ccmd.c_str(), output))
  27. {
  28. std::cerr << "Error: cmake execution failed\n";
  29. std::cerr << output.c_str() << "\n";
  30. // return to the original directory
  31. cmSystemTools::ChangeDirectory(cwd.c_str());
  32. return 1;
  33. }
  34. // now build the test
  35. if (!cmSystemTools::RunCommand(MAKECOMMAND, output))
  36. {
  37. std::cerr << "Error: " MAKECOMMAND " execution failed\n";
  38. std::cerr << output.c_str() << "\n";
  39. // return to the original directory
  40. cmSystemTools::ChangeDirectory(cwd.c_str());
  41. return 1;
  42. }
  43. // now run the compiled test
  44. if (!cmSystemTools::RunCommand(argv[3], output))
  45. {
  46. std::cerr << "Error: " << argv[3] << " execution failed\n";
  47. // return to the original directory
  48. cmSystemTools::ChangeDirectory(cwd.c_str());
  49. return 1;
  50. }
  51. // return to the original directory
  52. cmSystemTools::ChangeDirectory(cwd.c_str());
  53. return 0;
  54. }