CMakeSetup.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "QCMake.h" // include to disable MS warnings
  14. #include <QApplication>
  15. #include <QFileInfo>
  16. #include <QDir>
  17. #include <QTranslator>
  18. #include <QLocale>
  19. #include "QMacInstallDialog.h"
  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. QApplication app(argc, argv);
  60. // clean out standard Qt paths for plugins, which we don't use anyway
  61. // when creating Mac bundles, it potentially causes problems
  62. foreach(QString p, QApplication::libraryPaths())
  63. {
  64. QApplication::removeLibraryPath(p);
  65. }
  66. // if arg for install
  67. for(int i =0; i < argc; i++)
  68. {
  69. if(strcmp(argv[i], "--mac-install") == 0)
  70. {
  71. QMacInstallDialog setupdialog(0);
  72. setupdialog.exec();
  73. return 0;
  74. }
  75. }
  76. // tell the cmake library where cmake is
  77. QDir cmExecDir(QApplication::applicationDirPath());
  78. #if defined(Q_OS_MAC)
  79. cmExecDir.cd("../../../");
  80. #endif
  81. // pick up translation files if they exists in the data directory
  82. QDir translationsDir = cmExecDir;
  83. translationsDir.cd(".." CMAKE_DATA_DIR);
  84. translationsDir.cd("i18n");
  85. QTranslator translator;
  86. QString transfile = QString("cmake_%1").arg(QLocale::system().name());
  87. translator.load(transfile, translationsDir.path());
  88. app.installTranslator(&translator);
  89. // app setup
  90. app.setApplicationName("CMakeSetup");
  91. app.setOrganizationName("Kitware");
  92. app.setWindowIcon(QIcon(":/Icons/CMakeSetup.png"));
  93. // do docs, if args were given
  94. cmDocumentation doc;
  95. if(app.arguments().size() > 1 &&
  96. doc.CheckOptions(app.argc(), app.argv()))
  97. {
  98. // Construct and print requested documentation.
  99. cmake hcm;
  100. hcm.AddCMakePaths();
  101. doc.SetCMakeRoot(hcm.GetCacheDefinition("CMAKE_ROOT"));
  102. std::vector<cmDocumentationEntry> commands;
  103. std::vector<cmDocumentationEntry> compatCommands;
  104. std::map<std::string,cmDocumentationSection *> propDocs;
  105. std::vector<cmDocumentationEntry> generators;
  106. hcm.GetCommandDocumentation(commands, true, false);
  107. hcm.GetCommandDocumentation(compatCommands, false, true);
  108. hcm.GetGeneratorDocumentation(generators);
  109. hcm.GetPropertiesDocumentation(propDocs);
  110. doc.SetName("cmake");
  111. doc.SetSection("Name",cmDocumentationName);
  112. doc.SetSection("Usage",cmDocumentationUsage);
  113. doc.SetSection("Description",cmDocumentationDescription);
  114. doc.AppendSection("Generators",generators);
  115. doc.PrependSection("Options",cmDocumentationOptions);
  116. doc.SetSection("Commands",commands);
  117. doc.SetSection("Compatilbility Commands", compatCommands);
  118. doc.SetSections(propDocs);
  119. return (doc.PrintRequestedDocumentation(std::cout)? 0:1);
  120. }
  121. CMakeSetupDialog dialog;
  122. QString title = QString("CMake %1");
  123. title = title.arg(cmVersion::GetCMakeVersion().c_str());
  124. dialog.setWindowTitle(title);
  125. dialog.show();
  126. cmsys::CommandLineArguments arg;
  127. arg.Initialize(argc, argv);
  128. std::string binaryDirectory;
  129. std::string sourceDirectory;
  130. typedef cmsys::CommandLineArguments argT;
  131. arg.AddArgument("-B", argT::CONCAT_ARGUMENT,
  132. &binaryDirectory, "Binary Directory");
  133. arg.AddArgument("-H", argT::CONCAT_ARGUMENT,
  134. &sourceDirectory, "Source Directory");
  135. // do not complain about unknown options
  136. arg.StoreUnusedArguments(true);
  137. arg.Parse();
  138. if(!sourceDirectory.empty() && !binaryDirectory.empty())
  139. {
  140. dialog.setSourceDirectory(sourceDirectory.c_str());
  141. dialog.setBinaryDirectory(binaryDirectory.c_str());
  142. }
  143. else
  144. {
  145. QStringList args = app.arguments();
  146. if(args.count() == 2)
  147. {
  148. QFileInfo buildFileInfo(args[1], "CMakeCache.txt");
  149. QFileInfo srcFileInfo(args[1], "CMakeLists.txt");
  150. if(buildFileInfo.exists())
  151. {
  152. dialog.setBinaryDirectory(buildFileInfo.absolutePath());
  153. }
  154. else if(srcFileInfo.exists())
  155. {
  156. dialog.setSourceDirectory(srcFileInfo.absolutePath());
  157. dialog.setBinaryDirectory(QDir::currentPath());
  158. }
  159. }
  160. }
  161. return app.exec();
  162. }