cmaketest.cxx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. std::string makeCommand = MAKEPROGRAM;
  36. makeCommand += " ";
  37. makeCommand += argv[3];
  38. #ifdef _WIN32
  39. makeCommand += ".dsw /MAKE \"ALL_BUILD - Release\" /REBUILD";
  40. #endif
  41. if (!cmSystemTools::RunCommand(makeCommand.c_str(), output))
  42. {
  43. std::cerr << "Error: " << makeCommand.c_str() << " execution failed\n";
  44. std::cerr << output.c_str() << "\n";
  45. // return to the original directory
  46. cmSystemTools::ChangeDirectory(cwd.c_str());
  47. return 1;
  48. }
  49. // now run the compiled test if we can find it
  50. // See if the executable exists as written.
  51. std::string fullPath;
  52. if(cmSystemTools::FileExists(argv[3]))
  53. {
  54. fullPath = cmSystemTools::CollapseFullPath(argv[3]);
  55. }
  56. std::string tryPath = argv[3];
  57. tryPath += cmSystemTools::GetExecutableExtension();
  58. if(cmSystemTools::FileExists(tryPath.c_str()))
  59. {
  60. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  61. }
  62. // try the release extension
  63. tryPath = "Release/";
  64. tryPath += cmSystemTools::GetFilenameName(argv[3]);
  65. if(cmSystemTools::FileExists(tryPath.c_str()))
  66. {
  67. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  68. }
  69. tryPath += cmSystemTools::GetExecutableExtension();
  70. if(cmSystemTools::FileExists(tryPath.c_str()))
  71. {
  72. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  73. }
  74. if (!cmSystemTools::RunCommand(fullPath.c_str(), output))
  75. {
  76. std::cerr << "Error: " << fullPath.c_str() << " execution failed\n";
  77. // return to the original directory
  78. cmSystemTools::ChangeDirectory(cwd.c_str());
  79. return 1;
  80. }
  81. // return to the original directory
  82. cmSystemTools::ChangeDirectory(cwd.c_str());
  83. return 0;
  84. }