cmCTestConfigureCommand.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. #include "cmGlobalGenerator.h"
  14. cmCTestConfigureCommand::cmCTestConfigureCommand()
  15. {
  16. this->Arguments[ctc_OPTIONS] = "OPTIONS";
  17. this->Arguments[ctc_LAST] = 0;
  18. this->Last = ctc_LAST;
  19. }
  20. cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
  21. {
  22. std::vector<std::string> options;
  23. if (this->Values[ctc_OPTIONS])
  24. {
  25. cmSystemTools::ExpandListArgument(this->Values[ctc_OPTIONS], options);
  26. }
  27. if ( this->CTest->GetCTestConfiguration("BuildDirectory").empty() )
  28. {
  29. this->SetError("Build directory not specified. Either use BUILD "
  30. "argument to CTEST_CONFIGURE command or set CTEST_BINARY_DIRECTORY "
  31. "variable");
  32. return 0;
  33. }
  34. const char* ctestConfigureCommand
  35. = this->Makefile->GetDefinition("CTEST_CONFIGURE_COMMAND");
  36. if ( ctestConfigureCommand && *ctestConfigureCommand )
  37. {
  38. this->CTest->SetCTestConfiguration("ConfigureCommand",
  39. ctestConfigureCommand, this->Quiet);
  40. }
  41. else
  42. {
  43. const char* cmakeGeneratorName
  44. = this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
  45. if ( cmakeGeneratorName && *cmakeGeneratorName )
  46. {
  47. const std::string& source_dir
  48. = this->CTest->GetCTestConfiguration("SourceDirectory");
  49. if ( source_dir.empty() )
  50. {
  51. this->SetError("Source directory not specified. Either use SOURCE "
  52. "argument to CTEST_CONFIGURE command or set CTEST_SOURCE_DIRECTORY "
  53. "variable");
  54. return 0;
  55. }
  56. const std::string cmakelists_file = source_dir + "/CMakeLists.txt";
  57. if ( !cmSystemTools::FileExists(cmakelists_file.c_str()) )
  58. {
  59. std::ostringstream e;
  60. e << "CMakeLists.txt file does not exist ["
  61. << cmakelists_file << "]";
  62. this->SetError(e.str());
  63. return 0;
  64. }
  65. bool multiConfig = false;
  66. bool cmakeBuildTypeInOptions = false;
  67. cmGlobalGenerator *gg =
  68. this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
  69. cmakeGeneratorName);
  70. if(gg)
  71. {
  72. multiConfig = gg->IsMultiConfig();
  73. delete gg;
  74. }
  75. std::string cmakeConfigureCommand = "\"";
  76. cmakeConfigureCommand += cmSystemTools::GetCMakeCommand();
  77. cmakeConfigureCommand += "\"";
  78. std::vector<std::string>::const_iterator it;
  79. std::string option;
  80. for (it= options.begin(); it!=options.end(); ++it)
  81. {
  82. option = *it;
  83. cmakeConfigureCommand += " \"";
  84. cmakeConfigureCommand += option;
  85. cmakeConfigureCommand += "\"";
  86. if ((0 != strstr(option.c_str(), "CMAKE_BUILD_TYPE=")) ||
  87. (0 != strstr(option.c_str(), "CMAKE_BUILD_TYPE:STRING=")))
  88. {
  89. cmakeBuildTypeInOptions = true;
  90. }
  91. }
  92. if (!multiConfig && !cmakeBuildTypeInOptions &&
  93. !this->CTest->GetConfigType().empty())
  94. {
  95. cmakeConfigureCommand += " \"-DCMAKE_BUILD_TYPE:STRING=";
  96. cmakeConfigureCommand += this->CTest->GetConfigType();
  97. cmakeConfigureCommand += "\"";
  98. }
  99. cmakeConfigureCommand += " \"-G";
  100. cmakeConfigureCommand += cmakeGeneratorName;
  101. cmakeConfigureCommand += "\"";
  102. const char* cmakeGeneratorPlatform =
  103. this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR_PLATFORM");
  104. if(cmakeGeneratorPlatform && *cmakeGeneratorPlatform)
  105. {
  106. cmakeConfigureCommand += " \"-A";
  107. cmakeConfigureCommand += cmakeGeneratorPlatform;
  108. cmakeConfigureCommand += "\"";
  109. }
  110. const char* cmakeGeneratorToolset =
  111. this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR_TOOLSET");
  112. if(cmakeGeneratorToolset && *cmakeGeneratorToolset)
  113. {
  114. cmakeConfigureCommand += " \"-T";
  115. cmakeConfigureCommand += cmakeGeneratorToolset;
  116. cmakeConfigureCommand += "\"";
  117. }
  118. cmakeConfigureCommand += " \"";
  119. cmakeConfigureCommand += source_dir;
  120. cmakeConfigureCommand += "\"";
  121. this->CTest->SetCTestConfiguration("ConfigureCommand",
  122. cmakeConfigureCommand.c_str(), this->Quiet);
  123. }
  124. else
  125. {
  126. this->SetError("Configure command is not specified. If this is a "
  127. "\"built with CMake\" project, set CTEST_CMAKE_GENERATOR. If not, "
  128. "set CTEST_CONFIGURE_COMMAND.");
  129. return 0;
  130. }
  131. }
  132. cmCTestGenericHandler* handler
  133. = this->CTest->GetInitializedHandler("configure");
  134. if ( !handler )
  135. {
  136. this->SetError(
  137. "internal CTest error. Cannot instantiate configure handler");
  138. return 0;
  139. }
  140. handler->SetQuiet(this->Quiet);
  141. return handler;
  142. }