ccmake.cxx 5.5 KB

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