CMakeSetup.cxx 5.8 KB

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