cmCTestConfigureCommand.cxx 3.5 KB

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