cmCTestCoverageCommand.cxx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestCoverageCommand.h"
  14. #include "cmCTest.h"
  15. #include "cmCTestGenericHandler.h"
  16. bool cmCTestCoverageCommand::InitialPass(
  17. std::vector<std::string> const& args)
  18. {
  19. const char* build_dir = 0;
  20. const char* res_var = 0;
  21. bool havereturn_variable = false;
  22. bool havesource = false;
  23. for(size_t i=0; i < args.size(); ++i)
  24. {
  25. if ( havereturn_variable )
  26. {
  27. res_var = args[i].c_str();
  28. havereturn_variable = false;
  29. }
  30. else if ( havesource )
  31. {
  32. build_dir = args[i].c_str();
  33. havesource = false;
  34. }
  35. else if(args[i] == "RETURN_VALUE")
  36. {
  37. if ( res_var )
  38. {
  39. this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice.");
  40. return false;
  41. }
  42. havereturn_variable = true;
  43. }
  44. else if(args[i] == "BUILD")
  45. {
  46. if ( build_dir )
  47. {
  48. this->SetError("called with incorrect number of arguments. BUILD specified twice.");
  49. return false;
  50. }
  51. havesource = true;
  52. }
  53. else
  54. {
  55. cmOStringStream str;
  56. str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << ".";
  57. this->SetError(str.str().c_str());
  58. return false;
  59. }
  60. }
  61. if ( build_dir )
  62. {
  63. m_CTest->SetCTestConfiguration("BuildDirectory", build_dir);
  64. }
  65. m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile,
  66. "CoverageCommand", "CTEST_COVERAGE_COMMAND");
  67. cmCTestGenericHandler* handler = m_CTest->GetHandler("coverage");
  68. if ( !handler )
  69. {
  70. this->SetError("internal CTest error. Cannot instantiate test handler");
  71. return false;
  72. }
  73. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  74. cmSystemTools::ChangeDirectory(m_CTest->GetCTestConfiguration("BuildDirectory").c_str());
  75. int res = handler->ProcessHandler();
  76. if ( res_var )
  77. {
  78. cmOStringStream str;
  79. str << res;
  80. m_Makefile->AddDefinition(res_var, str.str().c_str());
  81. }
  82. cmSystemTools::ChangeDirectory(current_dir.c_str());
  83. return true;
  84. }