ccmake.cxx 5.2 KB

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