ccmake.cxx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 cmDocumentationEntry cmDocumentationName[] =
  24. {
  25. {0,
  26. " ccmake - Curses Interface for CMake.", 0},
  27. {0,0,0}
  28. };
  29. //----------------------------------------------------------------------------
  30. static const cmDocumentationEntry cmDocumentationUsage[] =
  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 cmDocumentationEntry cmDocumentationDescription[] =
  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 cmDocumentationEntry cmDocumentationOptions[] =
  50. {
  51. CMAKE_STANDARD_OPTIONS_TABLE,
  52. {0,0,0}
  53. };
  54. //----------------------------------------------------------------------------
  55. static const cmDocumentationEntry cmDocumentationSeeAlso[] =
  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. cmDocumentation doc;
  91. if(doc.CheckOptions(argc, argv))
  92. {
  93. cmake hcm;
  94. std::vector<cmDocumentationEntry> commands;
  95. std::vector<cmDocumentationEntry> compatCommands;
  96. std::vector<cmDocumentationEntry> generators;
  97. hcm.GetCommandDocumentation(commands, true, false);
  98. hcm.GetCommandDocumentation(compatCommands, false, true);
  99. hcm.GetGeneratorDocumentation(generators);
  100. doc.SetName("ccmake");
  101. doc.SetNameSection(cmDocumentationName);
  102. doc.SetUsageSection(cmDocumentationUsage);
  103. doc.SetDescriptionSection(cmDocumentationDescription);
  104. doc.SetGeneratorsSection(&generators[0]);
  105. doc.SetOptionsSection(cmDocumentationOptions);
  106. doc.SetCommandsSection(&commands[0]);
  107. doc.SetCompatCommandsSection(&compatCommands[0]);
  108. doc.SetSeeAlsoList(cmDocumentationSeeAlso);
  109. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  110. }
  111. bool debug = false;
  112. unsigned int i;
  113. int j;
  114. std::vector<std::string> args;
  115. for(j =0; j < argc; ++j)
  116. {
  117. if(strcmp(argv[j], "-debug") == 0)
  118. {
  119. debug = true;
  120. }
  121. else
  122. {
  123. args.push_back(argv[j]);
  124. }
  125. }
  126. std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
  127. for(i=1; i < args.size(); ++i)
  128. {
  129. std::string arg = args[i];
  130. if(arg.find("-B",0) == 0)
  131. {
  132. cacheDir = arg.substr(2);
  133. }
  134. }
  135. cmSystemTools::DisableRunCommandOutput();
  136. if (debug)
  137. {
  138. cmCursesForm::DebugStart();
  139. }
  140. initscr(); /* Initialization */
  141. noecho(); /* Echo off */
  142. cbreak(); /* nl- or cr not needed */
  143. keypad(stdscr,TRUE); /* Use key symbols as
  144. KEY_DOWN*/
  145. signal(SIGWINCH, onsig);
  146. int x,y;
  147. getmaxyx(stdscr, y, x);
  148. if ( x < cmCursesMainForm::MIN_WIDTH ||
  149. y < cmCursesMainForm::MIN_HEIGHT )
  150. {
  151. endwin();
  152. std::cerr << "Window is too small. A size of at least "
  153. << cmCursesMainForm::MIN_WIDTH << " x "
  154. << cmCursesMainForm::MIN_HEIGHT
  155. << " is required to run ccmake." << std::endl;
  156. return 1;
  157. }
  158. cmCursesMainForm* myform;
  159. myform = new cmCursesMainForm(args, x);
  160. if(myform->LoadCache(cacheDir.c_str()))
  161. {
  162. curses_clear();
  163. touchwin(stdscr);
  164. endwin();
  165. delete myform;
  166. std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
  167. return 1;
  168. }
  169. cmSystemTools::SetErrorCallback(CMakeErrorHandler, myform);
  170. cmCursesForm::CurrentForm = myform;
  171. myform->InitializeUI();
  172. if ( myform->Configure(1) == 0 )
  173. {
  174. myform->Render(1, 1, x, y);
  175. myform->HandleInput();
  176. }
  177. // Need to clean-up better
  178. curses_clear();
  179. touchwin(stdscr);
  180. endwin();
  181. delete cmCursesForm::CurrentForm;
  182. cmCursesForm::CurrentForm = 0;
  183. std::cout << std::endl << std::endl;
  184. return 0;
  185. }