ccmake.cxx 5.2 KB

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