cmCTestCoverageCommand.cxx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. "
  40. "RETURN_VALUE specified twice.");
  41. return false;
  42. }
  43. havereturn_variable = true;
  44. }
  45. else if(args[i] == "BUILD")
  46. {
  47. if ( build_dir )
  48. {
  49. this->SetError("called with incorrect number of arguments. "
  50. "BUILD specified twice.");
  51. return false;
  52. }
  53. havesource = true;
  54. }
  55. else
  56. {
  57. cmOStringStream str;
  58. str << "called with incorrect number of arguments. Extra argument is: "
  59. << args[i].c_str() << ".";
  60. this->SetError(str.str().c_str());
  61. return false;
  62. }
  63. }
  64. if ( build_dir )
  65. {
  66. this->CTest->SetCTestConfiguration("BuildDirectory", build_dir);
  67. }
  68. this->CTest->SetCTestConfigurationFromCMakeVariable(this->Makefile,
  69. "CoverageCommand", "CTEST_COVERAGE_COMMAND");
  70. cmCTestGenericHandler* handler
  71. = this->CTest->GetInitializedHandler("coverage");
  72. if ( !handler )
  73. {
  74. this->SetError("internal CTest error. Cannot instantiate test handler");
  75. return false;
  76. }
  77. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  78. cmSystemTools::ChangeDirectory(
  79. this->CTest->GetCTestConfiguration("BuildDirectory").c_str());
  80. int res = handler->ProcessHandler();
  81. if ( res_var )
  82. {
  83. cmOStringStream str;
  84. str << res;
  85. this->Makefile->AddDefinition(res_var, str.str().c_str());
  86. }
  87. cmSystemTools::ChangeDirectory(current_dir.c_str());
  88. return true;
  89. }