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