cmCTestConfigureCommand.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. RETURN_VALUE specified twice.");
  47. return false;
  48. }
  49. havereturn_variable = true;
  50. }
  51. else if(args[i] == "SOURCE")
  52. {
  53. if ( source_dir )
  54. {
  55. this->SetError("called with incorrect number of arguments. SOURCE specified twice.");
  56. return false;
  57. }
  58. havesource = true;
  59. }
  60. else if(args[i] == "BUILD")
  61. {
  62. if ( build_dir )
  63. {
  64. this->SetError("called with incorrect number of arguments. BUILD specified twice.");
  65. return false;
  66. }
  67. havebuild = true;
  68. }
  69. else
  70. {
  71. cmOStringStream str;
  72. str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << ".";
  73. this->SetError(str.str().c_str());
  74. return false;
  75. }
  76. }
  77. if ( source_dir )
  78. {
  79. m_CTest->SetCTestConfiguration("SourceDirectory", source_dir);
  80. }
  81. else
  82. {
  83. source_dir = m_Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY");
  84. }
  85. if ( build_dir )
  86. {
  87. m_CTest->SetCTestConfiguration("BuildDirectory", build_dir);
  88. }
  89. else
  90. {
  91. build_dir = m_Makefile->GetDefinition("CTEST_BINARY_DIRECTORY");
  92. if ( !build_dir )
  93. {
  94. this->SetError("Build directory not specified. Either use BUILD argument to CTEST_CONFIGURE command or set CTEST_BINARY_DIRECTORY variable");
  95. return false;
  96. }
  97. }
  98. const char* ctestConfigureCommand = m_Makefile->GetDefinition("CTEST_CONFIGURE_COMMAND");
  99. if ( ctestConfigureCommand && *ctestConfigureCommand )
  100. {
  101. m_CTest->SetCTestConfiguration("ConfigureCommand", ctestConfigureCommand);
  102. }
  103. else
  104. {
  105. const char* cmakeGeneratorName = m_Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
  106. if ( cmakeGeneratorName && *cmakeGeneratorName )
  107. {
  108. std::string cmakeConfigureCommand = "\"";
  109. cmakeConfigureCommand += m_CTest->GetCMakeExecutable();
  110. cmakeConfigureCommand += "\" \"-G";
  111. cmakeConfigureCommand += cmakeGeneratorName;
  112. cmakeConfigureCommand += "\" \"";
  113. cmakeConfigureCommand += source_dir;
  114. cmakeConfigureCommand += "\"";
  115. m_CTest->SetCTestConfiguration("ConfigureCommand", cmakeConfigureCommand.c_str());
  116. }
  117. else
  118. {
  119. this->SetError("Configure command is not specified. If this is a CMake project, specify CTEST_CMAKE_GENERATOR, or if this is not CMake project, specify CTEST_CONFIGURE_COMMAND.");
  120. return false;
  121. }
  122. }
  123. cmCTestGenericHandler* handler = m_CTest->GetInitializedHandler("configure");
  124. if ( !handler )
  125. {
  126. this->SetError("internal CTest error. Cannot instantiate configure handler");
  127. return false;
  128. }
  129. int res = handler->ProcessHandler();
  130. if ( res_var )
  131. {
  132. cmOStringStream str;
  133. str << res;
  134. m_Makefile->AddDefinition(res_var, str.str().c_str());
  135. }
  136. return true;
  137. }