ccmake.cxx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "../cmSystemTools.h"
  11. #include "../cmake.h"
  12. #include "../cmDocumentation.h"
  13. #include <signal.h>
  14. #include <sys/ioctl.h>
  15. #include "cmCursesMainForm.h"
  16. #include "cmCursesStandardIncludes.h"
  17. #include <cmsys/Encoding.hxx>
  18. #include <form.h>
  19. //----------------------------------------------------------------------------
  20. static const char * cmDocumentationName[][2] =
  21. {
  22. {0,
  23. " ccmake - Curses Interface for CMake."},
  24. {0,0}
  25. };
  26. //----------------------------------------------------------------------------
  27. static const char * cmDocumentationUsage[][2] =
  28. {
  29. {0,
  30. " ccmake <path-to-source>\n"
  31. " ccmake <path-to-existing-build>"},
  32. {0,
  33. "Specify a source directory to (re-)generate a build system for "
  34. "it in the current working directory. Specify an existing build "
  35. "directory to re-generate its build system."},
  36. {0,0}
  37. };
  38. //----------------------------------------------------------------------------
  39. static const char * cmDocumentationUsageNote[][2] =
  40. {
  41. {0,
  42. "Run 'ccmake --help' for more information."},
  43. {0,0}
  44. };
  45. //----------------------------------------------------------------------------
  46. static const char * cmDocumentationOptions[][2] =
  47. {
  48. CMAKE_STANDARD_OPTIONS_TABLE,
  49. {0,0}
  50. };
  51. cmCursesForm* cmCursesForm::CurrentForm=0;
  52. extern "C"
  53. {
  54. void onsig(int)
  55. {
  56. if (cmCursesForm::CurrentForm)
  57. {
  58. endwin();
  59. initscr(); /* Initialization */
  60. noecho(); /* Echo off */
  61. cbreak(); /* nl- or cr not needed */
  62. keypad(stdscr,TRUE); /* Use key symbols as
  63. KEY_DOWN*/
  64. refresh();
  65. int x,y;
  66. getmaxyx(stdscr, y, x);
  67. cmCursesForm::CurrentForm->Render(1,1,x,y);
  68. cmCursesForm::CurrentForm->UpdateStatusBar();
  69. }
  70. signal(SIGWINCH, onsig);
  71. }
  72. }
  73. void CMakeMessageHandler(const char* message, const char* title, bool&,
  74. void* clientData)
  75. {
  76. cmCursesForm* self = static_cast<cmCursesForm*>( clientData );
  77. self->AddError(message, title);
  78. }
  79. int main(int argc, char const* const* argv)
  80. {
  81. cmsys::Encoding::CommandLineArguments encoding_args =
  82. cmsys::Encoding::CommandLineArguments::Main(argc, argv);
  83. argc = encoding_args.argc();
  84. argv = encoding_args.argv();
  85. cmSystemTools::FindCMakeResources(argv[0]);
  86. cmDocumentation doc;
  87. doc.addCMakeStandardDocSections();
  88. if(doc.CheckOptions(argc, argv))
  89. {
  90. cmake hcm;
  91. hcm.SetHomeDirectory("");
  92. hcm.SetHomeOutputDirectory("");
  93. hcm.AddCMakePaths();
  94. std::vector<cmDocumentationEntry> generators;
  95. hcm.GetGeneratorDocumentation(generators);
  96. doc.SetName("ccmake");
  97. doc.SetSection("Name",cmDocumentationName);
  98. doc.SetSection("Usage",cmDocumentationUsage);
  99. if ( argc == 1 )
  100. {
  101. doc.AppendSection("Usage",cmDocumentationUsageNote);
  102. }
  103. doc.SetSection("Generators",generators);
  104. doc.PrependSection("Options",cmDocumentationOptions);
  105. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  106. }
  107. bool debug = false;
  108. unsigned int i;
  109. int j;
  110. std::vector<std::string> args;
  111. for(j =0; j < argc; ++j)
  112. {
  113. if(strcmp(argv[j], "-debug") == 0)
  114. {
  115. debug = true;
  116. }
  117. else
  118. {
  119. args.push_back(argv[j]);
  120. }
  121. }
  122. std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
  123. for(i=1; i < args.size(); ++i)
  124. {
  125. std::string arg = args[i];
  126. if(arg.find("-B",0) == 0)
  127. {
  128. cacheDir = arg.substr(2);
  129. }
  130. }
  131. cmSystemTools::DisableRunCommandOutput();
  132. if (debug)
  133. {
  134. cmCursesForm::DebugStart();
  135. }
  136. initscr(); /* Initialization */
  137. noecho(); /* Echo off */
  138. cbreak(); /* nl- or cr not needed */
  139. keypad(stdscr,TRUE); /* Use key symbols as
  140. KEY_DOWN*/
  141. signal(SIGWINCH, onsig);
  142. int x,y;
  143. getmaxyx(stdscr, y, x);
  144. if ( x < cmCursesMainForm::MIN_WIDTH ||
  145. y < cmCursesMainForm::MIN_HEIGHT )
  146. {
  147. endwin();
  148. std::cerr << "Window is too small. A size of at least "
  149. << cmCursesMainForm::MIN_WIDTH << " x "
  150. << cmCursesMainForm::MIN_HEIGHT
  151. << " is required to run ccmake." << std::endl;
  152. return 1;
  153. }
  154. cmCursesMainForm* myform;
  155. myform = new cmCursesMainForm(args, x);
  156. if(myform->LoadCache(cacheDir.c_str()))
  157. {
  158. curses_clear();
  159. touchwin(stdscr);
  160. endwin();
  161. delete myform;
  162. std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
  163. return 1;
  164. }
  165. cmSystemTools::SetMessageCallback(CMakeMessageHandler, myform);
  166. cmCursesForm::CurrentForm = myform;
  167. myform->InitializeUI();
  168. if ( myform->Configure(1) == 0 )
  169. {
  170. myform->Render(1, 1, x, y);
  171. myform->HandleInput();
  172. }
  173. // Need to clean-up better
  174. curses_clear();
  175. touchwin(stdscr);
  176. endwin();
  177. delete cmCursesForm::CurrentForm;
  178. cmCursesForm::CurrentForm = 0;
  179. std::cout << std::endl << std::endl;
  180. return 0;
  181. }