CMakeSetup.cxx 6.4 KB

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