cmCTestBuildCommand.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. bool cmCTestBuildCommand::InitialPass(
  19. std::vector<std::string> const& args)
  20. {
  21. const char* build_dir = 0;
  22. const char* res_var = 0;
  23. bool havereturn_variable = false;
  24. bool havesource = false;
  25. for(size_t i=0; i < args.size(); ++i)
  26. {
  27. if ( havereturn_variable )
  28. {
  29. res_var = args[i].c_str();
  30. havereturn_variable = false;
  31. }
  32. else if ( havesource )
  33. {
  34. build_dir = args[i].c_str();
  35. havesource = false;
  36. }
  37. else if(args[i] == "RETURN_VALUE")
  38. {
  39. if ( res_var )
  40. {
  41. this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice.");
  42. return false;
  43. }
  44. havereturn_variable = true;
  45. }
  46. else if(args[i] == "BUILD")
  47. {
  48. if ( build_dir )
  49. {
  50. this->SetError("called with incorrect number of arguments. 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: " << args[i].c_str() << ".";
  59. this->SetError(str.str().c_str());
  60. return false;
  61. }
  62. }
  63. if ( build_dir )
  64. {
  65. m_CTest->SetCTestConfiguration("BuildDirectory", build_dir);
  66. }
  67. cmCTestGenericHandler* handler = m_CTest->GetHandler("build");
  68. if ( !handler )
  69. {
  70. this->SetError("internal CTest error. Cannot instantiate build handler");
  71. return false;
  72. }
  73. const char* ctestBuildCommand = m_Makefile->GetDefinition("CTEST_BUILD_COMMAND");
  74. if ( ctestBuildCommand && *ctestBuildCommand )
  75. {
  76. m_CTest->SetCTestConfiguration("MakeCommand", ctestBuildCommand);
  77. }
  78. else
  79. {
  80. const char* cmakeGeneratorName = m_Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
  81. const char* cmakeProjectName = m_Makefile->GetDefinition("CTEST_PROJECT_NAME");
  82. const char* cmakeBuildConfiguration = m_Makefile->GetDefinition("CTEST_BUILD_CONFIGURATION");
  83. if ( cmakeGeneratorName && *cmakeGeneratorName &&
  84. cmakeProjectName && *cmakeProjectName )
  85. {
  86. if ( !cmakeBuildConfiguration )
  87. {
  88. cmakeBuildConfiguration = "Release";
  89. }
  90. cmGlobalGenerator* gen =
  91. m_Makefile->GetCMakeInstance()->CreateGlobalGenerator(cmakeGeneratorName);
  92. gen->FindMakeProgram(m_Makefile);
  93. const char* cmakeMakeProgram = m_Makefile->GetDefinition("CMAKE_MAKE_PROGRAM");
  94. std::string buildCommand = gen->GenerateBuildCommand(cmakeMakeProgram, cmakeProjectName,
  95. 0, cmakeBuildConfiguration, true);
  96. m_CTest->SetCTestConfiguration("MakeCommand", buildCommand.c_str());
  97. }
  98. else
  99. {
  100. cmOStringStream ostr;
  101. ostr << "CTEST_BUILD_COMMAND or CTEST_CMAKE_GENERATOR not specified. Please specify the CTEST_CMAKE_GENERATOR if this is a CMake project, or specify the CTEST_BUILD_COMMAND for cmake or any other project.";
  102. this->SetError(ostr.str().c_str());
  103. return false;
  104. }
  105. }
  106. int res = handler->ProcessHandler();
  107. if ( res_var )
  108. {
  109. cmOStringStream str;
  110. str << res;
  111. m_Makefile->AddDefinition(res_var, str.str().c_str());
  112. }
  113. return true;
  114. }