cmCTestBuildCommand.cxx 5.2 KB

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