cmCTestConfigureCommand.cxx 3.3 KB

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