1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: CMakeSetup.cxx,v $
6 Date: $Date: 2009-03-05 20:17:07 $
7 Version: $Revision: 1.22 $
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 cmSystemTools::FindExecutableDirectory(argv
[0]);
70 // check docs first so that X is not need to get docs
71 // do docs, if args were given
73 if(argc
>1 && doc
.CheckOptions(argc
, argv
))
75 // Construct and print requested documentation.
78 // just incase the install is bad avoid a seg fault
79 const char* root
= hcm
.GetCacheDefinition("CMAKE_ROOT");
82 doc
.SetCMakeRoot(root
);
84 std::vector
<cmDocumentationEntry
> commands
;
85 std::vector
<cmDocumentationEntry
> compatCommands
;
86 std::map
<std::string
,cmDocumentationSection
*> propDocs
;
88 std::vector
<cmDocumentationEntry
> generators
;
89 hcm
.GetCommandDocumentation(commands
, true, false);
90 hcm
.GetCommandDocumentation(compatCommands
, false, true);
91 hcm
.GetGeneratorDocumentation(generators
);
92 hcm
.GetPropertiesDocumentation(propDocs
);
94 doc
.SetSection("Name",cmDocumentationName
);
95 doc
.SetSection("Usage",cmDocumentationUsage
);
96 doc
.SetSection("Description",cmDocumentationDescription
);
97 doc
.AppendSection("Generators",generators
);
98 doc
.PrependSection("Options",cmDocumentationOptions
);
99 doc
.SetSection("Commands",commands
);
100 doc
.SetSection("Compatilbility Commands", compatCommands
);
101 doc
.SetSections(propDocs
);
103 return (doc
.PrintRequestedDocumentation(std::cout
)? 0:1);
106 QApplication
app(argc
, argv
);
108 // clean out standard Qt paths for plugins, which we don't use anyway
109 // when creating Mac bundles, it potentially causes problems
110 foreach(QString p
, QApplication::libraryPaths())
112 QApplication::removeLibraryPath(p
);
115 // if arg for install
116 for(int i
=0; i
< argc
; i
++)
118 if(strcmp(argv
[i
], "--mac-install") == 0)
120 QMacInstallDialog
setupdialog(0);
125 // tell the cmake library where cmake is
126 QDir
cmExecDir(QApplication::applicationDirPath());
127 #if defined(Q_OS_MAC)
128 cmExecDir
.cd("../../../");
131 // pick up translation files if they exists in the data directory
132 QDir translationsDir
= cmExecDir
;
133 translationsDir
.cd(".." CMAKE_DATA_DIR
);
134 translationsDir
.cd("i18n");
135 QTranslator translator
;
136 QString transfile
= QString("cmake_%1").arg(QLocale::system().name());
137 translator
.load(transfile
, translationsDir
.path());
138 app
.installTranslator(&translator
);
141 app
.setApplicationName("CMakeSetup");
142 app
.setOrganizationName("Kitware");
143 app
.setWindowIcon(QIcon(":/Icons/CMakeSetup.png"));
145 CMakeSetupDialog dialog
;
146 QString title
= QString("CMake %1");
147 title
= title
.arg(cmVersion::GetCMakeVersion());
148 dialog
.setWindowTitle(title
);
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);
163 if(!sourceDirectory
.empty() && !binaryDirectory
.empty())
165 dialog
.setSourceDirectory(sourceDirectory
.c_str());
166 dialog
.setBinaryDirectory(binaryDirectory
.c_str());
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());