ccmake.cxx 5.3 KB

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