ccmake.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 KEY_DOWN */
  47. refresh();
  48. int x, y;
  49. getmaxyx(stdscr, y, x);
  50. cmCursesForm::CurrentForm->Render(1, 1, x, y);
  51. cmCursesForm::CurrentForm->UpdateStatusBar();
  52. }
  53. signal(SIGWINCH, onsig);
  54. }
  55. }
  56. void CMakeMessageHandler(const char* message, const char* title,
  57. bool& /*unused*/, void* clientData)
  58. {
  59. cmCursesForm* self = static_cast<cmCursesForm*>(clientData);
  60. self->AddError(message, title);
  61. }
  62. int main(int argc, char const* const* argv)
  63. {
  64. cmsys::Encoding::CommandLineArguments encoding_args =
  65. cmsys::Encoding::CommandLineArguments::Main(argc, argv);
  66. argc = encoding_args.argc();
  67. argv = encoding_args.argv();
  68. cmSystemTools::FindCMakeResources(argv[0]);
  69. cmDocumentation doc;
  70. doc.addCMakeStandardDocSections();
  71. if (doc.CheckOptions(argc, argv)) {
  72. cmake hcm(cmake::RoleInternal);
  73. hcm.SetHomeDirectory("");
  74. hcm.SetHomeOutputDirectory("");
  75. hcm.AddCMakePaths();
  76. std::vector<cmDocumentationEntry> generators;
  77. hcm.GetGeneratorDocumentation(generators);
  78. doc.SetName("ccmake");
  79. doc.SetSection("Name", cmDocumentationName);
  80. doc.SetSection("Usage", cmDocumentationUsage);
  81. if (argc == 1) {
  82. doc.AppendSection("Usage", cmDocumentationUsageNote);
  83. }
  84. doc.SetSection("Generators", generators);
  85. doc.PrependSection("Options", cmDocumentationOptions);
  86. return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1;
  87. }
  88. bool debug = false;
  89. unsigned int i;
  90. int j;
  91. std::vector<std::string> args;
  92. for (j = 0; j < argc; ++j) {
  93. if (strcmp(argv[j], "-debug") == 0) {
  94. debug = true;
  95. } else {
  96. args.push_back(argv[j]);
  97. }
  98. }
  99. std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
  100. for (i = 1; i < args.size(); ++i) {
  101. std::string arg = args[i];
  102. if (arg.find("-B", 0) == 0) {
  103. cacheDir = arg.substr(2);
  104. }
  105. }
  106. cmSystemTools::DisableRunCommandOutput();
  107. if (debug) {
  108. cmCursesForm::DebugStart();
  109. }
  110. initscr(); /* Initialization */
  111. noecho(); /* Echo off */
  112. cbreak(); /* nl- or cr not needed */
  113. keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
  114. signal(SIGWINCH, onsig);
  115. int x, y;
  116. getmaxyx(stdscr, y, x);
  117. if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {
  118. endwin();
  119. std::cerr << "Window is too small. A size of at least "
  120. << cmCursesMainForm::MIN_WIDTH << " x "
  121. << cmCursesMainForm::MIN_HEIGHT << " is required to run ccmake."
  122. << std::endl;
  123. return 1;
  124. }
  125. cmCursesMainForm* myform;
  126. myform = new cmCursesMainForm(args, x);
  127. if (myform->LoadCache(cacheDir.c_str())) {
  128. curses_clear();
  129. touchwin(stdscr);
  130. endwin();
  131. delete myform;
  132. std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
  133. return 1;
  134. }
  135. cmSystemTools::SetMessageCallback(CMakeMessageHandler, myform);
  136. cmCursesForm::CurrentForm = myform;
  137. myform->InitializeUI();
  138. if (myform->Configure(1) == 0) {
  139. myform->Render(1, 1, x, y);
  140. myform->HandleInput();
  141. }
  142. // Need to clean-up better
  143. curses_clear();
  144. touchwin(stdscr);
  145. endwin();
  146. delete cmCursesForm::CurrentForm;
  147. cmCursesForm::CurrentForm = CM_NULLPTR;
  148. std::cout << std::endl << std::endl;
  149. return 0;
  150. }