CMakeSetup.cxx 5.8 KB

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