cmCTestConfigureCommand.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 "cmCTestConfigureCommand.h"
  14. #include "cmCTest.h"
  15. #include "cmCTestGenericHandler.h"
  16. bool cmCTestConfigureCommand::InitialPass(
  17. std::vector<std::string> const& args)
  18. {
  19. const char* source_dir = 0;
  20. const char* build_dir = 0;
  21. const char* res_var = 0;
  22. bool havereturn_variable = false;
  23. bool havesource = false;
  24. bool havebuild = 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 ( havebuild )
  33. {
  34. build_dir = args[i].c_str();
  35. havebuild = false;
  36. }
  37. else if ( havesource )
  38. {
  39. source_dir = args[i].c_str();
  40. havesource = false;
  41. }
  42. else if(args[i] == "RETURN_VALUE")
  43. {
  44. if ( res_var )
  45. {
  46. this->SetError("called with incorrect number of arguments. "
  47. "RETURN_VALUE specified twice.");
  48. return false;
  49. }
  50. havereturn_variable = true;
  51. }
  52. else if(args[i] == "SOURCE")
  53. {
  54. if ( source_dir )
  55. {
  56. this->SetError("called with incorrect number of arguments. "
  57. "SOURCE specified twice.");
  58. return false;
  59. }
  60. havesource = true;
  61. }
  62. else if(args[i] == "BUILD")
  63. {
  64. if ( build_dir )
  65. {
  66. this->SetError("called with incorrect number of arguments. "
  67. "BUILD specified twice.");
  68. return false;
  69. }
  70. havebuild = true;
  71. }
  72. else
  73. {
  74. cmOStringStream str;
  75. str << "called with incorrect number of arguments. Extra argument is: "
  76. << args[i].c_str() << ".";
  77. this->SetError(str.str().c_str());
  78. return false;
  79. }
  80. }
  81. if ( source_dir )
  82. {
  83. this->CTest->SetCTestConfiguration("SourceDirectory", source_dir);
  84. }
  85. else
  86. {
  87. source_dir = this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
  88. }
  89. if ( build_dir )
  90. {
  91. this->CTest->SetCTestConfiguration("BuildDirectory", build_dir);
  92. }
  93. else
  94. {
  95. build_dir = this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY");
  96. if ( !build_dir )
  97. {
  98. this->SetError("Build directory not specified. Either use BUILD "
  99. "argument to CTEST_CONFIGURE command or set CTEST_BINARY_DIRECTORY "
  100. "variable");
  101. return false;
  102. }
  103. }
  104. const char* ctestConfigureCommand
  105. = this->Makefile->GetDefinition("CTEST_CONFIGURE_COMMAND");
  106. if ( ctestConfigureCommand && *ctestConfigureCommand )
  107. {
  108. this->CTest->SetCTestConfiguration("ConfigureCommand",
  109. ctestConfigureCommand);
  110. }
  111. else
  112. {
  113. const char* cmakeGeneratorName
  114. = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
  115. if ( cmakeGeneratorName && *cmakeGeneratorName )
  116. {
  117. std::string cmakeConfigureCommand = "\"";
  118. cmakeConfigureCommand += this->CTest->GetCMakeExecutable();
  119. cmakeConfigureCommand += "\" \"-G";
  120. cmakeConfigureCommand += cmakeGeneratorName;
  121. cmakeConfigureCommand += "\" \"";
  122. cmakeConfigureCommand += source_dir;
  123. cmakeConfigureCommand += "\"";
  124. this->CTest->SetCTestConfiguration("ConfigureCommand",
  125. cmakeConfigureCommand.c_str());
  126. }
  127. else
  128. {
  129. this->SetError("Configure command is not specified. If this is a CMake "
  130. "project, specify CTEST_CMAKE_GENERATOR, or if this is not CMake "
  131. "project, specify CTEST_CONFIGURE_COMMAND.");
  132. return false;
  133. }
  134. }
  135. cmCTestGenericHandler* handler
  136. = this->CTest->GetInitializedHandler("configure");
  137. if ( !handler )
  138. {
  139. this->SetError(
  140. "internal CTest error. Cannot instantiate configure handler");
  141. return false;
  142. }
  143. int res = handler->ProcessHandler();
  144. if ( res_var )
  145. {
  146. cmOStringStream str;
  147. str << res;
  148. this->Makefile->AddDefinition(res_var, str.str().c_str());
  149. }
  150. return true;
  151. }