ccmake.cxx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 "../cmCacheManager.h"
  11. #include "../cmSystemTools.h"
  12. #include "../cmake.h"
  13. #include "../cmDocumentation.h"
  14. #include <signal.h>
  15. #include <sys/ioctl.h>
  16. #include "cmCursesMainForm.h"
  17. #include "cmCursesStandardIncludes.h"
  18. #include <form.h>
  19. //----------------------------------------------------------------------------
  20. static const char * cmDocumentationName[][3] =
  21. {
  22. {0,
  23. " ccmake - Curses Interface for CMake.", 0},
  24. {0,0,0}
  25. };
  26. //----------------------------------------------------------------------------
  27. static const char * cmDocumentationUsage[][3] =
  28. {
  29. {0,
  30. " ccmake <path-to-source>\n"
  31. " ccmake <path-to-existing-build>", 0},
  32. {0,0,0}
  33. };
  34. //----------------------------------------------------------------------------
  35. static const char * cmDocumentationDescription[][3] =
  36. {
  37. {0,
  38. "The \"ccmake\" executable is the CMake curses interface. Project "
  39. "configuration settings may be specified interactively through "
  40. "this GUI. Brief instructions are provided at the bottom of the "
  41. "terminal when the program is running.", 0},
  42. CMAKE_STANDARD_INTRODUCTION,
  43. {0,0,0}
  44. };
  45. //----------------------------------------------------------------------------
  46. static const char * cmDocumentationOptions[][3] =
  47. {
  48. CMAKE_STANDARD_OPTIONS_TABLE,
  49. {0,0,0}
  50. };
  51. //----------------------------------------------------------------------------
  52. static const char * cmDocumentationSeeAlso[][3] =
  53. {
  54. {0, "cmake", 0},
  55. {0, "ctest", 0},
  56. {0, 0, 0}
  57. };
  58. cmCursesForm* cmCursesForm::CurrentForm=0;
  59. extern "C"
  60. {
  61. void onsig(int)
  62. {
  63. if (cmCursesForm::CurrentForm)
  64. {
  65. endwin();
  66. initscr(); /* Initialization */
  67. noecho(); /* Echo off */
  68. cbreak(); /* nl- or cr not needed */
  69. keypad(stdscr,TRUE); /* Use key symbols as
  70. KEY_DOWN*/
  71. refresh();
  72. int x,y;
  73. getmaxyx(stdscr, y, x);
  74. cmCursesForm::CurrentForm->Render(1,1,x,y);
  75. cmCursesForm::CurrentForm->UpdateStatusBar();
  76. }
  77. signal(SIGWINCH, onsig);
  78. }
  79. }
  80. void CMakeErrorHandler(const char* message, const char* title, bool&, void* clientData)
  81. {
  82. cmCursesForm* self = static_cast<cmCursesForm*>( clientData );
  83. self->AddError(message, title);
  84. }
  85. int main(int argc, char** argv)
  86. {
  87. cmSystemTools::FindExecutableDirectory(argv[0]);
  88. cmDocumentation doc;
  89. if(doc.CheckOptions(argc, argv))
  90. {
  91. cmake hcm;
  92. std::vector<cmDocumentationEntry> commands;
  93. std::vector<cmDocumentationEntry> compatCommands;
  94. std::vector<cmDocumentationEntry> generators;
  95. hcm.GetCommandDocumentation(commands, true, false);
  96. hcm.GetCommandDocumentation(compatCommands, false, true);
  97. hcm.GetGeneratorDocumentation(generators);
  98. doc.SetName("ccmake");
  99. doc.SetSection("Name",cmDocumentationName);
  100. doc.SetSection("Usage",cmDocumentationUsage);
  101. doc.SetSection("Description",cmDocumentationDescription);
  102. doc.SetSection("Generators",generators);
  103. doc.SetSection("Options",cmDocumentationOptions);
  104. doc.SetSection("Command",commands);
  105. doc.SetSection("Compatibility Commands",compatCommands);
  106. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  107. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  108. }
  109. bool debug = false;
  110. unsigned int i;
  111. int j;
  112. std::vector<std::string> args;
  113. for(j =0; j < argc; ++j)
  114. {
  115. if(strcmp(argv[j], "-debug") == 0)
  116. {
  117. debug = true;
  118. }
  119. else
  120. {
  121. args.push_back(argv[j]);
  122. }
  123. }
  124. std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
  125. for(i=1; i < args.size(); ++i)
  126. {
  127. std::string arg = args[i];
  128. if(arg.find("-B",0) == 0)
  129. {
  130. cacheDir = arg.substr(2);
  131. }
  132. }
  133. cmSystemTools::DisableRunCommandOutput();
  134. if (debug)
  135. {
  136. cmCursesForm::DebugStart();
  137. }
  138. initscr(); /* Initialization */
  139. noecho(); /* Echo off */
  140. cbreak(); /* nl- or cr not needed */
  141. keypad(stdscr,TRUE); /* Use key symbols as
  142. KEY_DOWN*/
  143. signal(SIGWINCH, onsig);
  144. int x,y;
  145. getmaxyx(stdscr, y, x);
  146. if ( x < cmCursesMainForm::MIN_WIDTH ||
  147. y < cmCursesMainForm::MIN_HEIGHT )
  148. {
  149. endwin();
  150. std::cerr << "Window is too small. A size of at least "
  151. << cmCursesMainForm::MIN_WIDTH << " x "
  152. << cmCursesMainForm::MIN_HEIGHT
  153. << " is required to run ccmake." << std::endl;
  154. return 1;
  155. }
  156. cmCursesMainForm* myform;
  157. myform = new cmCursesMainForm(args, x);
  158. if(myform->LoadCache(cacheDir.c_str()))
  159. {
  160. curses_clear();
  161. touchwin(stdscr);
  162. endwin();
  163. delete myform;
  164. std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
  165. return 1;
  166. }
  167. cmSystemTools::SetErrorCallback(CMakeErrorHandler, myform);
  168. cmCursesForm::CurrentForm = myform;
  169. myform->InitializeUI();
  170. if ( myform->Configure(1) == 0 )
  171. {
  172. myform->Render(1, 1, x, y);
  173. myform->HandleInput();
  174. }
  175. // Need to clean-up better
  176. curses_clear();
  177. touchwin(stdscr);
  178. endwin();
  179. delete cmCursesForm::CurrentForm;
  180. cmCursesForm::CurrentForm = 0;
  181. std::cout << std::endl << std::endl;
  182. return 0;
  183. }