ccmake.cxx 5.0 KB

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