CMakeSetup.cxx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 "QCMake.h" // include to disable MS warnings
  11. #include <QApplication>
  12. #include <QFileInfo>
  13. #include <QDir>
  14. #include <QTranslator>
  15. #include <QLocale>
  16. #include "QMacInstallDialog.h"
  17. #ifdef Q_OS_WIN
  18. #include "windows.h" // for SetErrorMode
  19. #endif
  20. #include "CMakeSetupDialog.h"
  21. #include "cmDocumentation.h"
  22. #include "cmake.h"
  23. #include "cmVersion.h"
  24. #include <cmsys/CommandLineArguments.hxx>
  25. //----------------------------------------------------------------------------
  26. static const char * cmDocumentationName[][3] =
  27. {
  28. {0,
  29. " cmake-gui - CMake GUI.", 0},
  30. {0,0,0}
  31. };
  32. //----------------------------------------------------------------------------
  33. static const char * cmDocumentationUsage[][3] =
  34. {
  35. {0,
  36. " cmake-gui [options]\n"
  37. " cmake-gui [options] <path-to-source>\n"
  38. " cmake-gui [options] <path-to-existing-build>", 0},
  39. {0,0,0}
  40. };
  41. //----------------------------------------------------------------------------
  42. static const char * cmDocumentationDescription[][3] =
  43. {
  44. {0,
  45. "The \"cmake-gui\" executable is the CMake GUI. Project "
  46. "configuration settings may be specified interactively. "
  47. "Brief instructions are provided at the bottom of the "
  48. "window when the program is running.", 0},
  49. CMAKE_STANDARD_INTRODUCTION,
  50. {0,0,0}
  51. };
  52. //----------------------------------------------------------------------------
  53. static const char * cmDocumentationOptions[][3] =
  54. {
  55. {0,0,0}
  56. };
  57. int main(int argc, char** argv)
  58. {
  59. cmSystemTools::FindExecutableDirectory(argv[0]);
  60. // check docs first so that X is not need to get docs
  61. // do docs, if args were given
  62. cmDocumentation doc;
  63. if(argc >1 && doc.CheckOptions(argc, argv))
  64. {
  65. // Construct and print requested documentation.
  66. cmake hcm;
  67. hcm.AddCMakePaths();
  68. // just incase the install is bad avoid a seg fault
  69. const char* root = hcm.GetCacheDefinition("CMAKE_ROOT");
  70. if(root)
  71. {
  72. doc.SetCMakeRoot(root);
  73. }
  74. std::vector<cmDocumentationEntry> commands;
  75. std::vector<cmDocumentationEntry> compatCommands;
  76. std::map<std::string,cmDocumentationSection *> propDocs;
  77. std::vector<cmDocumentationEntry> generators;
  78. hcm.GetCommandDocumentation(commands, true, false);
  79. hcm.GetCommandDocumentation(compatCommands, false, true);
  80. hcm.GetGeneratorDocumentation(generators);
  81. hcm.GetPropertiesDocumentation(propDocs);
  82. doc.SetName("cmake");
  83. doc.SetSection("Name",cmDocumentationName);
  84. doc.SetSection("Usage",cmDocumentationUsage);
  85. doc.SetSection("Description",cmDocumentationDescription);
  86. doc.AppendSection("Generators",generators);
  87. doc.PrependSection("Options",cmDocumentationOptions);
  88. doc.SetSection("Commands",commands);
  89. doc.SetSection("Compatilbility Commands", compatCommands);
  90. doc.SetSections(propDocs);
  91. return (doc.PrintRequestedDocumentation(std::cout)? 0:1);
  92. }
  93. QApplication app(argc, argv);
  94. #ifdef Q_OS_WIN
  95. // QApplication changes error mode, let's put it back
  96. SetErrorMode(0);
  97. #endif
  98. // clean out standard Qt paths for plugins, which we don't use anyway
  99. // when creating Mac bundles, it potentially causes problems
  100. foreach(QString p, QApplication::libraryPaths())
  101. {
  102. QApplication::removeLibraryPath(p);
  103. }
  104. // if arg for install
  105. for(int i =0; i < argc; i++)
  106. {
  107. if(strcmp(argv[i], "--mac-install") == 0)
  108. {
  109. QMacInstallDialog setupdialog(0);
  110. setupdialog.exec();
  111. return 0;
  112. }
  113. }
  114. // tell the cmake library where cmake is
  115. QDir cmExecDir(QApplication::applicationDirPath());
  116. #if defined(Q_OS_MAC)
  117. cmExecDir.cd("../../../");
  118. #endif
  119. // pick up translation files if they exists in the data directory
  120. QDir translationsDir = cmExecDir;
  121. translationsDir.cd(".." CMAKE_DATA_DIR);
  122. translationsDir.cd("i18n");
  123. QTranslator translator;
  124. QString transfile = QString("cmake_%1").arg(QLocale::system().name());
  125. translator.load(transfile, translationsDir.path());
  126. app.installTranslator(&translator);
  127. // app setup
  128. app.setApplicationName("CMakeSetup");
  129. app.setOrganizationName("Kitware");
  130. app.setWindowIcon(QIcon(":/Icons/CMakeSetup.png"));
  131. CMakeSetupDialog dialog;
  132. dialog.show();
  133. cmsys::CommandLineArguments arg;
  134. arg.Initialize(argc, argv);
  135. std::string binaryDirectory;
  136. std::string sourceDirectory;
  137. typedef cmsys::CommandLineArguments argT;
  138. arg.AddArgument("-B", argT::CONCAT_ARGUMENT,
  139. &binaryDirectory, "Binary Directory");
  140. arg.AddArgument("-H", argT::CONCAT_ARGUMENT,
  141. &sourceDirectory, "Source Directory");
  142. // do not complain about unknown options
  143. arg.StoreUnusedArguments(true);
  144. arg.Parse();
  145. if(!sourceDirectory.empty() && !binaryDirectory.empty())
  146. {
  147. dialog.setSourceDirectory(sourceDirectory.c_str());
  148. dialog.setBinaryDirectory(binaryDirectory.c_str());
  149. }
  150. else
  151. {
  152. QStringList args = app.arguments();
  153. if(args.count() == 2)
  154. {
  155. QFileInfo buildFileInfo(args[1], "CMakeCache.txt");
  156. QFileInfo srcFileInfo(args[1], "CMakeLists.txt");
  157. if(buildFileInfo.exists())
  158. {
  159. dialog.setBinaryDirectory(buildFileInfo.absolutePath());
  160. }
  161. else if(srcFileInfo.exists())
  162. {
  163. dialog.setSourceDirectory(srcFileInfo.absolutePath());
  164. dialog.setBinaryDirectory(QDir::currentPath());
  165. }
  166. }
  167. }
  168. return app.exec();
  169. }