ccmake.cxx 5.6 KB

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