1
0

ccmake.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include <cmConfigure.h>
  4. #include "cmCursesForm.h"
  5. #include "cmCursesMainForm.h"
  6. #include "cmCursesStandardIncludes.h"
  7. #include "cmDocumentation.h"
  8. #include "cmDocumentationEntry.h"
  9. #include "cmSystemTools.h"
  10. #include "cmake.h"
  11. #include <cmsys/Encoding.hxx>
  12. #include <iostream>
  13. #include <signal.h>
  14. #include <string.h>
  15. #include <string>
  16. #include <vector>
  17. static const char* cmDocumentationName[][2] = {
  18. { CM_NULLPTR, " ccmake - Curses Interface for CMake." },
  19. { CM_NULLPTR, CM_NULLPTR }
  20. };
  21. static const char* cmDocumentationUsage[][2] = {
  22. { CM_NULLPTR, " ccmake <path-to-source>\n"
  23. " ccmake <path-to-existing-build>" },
  24. { CM_NULLPTR,
  25. "Specify a source directory to (re-)generate a build system for "
  26. "it in the current working directory. Specify an existing build "
  27. "directory to re-generate its build system." },
  28. { CM_NULLPTR, CM_NULLPTR }
  29. };
  30. static const char* cmDocumentationUsageNote[][2] = {
  31. { CM_NULLPTR, "Run 'ccmake --help' for more information." },
  32. { CM_NULLPTR, CM_NULLPTR }
  33. };
  34. static const char* cmDocumentationOptions[]
  35. [2] = { CMAKE_STANDARD_OPTIONS_TABLE,
  36. { CM_NULLPTR, CM_NULLPTR } };
  37. cmCursesForm* cmCursesForm::CurrentForm = CM_NULLPTR;
  38. extern "C" {
  39. void onsig(int /*unused*/)
  40. {
  41. if (cmCursesForm::CurrentForm) {
  42. endwin();
  43. initscr(); /* Initialization */
  44. noecho(); /* Echo off */
  45. cbreak(); /* nl- or cr not needed */
  46. keypad(stdscr, TRUE); /* Use key symbols as
  47. KEY_DOWN*/
  48. refresh();
  49. int x, y;
  50. getmaxyx(stdscr, y, x);
  51. cmCursesForm::CurrentForm->Render(1, 1, x, y);
  52. cmCursesForm::CurrentForm->UpdateStatusBar();
  53. }
  54. signal(SIGWINCH, onsig);
  55. }
  56. }
  57. void CMakeMessageHandler(const char* message, const char* title,
  58. bool& /*unused*/, void* clientData)
  59. {
  60. cmCursesForm* self = static_cast<cmCursesForm*>(clientData);
  61. self->AddError(message, title);
  62. }
  63. int main(int argc, char const* const* argv)
  64. {
  65. cmsys::Encoding::CommandLineArguments encoding_args =
  66. cmsys::Encoding::CommandLineArguments::Main(argc, argv);
  67. argc = encoding_args.argc();
  68. argv = encoding_args.argv();
  69. cmSystemTools::FindCMakeResources(argv[0]);
  70. cmDocumentation doc;
  71. doc.addCMakeStandardDocSections();
  72. if (doc.CheckOptions(argc, argv)) {
  73. cmake hcm;
  74. hcm.SetHomeDirectory("");
  75. hcm.SetHomeOutputDirectory("");
  76. hcm.AddCMakePaths();
  77. std::vector<cmDocumentationEntry> generators;
  78. hcm.GetGeneratorDocumentation(generators);
  79. doc.SetName("ccmake");
  80. doc.SetSection("Name", cmDocumentationName);
  81. doc.SetSection("Usage", cmDocumentationUsage);
  82. if (argc == 1) {
  83. doc.AppendSection("Usage", cmDocumentationUsageNote);
  84. }
  85. doc.SetSection("Generators", generators);
  86. doc.PrependSection("Options", cmDocumentationOptions);
  87. return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1;
  88. }
  89. bool debug = false;
  90. unsigned int i;
  91. int j;
  92. std::vector<std::string> args;
  93. for (j = 0; j < argc; ++j) {
  94. if (strcmp(argv[j], "-debug") == 0) {
  95. debug = true;
  96. } else {
  97. args.push_back(argv[j]);
  98. }
  99. }
  100. std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
  101. for (i = 1; i < args.size(); ++i) {
  102. std::string arg = args[i];
  103. if (arg.find("-B", 0) == 0) {
  104. cacheDir = arg.substr(2);
  105. }
  106. }
  107. cmSystemTools::DisableRunCommandOutput();
  108. if (debug) {
  109. cmCursesForm::DebugStart();
  110. }
  111. initscr(); /* Initialization */
  112. noecho(); /* Echo off */
  113. cbreak(); /* nl- or cr not needed */
  114. keypad(stdscr, TRUE); /* Use key symbols as
  115. KEY_DOWN*/
  116. signal(SIGWINCH, onsig);
  117. int x, y;
  118. getmaxyx(stdscr, y, x);
  119. if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {
  120. endwin();
  121. std::cerr << "Window is too small. A size of at least "
  122. << cmCursesMainForm::MIN_WIDTH << " x "
  123. << cmCursesMainForm::MIN_HEIGHT << " is required to run ccmake."
  124. << std::endl;
  125. return 1;
  126. }
  127. cmCursesMainForm* myform;
  128. myform = new cmCursesMainForm(args, x);
  129. if (myform->LoadCache(cacheDir.c_str())) {
  130. curses_clear();
  131. touchwin(stdscr);
  132. endwin();
  133. delete myform;
  134. std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
  135. return 1;
  136. }
  137. cmSystemTools::SetMessageCallback(CMakeMessageHandler, myform);
  138. cmCursesForm::CurrentForm = myform;
  139. myform->InitializeUI();
  140. if (myform->Configure(1) == 0) {
  141. myform->Render(1, 1, x, y);
  142. myform->HandleInput();
  143. }
  144. // Need to clean-up better
  145. curses_clear();
  146. touchwin(stdscr);
  147. endwin();
  148. delete cmCursesForm::CurrentForm;
  149. cmCursesForm::CurrentForm = CM_NULLPTR;
  150. std::cout << std::endl << std::endl;
  151. return 0;
  152. }