ccmake.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 "../cmCacheManager.h"
  11. #include "../cmSystemTools.h"
  12. #include "../cmake.h"
  13. #include "../cmDocumentation.h"
  14. #include <signal.h>
  15. #include <sys/ioctl.h>
  16. #include "cmCursesMainForm.h"
  17. #include "cmCursesStandardIncludes.h"
  18. #include <cmsys/Encoding.hxx>
  19. #include <form.h>
  20. //----------------------------------------------------------------------------
  21. static const char * cmDocumentationName[][2] =
  22. {
  23. {0,
  24. " ccmake - Curses Interface for CMake."},
  25. {0,0}
  26. };
  27. //----------------------------------------------------------------------------
  28. static const char * cmDocumentationUsage[][2] =
  29. {
  30. {0,
  31. " ccmake <path-to-source>\n"
  32. " ccmake <path-to-existing-build>"},
  33. {0,0}
  34. };
  35. //----------------------------------------------------------------------------
  36. static const char * cmDocumentationOptions[][2] =
  37. {
  38. CMAKE_STANDARD_OPTIONS_TABLE,
  39. {0,0}
  40. };
  41. cmCursesForm* cmCursesForm::CurrentForm=0;
  42. extern "C"
  43. {
  44. void onsig(int)
  45. {
  46. if (cmCursesForm::CurrentForm)
  47. {
  48. endwin();
  49. initscr(); /* Initialization */
  50. noecho(); /* Echo off */
  51. cbreak(); /* nl- or cr not needed */
  52. keypad(stdscr,TRUE); /* Use key symbols as
  53. KEY_DOWN*/
  54. refresh();
  55. int x,y;
  56. getmaxyx(stdscr, y, x);
  57. cmCursesForm::CurrentForm->Render(1,1,x,y);
  58. cmCursesForm::CurrentForm->UpdateStatusBar();
  59. }
  60. signal(SIGWINCH, onsig);
  61. }
  62. }
  63. void CMakeErrorHandler(const char* message, const char* title, bool&, void* clientData)
  64. {
  65. cmCursesForm* self = static_cast<cmCursesForm*>( clientData );
  66. self->AddError(message, title);
  67. }
  68. int main(int argc, char const* const* argv)
  69. {
  70. cmsys::Encoding::CommandLineArguments encoding_args =
  71. cmsys::Encoding::CommandLineArguments::Main(argc, argv);
  72. argc = encoding_args.argc();
  73. argv = encoding_args.argv();
  74. cmSystemTools::FindCMakeResources(argv[0]);
  75. cmDocumentation doc;
  76. doc.addCMakeStandardDocSections();
  77. if(doc.CheckOptions(argc, argv))
  78. {
  79. cmake hcm;
  80. hcm.AddCMakePaths();
  81. std::vector<cmDocumentationEntry> generators;
  82. hcm.GetGeneratorDocumentation(generators);
  83. doc.SetName("ccmake");
  84. doc.SetSection("Name",cmDocumentationName);
  85. doc.SetSection("Usage",cmDocumentationUsage);
  86. doc.SetSection("Generators",generators);
  87. doc.PrependSection("Options",cmDocumentationOptions);
  88. return doc.PrintRequestedDocumentation(std::cout)? 0:1;
  89. }
  90. bool debug = false;
  91. unsigned int i;
  92. int j;
  93. std::vector<std::string> args;
  94. for(j =0; j < argc; ++j)
  95. {
  96. if(strcmp(argv[j], "-debug") == 0)
  97. {
  98. debug = true;
  99. }
  100. else
  101. {
  102. args.push_back(argv[j]);
  103. }
  104. }
  105. std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
  106. for(i=1; i < args.size(); ++i)
  107. {
  108. std::string arg = args[i];
  109. if(arg.find("-B",0) == 0)
  110. {
  111. cacheDir = arg.substr(2);
  112. }
  113. }
  114. cmSystemTools::DisableRunCommandOutput();
  115. if (debug)
  116. {
  117. cmCursesForm::DebugStart();
  118. }
  119. initscr(); /* Initialization */
  120. noecho(); /* Echo off */
  121. cbreak(); /* nl- or cr not needed */
  122. keypad(stdscr,TRUE); /* Use key symbols as
  123. KEY_DOWN*/
  124. signal(SIGWINCH, onsig);
  125. int x,y;
  126. getmaxyx(stdscr, y, x);
  127. if ( x < cmCursesMainForm::MIN_WIDTH ||
  128. y < cmCursesMainForm::MIN_HEIGHT )
  129. {
  130. endwin();
  131. std::cerr << "Window is too small. A size of at least "
  132. << cmCursesMainForm::MIN_WIDTH << " x "
  133. << cmCursesMainForm::MIN_HEIGHT
  134. << " is required to run ccmake." << std::endl;
  135. return 1;
  136. }
  137. cmCursesMainForm* myform;
  138. myform = new cmCursesMainForm(args, x);
  139. if(myform->LoadCache(cacheDir.c_str()))
  140. {
  141. curses_clear();
  142. touchwin(stdscr);
  143. endwin();
  144. delete myform;
  145. std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
  146. return 1;
  147. }
  148. cmSystemTools::SetErrorCallback(CMakeErrorHandler, myform);
  149. cmCursesForm::CurrentForm = myform;
  150. myform->InitializeUI();
  151. if ( myform->Configure(1) == 0 )
  152. {
  153. myform->Render(1, 1, x, y);
  154. myform->HandleInput();
  155. }
  156. // Need to clean-up better
  157. curses_clear();
  158. touchwin(stdscr);
  159. endwin();
  160. delete cmCursesForm::CurrentForm;
  161. cmCursesForm::CurrentForm = 0;
  162. std::cout << std::endl << std::endl;
  163. return 0;
  164. }