cmCTestBuildCommand.cxx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestBuildCommand.h"
  11. #include "cmCTest.h"
  12. #include "cmCTestGenericHandler.h"
  13. #include "cmCTestBuildHandler.h"
  14. #include "cmake.h"
  15. #include "cmGlobalGenerator.h"
  16. //----------------------------------------------------------------------------
  17. cmCTestBuildCommand::cmCTestBuildCommand()
  18. {
  19. this->GlobalGenerator = 0;
  20. this->Arguments[ctb_NUMBER_ERRORS] = "NUMBER_ERRORS";
  21. this->Arguments[ctb_NUMBER_WARNINGS] = "NUMBER_WARNINGS";
  22. this->Arguments[ctb_LAST] = 0;
  23. this->Last = ctb_LAST;
  24. }
  25. //----------------------------------------------------------------------------
  26. cmCTestBuildCommand::~cmCTestBuildCommand()
  27. {
  28. if ( this->GlobalGenerator )
  29. {
  30. delete this->GlobalGenerator;
  31. this->GlobalGenerator = 0;
  32. }
  33. }
  34. //----------------------------------------------------------------------------
  35. cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
  36. {
  37. cmCTestGenericHandler* handler
  38. = this->CTest->GetInitializedHandler("build");
  39. if ( !handler )
  40. {
  41. this->SetError("internal CTest error. Cannot instantiate build handler");
  42. return 0;
  43. }
  44. this->Handler = (cmCTestBuildHandler*)handler;
  45. const char* ctestBuildCommand
  46. = this->Makefile->GetDefinition("CTEST_BUILD_COMMAND");
  47. if ( ctestBuildCommand && *ctestBuildCommand )
  48. {
  49. this->CTest->SetCTestConfiguration("MakeCommand", ctestBuildCommand);
  50. }
  51. else
  52. {
  53. const char* cmakeGeneratorName
  54. = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
  55. const char* cmakeProjectName
  56. = this->Makefile->GetDefinition("CTEST_PROJECT_NAME");
  57. const char* cmakeBuildConfiguration
  58. = this->Makefile->GetDefinition("CTEST_BUILD_CONFIGURATION");
  59. const char* cmakeBuildAdditionalFlags
  60. = this->Makefile->GetDefinition("CTEST_BUILD_FLAGS");
  61. const char* cmakeBuildTarget
  62. = this->Makefile->GetDefinition("CTEST_BUILD_TARGET");
  63. if ( cmakeGeneratorName && *cmakeGeneratorName &&
  64. cmakeProjectName && *cmakeProjectName )
  65. {
  66. if ( !cmakeBuildConfiguration )
  67. {
  68. cmakeBuildConfiguration = "Release";
  69. }
  70. if ( this->GlobalGenerator )
  71. {
  72. if ( strcmp(this->GlobalGenerator->GetName(),
  73. cmakeGeneratorName) != 0 )
  74. {
  75. delete this->GlobalGenerator;
  76. this->GlobalGenerator = 0;
  77. }
  78. }
  79. if ( !this->GlobalGenerator )
  80. {
  81. this->GlobalGenerator =
  82. this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
  83. cmakeGeneratorName);
  84. }
  85. this->GlobalGenerator->FindMakeProgram(this->Makefile);
  86. const char* cmakeMakeProgram
  87. = this->Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
  88. if(strlen(cmakeBuildConfiguration) == 0)
  89. {
  90. const char* config = 0;
  91. #ifdef CMAKE_INTDIR
  92. config = CMAKE_INTDIR;
  93. #endif
  94. if(!config)
  95. {
  96. config = "Debug";
  97. }
  98. cmakeBuildConfiguration = config;
  99. }
  100. std::string buildCommand
  101. = this->GlobalGenerator->
  102. GenerateBuildCommand(cmakeMakeProgram,
  103. cmakeProjectName,
  104. cmakeBuildAdditionalFlags, cmakeBuildTarget,
  105. cmakeBuildConfiguration, true, false);
  106. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  107. "SetMakeCommand:"
  108. << buildCommand.c_str() << "\n");
  109. this->CTest->SetCTestConfiguration("MakeCommand", buildCommand.c_str());
  110. }
  111. else
  112. {
  113. cmOStringStream ostr;
  114. ostr << "CTEST_BUILD_COMMAND or CTEST_CMAKE_GENERATOR not specified. "
  115. "Please specify the CTEST_CMAKE_GENERATOR and CTEST_PROJECT_NAME if "
  116. "this is a CMake project, or specify the CTEST_BUILD_COMMAND for "
  117. "cmake or any other project.";
  118. this->SetError(ostr.str().c_str());
  119. return 0;
  120. }
  121. }
  122. if(const char* useLaunchers =
  123. this->Makefile->GetDefinition("CTEST_USE_LAUNCHERS"))
  124. {
  125. this->CTest->SetCTestConfiguration("UseLaunchers", useLaunchers);
  126. }
  127. return handler;
  128. }
  129. bool cmCTestBuildCommand::InitialPass(std::vector<std::string> const& args,
  130. cmExecutionStatus &status)
  131. {
  132. bool ret = cmCTestHandlerCommand::InitialPass(args, status);
  133. if ( this->Values[ctb_NUMBER_ERRORS] && *this->Values[ctb_NUMBER_ERRORS])
  134. {
  135. cmOStringStream str;
  136. str << this->Handler->GetTotalErrors();
  137. this->Makefile->AddDefinition(
  138. this->Values[ctb_NUMBER_ERRORS], str.str().c_str());
  139. }
  140. if ( this->Values[ctb_NUMBER_WARNINGS]
  141. && *this->Values[ctb_NUMBER_WARNINGS])
  142. {
  143. cmOStringStream str;
  144. str << this->Handler->GetTotalWarnings();
  145. this->Makefile->AddDefinition(
  146. this->Values[ctb_NUMBER_WARNINGS], str.str().c_str());
  147. }
  148. return ret;
  149. }