CMakeSetup.cxx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. if(argc >1 && doc.CheckOptions(argc, argv))
  61. {
  62. // Construct and print requested documentation.
  63. cmake hcm;
  64. hcm.AddCMakePaths();
  65. // just incase the install is bad avoid a seg fault
  66. const char* root = hcm.GetCacheDefinition("CMAKE_ROOT");
  67. if(root)
  68. {
  69. doc.SetCMakeRoot(root);
  70. }
  71. std::vector<cmDocumentationEntry> commands;
  72. std::vector<cmDocumentationEntry> compatCommands;
  73. std::map<std::string,cmDocumentationSection *> propDocs;
  74. std::vector<cmDocumentationEntry> generators;
  75. hcm.GetCommandDocumentation(commands, true, false);
  76. hcm.GetCommandDocumentation(compatCommands, false, true);
  77. hcm.GetGeneratorDocumentation(generators);
  78. hcm.GetPropertiesDocumentation(propDocs);
  79. doc.SetName("cmake");
  80. doc.SetSection("Name",cmDocumentationName);
  81. doc.SetSection("Usage",cmDocumentationUsage);
  82. doc.SetSection("Description",cmDocumentationDescription);
  83. doc.AppendSection("Generators",generators);
  84. doc.PrependSection("Options",cmDocumentationOptions);
  85. doc.SetSection("Commands",commands);
  86. doc.SetSection("Compatilbility Commands", compatCommands);
  87. doc.SetSections(propDocs);
  88. return (doc.PrintRequestedDocumentation(std::cout)? 0:1);
  89. }
  90. QApplication app(argc, argv);
  91. // clean out standard Qt paths for plugins, which we don't use anyway
  92. // when creating Mac bundles, it potentially causes problems
  93. foreach(QString p, QApplication::libraryPaths())
  94. {
  95. QApplication::removeLibraryPath(p);
  96. }
  97. // if arg for install
  98. for(int i =0; i < argc; i++)
  99. {
  100. if(strcmp(argv[i], "--mac-install") == 0)
  101. {
  102. QMacInstallDialog setupdialog(0);
  103. setupdialog.exec();
  104. return 0;
  105. }
  106. }
  107. // tell the cmake library where cmake is
  108. QDir cmExecDir(QApplication::applicationDirPath());
  109. #if defined(Q_OS_MAC)
  110. cmExecDir.cd("../../../");
  111. #endif
  112. // pick up translation files if they exists in the data directory
  113. QDir translationsDir = cmExecDir;
  114. translationsDir.cd(".." CMAKE_DATA_DIR);
  115. translationsDir.cd("i18n");
  116. QTranslator translator;
  117. QString transfile = QString("cmake_%1").arg(QLocale::system().name());
  118. translator.load(transfile, translationsDir.path());
  119. app.installTranslator(&translator);
  120. // app setup
  121. app.setApplicationName("CMakeSetup");
  122. app.setOrganizationName("Kitware");
  123. QIcon appIcon;
  124. appIcon.addFile(":/Icons/CMakeSetup32.png");
  125. appIcon.addFile(":/Icons/CMakeSetup128.png");
  126. app.setWindowIcon(appIcon);
  127. CMakeSetupDialog dialog;
  128. dialog.show();
  129. cmsys::CommandLineArguments arg;
  130. arg.Initialize(argc, argv);
  131. std::string binaryDirectory;
  132. std::string sourceDirectory;
  133. typedef cmsys::CommandLineArguments argT;
  134. arg.AddArgument("-B", argT::CONCAT_ARGUMENT,
  135. &binaryDirectory, "Binary Directory");
  136. arg.AddArgument("-H", argT::CONCAT_ARGUMENT,
  137. &sourceDirectory, "Source Directory");
  138. // do not complain about unknown options
  139. arg.StoreUnusedArguments(true);
  140. arg.Parse();
  141. if(!sourceDirectory.empty() && !binaryDirectory.empty())
  142. {
  143. dialog.setSourceDirectory(sourceDirectory.c_str());
  144. dialog.setBinaryDirectory(binaryDirectory.c_str());
  145. }
  146. else
  147. {
  148. QStringList args = app.arguments();
  149. if(args.count() == 2)
  150. {
  151. cmsys_stl::string filePath = cmSystemTools::CollapseFullPath(args[1].toAscii().data());
  152. // check if argument is a directory containing CMakeCache.txt
  153. cmsys_stl::string buildFilePath =
  154. cmSystemTools::CollapseFullPath("CMakeCache.txt", filePath.c_str());
  155. // check if argument is a CMakeCache.txt file
  156. if(cmSystemTools::GetFilenameName(filePath) == "CMakeCache.txt" &&
  157. cmSystemTools::FileExists(filePath.c_str()))
  158. {
  159. buildFilePath = filePath;
  160. }
  161. // check if argument is a directory containing CMakeLists.txt
  162. cmsys_stl::string srcFilePath =
  163. cmSystemTools::CollapseFullPath("CMakeLists.txt", filePath.c_str());
  164. if(cmSystemTools::FileExists(buildFilePath.c_str()))
  165. {
  166. dialog.setBinaryDirectory(cmSystemTools::GetFilenamePath(buildFilePath).c_str());
  167. }
  168. else if(cmSystemTools::FileExists(srcFilePath.c_str()))
  169. {
  170. dialog.setSourceDirectory(filePath.c_str());
  171. dialog.setBinaryDirectory(cmSystemTools::CollapseFullPath(".").c_str());
  172. }
  173. }
  174. }
  175. return app.exec();
  176. }