cmCTestConfigureCommand.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. cmCTestConfigureCommand::cmCTestConfigureCommand()
  17. {
  18. this->Arguments[ctc_OPTIONS] = "OPTIONS";
  19. this->Arguments[ctc_LAST] = 0;
  20. this->Last = ctc_LAST;
  21. }
  22. cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
  23. {
  24. std::vector<std::string> options;
  25. if (this->Values[ctc_OPTIONS])
  26. {
  27. cmSystemTools::ExpandListArgument(this->Values[ctc_OPTIONS], options);
  28. }
  29. if ( this->Values[ct_BUILD] )
  30. {
  31. this->CTest->SetCTestConfiguration("BuildDirectory",
  32. cmSystemTools::CollapseFullPath(
  33. this->Values[ct_BUILD]).c_str());
  34. }
  35. else
  36. {
  37. this->CTest->SetCTestConfiguration("BuildDirectory",
  38. cmSystemTools::CollapseFullPath(
  39. this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY")).c_str());
  40. }
  41. if ( this->Values[ct_SOURCE] )
  42. {
  43. this->CTest->SetCTestConfiguration("SourceDirectory",
  44. cmSystemTools::CollapseFullPath(
  45. this->Values[ct_SOURCE]).c_str());
  46. }
  47. else
  48. {
  49. this->CTest->SetCTestConfiguration("SourceDirectory",
  50. cmSystemTools::CollapseFullPath(
  51. this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
  52. }
  53. if ( this->CTest->GetCTestConfiguration("BuildDirectory").empty() )
  54. {
  55. this->SetError("Build directory not specified. Either use BUILD "
  56. "argument to CTEST_CONFIGURE command or set CTEST_BINARY_DIRECTORY "
  57. "variable");
  58. return 0;
  59. }
  60. const char* ctestConfigureCommand
  61. = this->Makefile->GetDefinition("CTEST_CONFIGURE_COMMAND");
  62. if ( ctestConfigureCommand && *ctestConfigureCommand )
  63. {
  64. this->CTest->SetCTestConfiguration("ConfigureCommand",
  65. ctestConfigureCommand);
  66. }
  67. else
  68. {
  69. const char* cmakeGeneratorName
  70. = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
  71. if ( cmakeGeneratorName && *cmakeGeneratorName )
  72. {
  73. const std::string& source_dir
  74. = this->CTest->GetCTestConfiguration("SourceDirectory");
  75. if ( source_dir.empty() )
  76. {
  77. this->SetError("Source directory not specified. Either use SOURCE "
  78. "argument to CTEST_CONFIGURE command or set CTEST_SOURCE_DIRECTORY "
  79. "variable");
  80. return 0;
  81. }
  82. std::string cmakeConfigureCommand = "\"";
  83. cmakeConfigureCommand += this->CTest->GetCMakeExecutable();
  84. cmakeConfigureCommand += "\"";
  85. std::vector<std::string>::const_iterator it;
  86. std::string option;
  87. for (it= options.begin(); it!=options.end(); ++it)
  88. {
  89. option = *it;
  90. cmakeConfigureCommand += " \"";
  91. cmakeConfigureCommand += option;
  92. cmakeConfigureCommand += "\"";
  93. }
  94. cmakeConfigureCommand += " \"-G";
  95. cmakeConfigureCommand += cmakeGeneratorName;
  96. cmakeConfigureCommand += "\"";
  97. cmakeConfigureCommand += " \"";
  98. cmakeConfigureCommand += source_dir;
  99. cmakeConfigureCommand += "\"";
  100. this->CTest->SetCTestConfiguration("ConfigureCommand",
  101. cmakeConfigureCommand.c_str());
  102. }
  103. else
  104. {
  105. this->SetError("Configure command is not specified. If this is a CMake "
  106. "project, specify CTEST_CMAKE_GENERATOR, or if this is not CMake "
  107. "project, specify CTEST_CONFIGURE_COMMAND.");
  108. return 0;
  109. }
  110. }
  111. cmCTestGenericHandler* handler
  112. = this->CTest->GetInitializedHandler("configure");
  113. if ( !handler )
  114. {
  115. this->SetError(
  116. "internal CTest error. Cannot instantiate configure handler");
  117. return 0;
  118. }
  119. return handler;
  120. }