Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / QtDialog / CMakeSetup.cxx
blobbd5b36ae43a1da53f7df60e1545f54f33bd28034
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: CMakeSetup.cxx,v $
5 Language: C++
6 Date: $Date: 2008-04-04 20:02:50 $
7 Version: $Revision: 1.19 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "QCMake.h" // include to disable MS warnings
18 #include <QApplication>
19 #include <QFileInfo>
20 #include <QDir>
21 #include <QTranslator>
22 #include <QLocale>
23 #include "QMacInstallDialog.h"
25 #include "CMakeSetupDialog.h"
26 #include "cmDocumentation.h"
27 #include "cmake.h"
28 #include "cmVersion.h"
29 #include <cmsys/CommandLineArguments.hxx>
31 //----------------------------------------------------------------------------
32 static const char * cmDocumentationName[][3] =
34 {0,
35 " cmake-gui - CMake GUI.", 0},
36 {0,0,0}
39 //----------------------------------------------------------------------------
40 static const char * cmDocumentationUsage[][3] =
42 {0,
43 " cmake-gui [options]\n"
44 " cmake-gui [options] <path-to-source>\n"
45 " cmake-gui [options] <path-to-existing-build>", 0},
46 {0,0,0}
49 //----------------------------------------------------------------------------
50 static const char * cmDocumentationDescription[][3] =
52 {0,
53 "The \"cmake-gui\" executable is the CMake GUI. Project "
54 "configuration settings may be specified interactively. "
55 "Brief instructions are provided at the bottom of the "
56 "window when the program is running.", 0},
57 CMAKE_STANDARD_INTRODUCTION,
58 {0,0,0}
61 //----------------------------------------------------------------------------
62 static const char * cmDocumentationOptions[][3] =
64 {0,0,0}
67 int main(int argc, char** argv)
69 cmSystemTools::FindExecutableDirectory(argv[0]);
70 QApplication app(argc, argv);
72 // clean out standard Qt paths for plugins, which we don't use anyway
73 // when creating Mac bundles, it potentially causes problems
74 foreach(QString p, QApplication::libraryPaths())
76 QApplication::removeLibraryPath(p);
79 // if arg for install
80 for(int i =0; i < argc; i++)
82 if(strcmp(argv[i], "--mac-install") == 0)
84 QMacInstallDialog setupdialog(0);
85 setupdialog.exec();
86 return 0;
89 // tell the cmake library where cmake is
90 QDir cmExecDir(QApplication::applicationDirPath());
91 #if defined(Q_OS_MAC)
92 cmExecDir.cd("../../../");
93 #endif
95 // pick up translation files if they exists in the data directory
96 QDir translationsDir = cmExecDir;
97 translationsDir.cd(".." CMAKE_DATA_DIR);
98 translationsDir.cd("i18n");
99 QTranslator translator;
100 QString transfile = QString("cmake_%1").arg(QLocale::system().name());
101 translator.load(transfile, translationsDir.path());
102 app.installTranslator(&translator);
104 // app setup
105 app.setApplicationName("CMakeSetup");
106 app.setOrganizationName("Kitware");
107 app.setWindowIcon(QIcon(":/Icons/CMakeSetup.png"));
109 // do docs, if args were given
110 cmDocumentation doc;
111 if(app.arguments().size() > 1 &&
112 doc.CheckOptions(app.argc(), app.argv()))
114 // Construct and print requested documentation.
115 cmake hcm;
116 hcm.AddCMakePaths();
117 // just incase the install is bad avoid a seg fault
118 const char* root = hcm.GetCacheDefinition("CMAKE_ROOT");
119 if(root)
121 doc.SetCMakeRoot(root);
123 std::vector<cmDocumentationEntry> commands;
124 std::vector<cmDocumentationEntry> compatCommands;
125 std::map<std::string,cmDocumentationSection *> propDocs;
127 std::vector<cmDocumentationEntry> generators;
128 hcm.GetCommandDocumentation(commands, true, false);
129 hcm.GetCommandDocumentation(compatCommands, false, true);
130 hcm.GetGeneratorDocumentation(generators);
131 hcm.GetPropertiesDocumentation(propDocs);
132 doc.SetName("cmake");
133 doc.SetSection("Name",cmDocumentationName);
134 doc.SetSection("Usage",cmDocumentationUsage);
135 doc.SetSection("Description",cmDocumentationDescription);
136 doc.AppendSection("Generators",generators);
137 doc.PrependSection("Options",cmDocumentationOptions);
138 doc.SetSection("Commands",commands);
139 doc.SetSection("Compatilbility Commands", compatCommands);
140 doc.SetSections(propDocs);
142 return (doc.PrintRequestedDocumentation(std::cout)? 0:1);
145 CMakeSetupDialog dialog;
146 QString title = QString("CMake %1");
147 title = title.arg(cmVersion::GetCMakeVersion().c_str());
148 dialog.setWindowTitle(title);
149 dialog.show();
151 cmsys::CommandLineArguments arg;
152 arg.Initialize(argc, argv);
153 std::string binaryDirectory;
154 std::string sourceDirectory;
155 typedef cmsys::CommandLineArguments argT;
156 arg.AddArgument("-B", argT::CONCAT_ARGUMENT,
157 &binaryDirectory, "Binary Directory");
158 arg.AddArgument("-H", argT::CONCAT_ARGUMENT,
159 &sourceDirectory, "Source Directory");
160 // do not complain about unknown options
161 arg.StoreUnusedArguments(true);
162 arg.Parse();
163 if(!sourceDirectory.empty() && !binaryDirectory.empty())
165 dialog.setSourceDirectory(sourceDirectory.c_str());
166 dialog.setBinaryDirectory(binaryDirectory.c_str());
168 else
170 QStringList args = app.arguments();
171 if(args.count() == 2)
173 QFileInfo buildFileInfo(args[1], "CMakeCache.txt");
174 QFileInfo srcFileInfo(args[1], "CMakeLists.txt");
175 if(buildFileInfo.exists())
177 dialog.setBinaryDirectory(buildFileInfo.absolutePath());
179 else if(srcFileInfo.exists())
181 dialog.setSourceDirectory(srcFileInfo.absolutePath());
182 dialog.setBinaryDirectory(QDir::currentPath());
187 return app.exec();