CMakeSetup.cxx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. // tell the cmake library where cmake is
  82. QDir cmExecDir(QApplication::applicationDirPath());
  83. #if defined(Q_OS_MAC)
  84. cmExecDir.cd("../../../");
  85. #endif
  86. // pick up translation files if they exists in the data directory
  87. QDir translationsDir = cmExecDir;
  88. translationsDir.cd(QString::fromLocal8Bit(".." CMAKE_DATA_DIR));
  89. translationsDir.cd("i18n");
  90. QTranslator translator;
  91. QString transfile = QString("cmake_%1").arg(QLocale::system().name());
  92. translator.load(transfile, translationsDir.path());
  93. app.installTranslator(&translator);
  94. // app setup
  95. app.setApplicationName("CMakeSetup");
  96. app.setOrganizationName("Kitware");
  97. QIcon appIcon;
  98. appIcon.addFile(":/Icons/CMakeSetup32.png");
  99. appIcon.addFile(":/Icons/CMakeSetup128.png");
  100. app.setWindowIcon(appIcon);
  101. CMakeSetupDialog dialog;
  102. dialog.show();
  103. cmsys::CommandLineArguments arg;
  104. arg.Initialize(argc2, argv2);
  105. std::string binaryDirectory;
  106. std::string sourceDirectory;
  107. typedef cmsys::CommandLineArguments argT;
  108. arg.AddArgument("-B", argT::CONCAT_ARGUMENT,
  109. &binaryDirectory, "Binary Directory");
  110. arg.AddArgument("-H", argT::CONCAT_ARGUMENT,
  111. &sourceDirectory, "Source Directory");
  112. // do not complain about unknown options
  113. arg.StoreUnusedArguments(true);
  114. arg.Parse();
  115. if(!sourceDirectory.empty() && !binaryDirectory.empty())
  116. {
  117. dialog.setSourceDirectory(QString::fromLocal8Bit(sourceDirectory.c_str()));
  118. dialog.setBinaryDirectory(QString::fromLocal8Bit(binaryDirectory.c_str()));
  119. }
  120. else
  121. {
  122. QStringList args = app.arguments();
  123. if(args.count() == 2)
  124. {
  125. std::string filePath = cmSystemTools::CollapseFullPath(args[1].toLocal8Bit().data());
  126. // check if argument is a directory containing CMakeCache.txt
  127. std::string buildFilePath =
  128. cmSystemTools::CollapseFullPath("CMakeCache.txt", filePath.c_str());
  129. // check if argument is a CMakeCache.txt file
  130. if(cmSystemTools::GetFilenameName(filePath) == "CMakeCache.txt" &&
  131. cmSystemTools::FileExists(filePath.c_str()))
  132. {
  133. buildFilePath = filePath;
  134. }
  135. // check if argument is a directory containing CMakeLists.txt
  136. std::string srcFilePath =
  137. cmSystemTools::CollapseFullPath("CMakeLists.txt", filePath.c_str());
  138. if(cmSystemTools::FileExists(buildFilePath.c_str()))
  139. {
  140. dialog.setBinaryDirectory(
  141. QString::fromLocal8Bit(
  142. cmSystemTools::GetFilenamePath(buildFilePath).c_str()
  143. )
  144. );
  145. }
  146. else if(cmSystemTools::FileExists(srcFilePath.c_str()))
  147. {
  148. dialog.setSourceDirectory(QString::fromLocal8Bit(filePath.c_str()));
  149. dialog.setBinaryDirectory(
  150. QString::fromLocal8Bit(cmSystemTools::CollapseFullPath(".").c_str())
  151. );
  152. }
  153. }
  154. }
  155. return app.exec();
  156. }