cmCTestBuildCommand.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. if ( cmakeGeneratorName && *cmakeGeneratorName &&
  59. cmakeProjectName && *cmakeProjectName )
  60. {
  61. if ( !cmakeBuildConfiguration )
  62. {
  63. cmakeBuildConfiguration = "Release";
  64. }
  65. if ( this->GlobalGenerator )
  66. {
  67. if ( strcmp(this->GlobalGenerator->GetName(),
  68. cmakeGeneratorName) != 0 )
  69. {
  70. delete this->GlobalGenerator;
  71. this->GlobalGenerator = 0;
  72. }
  73. }
  74. if ( !this->GlobalGenerator )
  75. {
  76. this->GlobalGenerator =
  77. this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
  78. cmakeGeneratorName);
  79. }
  80. this->GlobalGenerator->FindMakeProgram(this->Makefile);
  81. const char* cmakeMakeProgram
  82. = this->Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
  83. std::string buildCommand
  84. = this->GlobalGenerator->GenerateBuildCommand(cmakeMakeProgram,
  85. cmakeProjectName,
  86. cmakeBuildAdditionalFlags, 0, cmakeBuildConfiguration, true);
  87. this->CTest->SetCTestConfiguration("MakeCommand", buildCommand.c_str());
  88. }
  89. else
  90. {
  91. cmOStringStream ostr;
  92. ostr << "CTEST_BUILD_COMMAND or CTEST_CMAKE_GENERATOR not specified. "
  93. "Please specify the CTEST_CMAKE_GENERATOR and CTEST_PROJECT_NAME if "
  94. "this is a CMake project, or specify the CTEST_BUILD_COMMAND for "
  95. "cmake or any other project.";
  96. this->SetError(ostr.str().c_str());
  97. return 0;
  98. }
  99. }
  100. return handler;
  101. }