cmCTestBuildCommand.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 "cmake.h"
  17. #include "cmGlobalGenerator.h"
  18. //----------------------------------------------------------------------------
  19. cmCTestBuildCommand::cmCTestBuildCommand()
  20. {
  21. this->GlobalGenerator = 0;
  22. }
  23. //----------------------------------------------------------------------------
  24. cmCTestBuildCommand::~cmCTestBuildCommand()
  25. {
  26. if ( this->GlobalGenerator )
  27. {
  28. delete this->GlobalGenerator;
  29. this->GlobalGenerator = 0;
  30. }
  31. }
  32. //----------------------------------------------------------------------------
  33. cmCTestGenericHandler* cmCTestBuildCommand::InitializeHandler()
  34. {
  35. cmCTestGenericHandler* handler
  36. = this->CTest->GetInitializedHandler("build");
  37. if ( !handler )
  38. {
  39. this->SetError("internal CTest error. Cannot instantiate build handler");
  40. return 0;
  41. }
  42. const char* ctestBuildCommand
  43. = this->Makefile->GetDefinition("CTEST_BUILD_COMMAND");
  44. if ( ctestBuildCommand && *ctestBuildCommand )
  45. {
  46. this->CTest->SetCTestConfiguration("MakeCommand", ctestBuildCommand);
  47. }
  48. else
  49. {
  50. const char* cmakeGeneratorName
  51. = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
  52. const char* cmakeProjectName
  53. = this->Makefile->GetDefinition("CTEST_PROJECT_NAME");
  54. const char* cmakeBuildConfiguration
  55. = this->Makefile->GetDefinition("CTEST_BUILD_CONFIGURATION");
  56. const char* cmakeBuildAdditionalFlags
  57. = this->Makefile->GetDefinition("CTEST_BUILD_FLAGS");
  58. const char* cmakeBuildTarget
  59. = this->Makefile->GetDefinition("CTEST_BUILD_TARGET");
  60. if ( cmakeGeneratorName && *cmakeGeneratorName &&
  61. cmakeProjectName && *cmakeProjectName )
  62. {
  63. if ( !cmakeBuildConfiguration )
  64. {
  65. cmakeBuildConfiguration = "Release";
  66. }
  67. if ( this->GlobalGenerator )
  68. {
  69. if ( strcmp(this->GlobalGenerator->GetName(),
  70. cmakeGeneratorName) != 0 )
  71. {
  72. delete this->GlobalGenerator;
  73. this->GlobalGenerator = 0;
  74. }
  75. }
  76. if ( !this->GlobalGenerator )
  77. {
  78. this->GlobalGenerator =
  79. this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
  80. cmakeGeneratorName);
  81. }
  82. this->GlobalGenerator->FindMakeProgram(this->Makefile);
  83. const char* cmakeMakeProgram
  84. = this->Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
  85. if(strlen(cmakeBuildConfiguration) == 0)
  86. {
  87. const char* config = 0;
  88. #ifdef CMAKE_INTDIR
  89. config = CMAKE_INTDIR;
  90. #endif
  91. if(!config)
  92. {
  93. config = "Debug";
  94. }
  95. cmakeBuildConfiguration = config;
  96. }
  97. std::string buildCommand
  98. = this->GlobalGenerator->
  99. GenerateBuildCommand(cmakeMakeProgram,
  100. cmakeProjectName,
  101. cmakeBuildAdditionalFlags, cmakeBuildTarget,
  102. cmakeBuildConfiguration, true, false);
  103. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  104. "SetMakeCommand:"
  105. << buildCommand.c_str() << "\n");
  106. this->CTest->SetCTestConfiguration("MakeCommand", buildCommand.c_str());
  107. }
  108. else
  109. {
  110. cmOStringStream ostr;
  111. ostr << "CTEST_BUILD_COMMAND or CTEST_CMAKE_GENERATOR not specified. "
  112. "Please specify the CTEST_CMAKE_GENERATOR and CTEST_PROJECT_NAME if "
  113. "this is a CMake project, or specify the CTEST_BUILD_COMMAND for "
  114. "cmake or any other project.";
  115. this->SetError(ostr.str().c_str());
  116. return 0;
  117. }
  118. }
  119. return handler;
  120. }