ccmake.cxx 4.9 KB

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