1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: CMakeSetup.cxx,v $
6 Date: $Date: 2008-03-14 19:18:04 $
7 Version: $Revision: 1.18 $
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"
25 #include "CMakeSetupDialog.h"
26 #include "cmDocumentation.h"
28 #include "cmVersion.h"
29 #include <cmsys/CommandLineArguments.hxx>
31 //----------------------------------------------------------------------------
32 static const char * cmDocumentationName
[][3] =
35 " cmake-gui - CMake GUI.", 0},
39 //----------------------------------------------------------------------------
40 static const char * cmDocumentationUsage
[][3] =
43 " cmake-gui [options]\n"
44 " cmake-gui [options] <path-to-source>\n"
45 " cmake-gui [options] <path-to-existing-build>", 0},
49 //----------------------------------------------------------------------------
50 static const char * cmDocumentationDescription
[][3] =
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
,
61 //----------------------------------------------------------------------------
62 static const char * cmDocumentationOptions
[][3] =
67 int main(int argc
, char** argv
)
69 QApplication
app(argc
, argv
);
71 // clean out standard Qt paths for plugins, which we don't use anyway
72 // when creating Mac bundles, it potentially causes problems
73 foreach(QString p
, QApplication::libraryPaths())
75 QApplication::removeLibraryPath(p
);
79 for(int i
=0; i
< argc
; i
++)
81 if(strcmp(argv
[i
], "--mac-install") == 0)
83 QMacInstallDialog
setupdialog(0);
88 // tell the cmake library where cmake is
89 QDir
cmExecDir(QApplication::applicationDirPath());
91 cmExecDir
.cd("../../../");
94 // pick up translation files if they exists in the data directory
95 QDir translationsDir
= cmExecDir
;
96 translationsDir
.cd(".." CMAKE_DATA_DIR
);
97 translationsDir
.cd("i18n");
98 QTranslator translator
;
99 QString transfile
= QString("cmake_%1").arg(QLocale::system().name());
100 translator
.load(transfile
, translationsDir
.path());
101 app
.installTranslator(&translator
);
104 app
.setApplicationName("CMakeSetup");
105 app
.setOrganizationName("Kitware");
106 app
.setWindowIcon(QIcon(":/Icons/CMakeSetup.png"));
108 // do docs, if args were given
110 if(app
.arguments().size() > 1 &&
111 doc
.CheckOptions(app
.argc(), app
.argv()))
113 // Construct and print requested documentation.
116 doc
.SetCMakeRoot(hcm
.GetCacheDefinition("CMAKE_ROOT"));
117 std::vector
<cmDocumentationEntry
> commands
;
118 std::vector
<cmDocumentationEntry
> compatCommands
;
119 std::map
<std::string
,cmDocumentationSection
*> propDocs
;
121 std::vector
<cmDocumentationEntry
> generators
;
122 hcm
.GetCommandDocumentation(commands
, true, false);
123 hcm
.GetCommandDocumentation(compatCommands
, false, true);
124 hcm
.GetGeneratorDocumentation(generators
);
125 hcm
.GetPropertiesDocumentation(propDocs
);
126 doc
.SetName("cmake");
127 doc
.SetSection("Name",cmDocumentationName
);
128 doc
.SetSection("Usage",cmDocumentationUsage
);
129 doc
.SetSection("Description",cmDocumentationDescription
);
130 doc
.AppendSection("Generators",generators
);
131 doc
.PrependSection("Options",cmDocumentationOptions
);
132 doc
.SetSection("Commands",commands
);
133 doc
.SetSection("Compatilbility Commands", compatCommands
);
134 doc
.SetSections(propDocs
);
136 return (doc
.PrintRequestedDocumentation(std::cout
)? 0:1);
139 CMakeSetupDialog dialog
;
140 QString title
= QString("CMake %1");
141 title
= title
.arg(cmVersion::GetCMakeVersion().c_str());
142 dialog
.setWindowTitle(title
);
145 cmsys::CommandLineArguments arg
;
146 arg
.Initialize(argc
, argv
);
147 std::string binaryDirectory
;
148 std::string sourceDirectory
;
149 typedef cmsys::CommandLineArguments argT
;
150 arg
.AddArgument("-B", argT::CONCAT_ARGUMENT
,
151 &binaryDirectory
, "Binary Directory");
152 arg
.AddArgument("-H", argT::CONCAT_ARGUMENT
,
153 &sourceDirectory
, "Source Directory");
154 // do not complain about unknown options
155 arg
.StoreUnusedArguments(true);
157 if(!sourceDirectory
.empty() && !binaryDirectory
.empty())
159 dialog
.setSourceDirectory(sourceDirectory
.c_str());
160 dialog
.setBinaryDirectory(binaryDirectory
.c_str());
164 QStringList args
= app
.arguments();
165 if(args
.count() == 2)
167 QFileInfo
buildFileInfo(args
[1], "CMakeCache.txt");
168 QFileInfo
srcFileInfo(args
[1], "CMakeLists.txt");
169 if(buildFileInfo
.exists())
171 dialog
.setBinaryDirectory(buildFileInfo
.absolutePath());
173 else if(srcFileInfo
.exists())
175 dialog
.setSourceDirectory(srcFileInfo
.absolutePath());
176 dialog
.setBinaryDirectory(QDir::currentPath());