1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: CMakeSetup.cxx,v $
6 Date: $Date: 2009-09-22 22:29:35 $
7 Version: $Revision: 1.24 $
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>
21 #include <QTranslator>
23 #include "QMacInstallDialog.h"
26 #include "windows.h" // for SetErrorMode
29 #include "CMakeSetupDialog.h"
30 #include "cmDocumentation.h"
32 #include "cmVersion.h"
33 #include <cmsys/CommandLineArguments.hxx>
35 //----------------------------------------------------------------------------
36 static const char * cmDocumentationName
[][3] =
39 " cmake-gui - CMake GUI.", 0},
43 //----------------------------------------------------------------------------
44 static const char * cmDocumentationUsage
[][3] =
47 " cmake-gui [options]\n"
48 " cmake-gui [options] <path-to-source>\n"
49 " cmake-gui [options] <path-to-existing-build>", 0},
53 //----------------------------------------------------------------------------
54 static const char * cmDocumentationDescription
[][3] =
57 "The \"cmake-gui\" executable is the CMake GUI. Project "
58 "configuration settings may be specified interactively. "
59 "Brief instructions are provided at the bottom of the "
60 "window when the program is running.", 0},
61 CMAKE_STANDARD_INTRODUCTION
,
65 //----------------------------------------------------------------------------
66 static const char * cmDocumentationOptions
[][3] =
71 int main(int argc
, char** argv
)
73 cmSystemTools::FindExecutableDirectory(argv
[0]);
74 // check docs first so that X is not need to get docs
75 // do docs, if args were given
77 if(argc
>1 && doc
.CheckOptions(argc
, argv
))
79 // Construct and print requested documentation.
82 // just incase the install is bad avoid a seg fault
83 const char* root
= hcm
.GetCacheDefinition("CMAKE_ROOT");
86 doc
.SetCMakeRoot(root
);
88 std::vector
<cmDocumentationEntry
> commands
;
89 std::vector
<cmDocumentationEntry
> compatCommands
;
90 std::map
<std::string
,cmDocumentationSection
*> propDocs
;
92 std::vector
<cmDocumentationEntry
> generators
;
93 hcm
.GetCommandDocumentation(commands
, true, false);
94 hcm
.GetCommandDocumentation(compatCommands
, false, true);
95 hcm
.GetGeneratorDocumentation(generators
);
96 hcm
.GetPropertiesDocumentation(propDocs
);
98 doc
.SetSection("Name",cmDocumentationName
);
99 doc
.SetSection("Usage",cmDocumentationUsage
);
100 doc
.SetSection("Description",cmDocumentationDescription
);
101 doc
.AppendSection("Generators",generators
);
102 doc
.PrependSection("Options",cmDocumentationOptions
);
103 doc
.SetSection("Commands",commands
);
104 doc
.SetSection("Compatilbility Commands", compatCommands
);
105 doc
.SetSections(propDocs
);
107 return (doc
.PrintRequestedDocumentation(std::cout
)? 0:1);
110 QApplication
app(argc
, argv
);
112 // QApplication changes error mode, let's put it back
116 // clean out standard Qt paths for plugins, which we don't use anyway
117 // when creating Mac bundles, it potentially causes problems
118 foreach(QString p
, QApplication::libraryPaths())
120 QApplication::removeLibraryPath(p
);
123 // if arg for install
124 for(int i
=0; i
< argc
; i
++)
126 if(strcmp(argv
[i
], "--mac-install") == 0)
128 QMacInstallDialog
setupdialog(0);
133 // tell the cmake library where cmake is
134 QDir
cmExecDir(QApplication::applicationDirPath());
135 #if defined(Q_OS_MAC)
136 cmExecDir
.cd("../../../");
139 // pick up translation files if they exists in the data directory
140 QDir translationsDir
= cmExecDir
;
141 translationsDir
.cd(".." CMAKE_DATA_DIR
);
142 translationsDir
.cd("i18n");
143 QTranslator translator
;
144 QString transfile
= QString("cmake_%1").arg(QLocale::system().name());
145 translator
.load(transfile
, translationsDir
.path());
146 app
.installTranslator(&translator
);
149 app
.setApplicationName("CMakeSetup");
150 app
.setOrganizationName("Kitware");
151 app
.setWindowIcon(QIcon(":/Icons/CMakeSetup.png"));
153 CMakeSetupDialog dialog
;
156 cmsys::CommandLineArguments arg
;
157 arg
.Initialize(argc
, argv
);
158 std::string binaryDirectory
;
159 std::string sourceDirectory
;
160 typedef cmsys::CommandLineArguments argT
;
161 arg
.AddArgument("-B", argT::CONCAT_ARGUMENT
,
162 &binaryDirectory
, "Binary Directory");
163 arg
.AddArgument("-H", argT::CONCAT_ARGUMENT
,
164 &sourceDirectory
, "Source Directory");
165 // do not complain about unknown options
166 arg
.StoreUnusedArguments(true);
168 if(!sourceDirectory
.empty() && !binaryDirectory
.empty())
170 dialog
.setSourceDirectory(sourceDirectory
.c_str());
171 dialog
.setBinaryDirectory(binaryDirectory
.c_str());
175 QStringList args
= app
.arguments();
176 if(args
.count() == 2)
178 QFileInfo
buildFileInfo(args
[1], "CMakeCache.txt");
179 QFileInfo
srcFileInfo(args
[1], "CMakeLists.txt");
180 if(buildFileInfo
.exists())
182 dialog
.setBinaryDirectory(buildFileInfo
.absolutePath());
184 else if(srcFileInfo
.exists())
186 dialog
.setSourceDirectory(srcFileInfo
.absolutePath());
187 dialog
.setBinaryDirectory(QDir::currentPath());