cmCTestConfigureCommand.cxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestConfigureCommand.h"
  11. #include "cmCTest.h"
  12. #include "cmCTestGenericHandler.h"
  13. cmCTestConfigureCommand::cmCTestConfigureCommand()
  14. {
  15. this->Arguments[ctc_OPTIONS] = "OPTIONS";
  16. this->Arguments[ctc_LAST] = 0;
  17. this->Last = ctc_LAST;
  18. }
  19. cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
  20. {
  21. std::vector<std::string> options;
  22. if (this->Values[ctc_OPTIONS])
  23. {
  24. cmSystemTools::ExpandListArgument(this->Values[ctc_OPTIONS], options);
  25. }
  26. if ( this->Values[ct_BUILD] )
  27. {
  28. this->CTest->SetCTestConfiguration("BuildDirectory",
  29. cmSystemTools::CollapseFullPath(
  30. this->Values[ct_BUILD]).c_str());
  31. }
  32. else
  33. {
  34. this->CTest->SetCTestConfiguration("BuildDirectory",
  35. cmSystemTools::CollapseFullPath(
  36. this->Makefile->GetDefinition("CTEST_BINARY_DIRECTORY")).c_str());
  37. }
  38. if ( this->Values[ct_SOURCE] )
  39. {
  40. this->CTest->SetCTestConfiguration("SourceDirectory",
  41. cmSystemTools::CollapseFullPath(
  42. this->Values[ct_SOURCE]).c_str());
  43. }
  44. else
  45. {
  46. this->CTest->SetCTestConfiguration("SourceDirectory",
  47. cmSystemTools::CollapseFullPath(
  48. this->Makefile->GetDefinition("CTEST_SOURCE_DIRECTORY")).c_str());
  49. }
  50. if ( this->CTest->GetCTestConfiguration("BuildDirectory").empty() )
  51. {
  52. this->SetError("Build directory not specified. Either use BUILD "
  53. "argument to CTEST_CONFIGURE command or set CTEST_BINARY_DIRECTORY "
  54. "variable");
  55. return 0;
  56. }
  57. const char* ctestConfigureCommand
  58. = this->Makefile->GetDefinition("CTEST_CONFIGURE_COMMAND");
  59. if ( ctestConfigureCommand && *ctestConfigureCommand )
  60. {
  61. this->CTest->SetCTestConfiguration("ConfigureCommand",
  62. ctestConfigureCommand);
  63. }
  64. else
  65. {
  66. const char* cmakeGeneratorName
  67. = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
  68. if ( cmakeGeneratorName && *cmakeGeneratorName )
  69. {
  70. const std::string& source_dir
  71. = this->CTest->GetCTestConfiguration("SourceDirectory");
  72. if ( source_dir.empty() )
  73. {
  74. this->SetError("Source directory not specified. Either use SOURCE "
  75. "argument to CTEST_CONFIGURE command or set CTEST_SOURCE_DIRECTORY "
  76. "variable");
  77. return 0;
  78. }
  79. std::string cmakeConfigureCommand = "\"";
  80. cmakeConfigureCommand += this->CTest->GetCMakeExecutable();
  81. cmakeConfigureCommand += "\"";
  82. std::vector<std::string>::const_iterator it;
  83. std::string option;
  84. for (it= options.begin(); it!=options.end(); ++it)
  85. {
  86. option = *it;
  87. cmakeConfigureCommand += " \"";
  88. cmakeConfigureCommand += option;
  89. cmakeConfigureCommand += "\"";
  90. }
  91. cmakeConfigureCommand += " \"-G";
  92. cmakeConfigureCommand += cmakeGeneratorName;
  93. cmakeConfigureCommand += "\"";
  94. cmakeConfigureCommand += " \"";
  95. cmakeConfigureCommand += source_dir;
  96. cmakeConfigureCommand += "\"";
  97. this->CTest->SetCTestConfiguration("ConfigureCommand",
  98. cmakeConfigureCommand.c_str());
  99. }
  100. else
  101. {
  102. this->SetError("Configure command is not specified. If this is a CMake "
  103. "project, specify CTEST_CMAKE_GENERATOR, or if this is not CMake "
  104. "project, specify CTEST_CONFIGURE_COMMAND.");
  105. return 0;
  106. }
  107. }
  108. cmCTestGenericHandler* handler
  109. = this->CTest->GetInitializedHandler("configure");
  110. if ( !handler )
  111. {
  112. this->SetError(
  113. "internal CTest error. Cannot instantiate configure handler");
  114. return 0;
  115. }
  116. return handler;
  117. }