ccmake.cxx 4.8 KB

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