2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2016-05-16 17:34:04 +03:00
|
|
|
#include "QCMake.h" // include to disable MS warnings
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "CMakeSetupDialog.h"
|
|
|
|
#include "cmAlgorithms.h"
|
|
|
|
#include "cmDocumentation.h"
|
|
|
|
#include "cmVersion.h"
|
|
|
|
#include "cmake.h"
|
2007-11-02 18:50:17 +03:00
|
|
|
#include <QApplication>
|
2007-11-13 08:33:22 +03:00
|
|
|
#include <QDir>
|
2008-02-08 18:42:14 +03:00
|
|
|
#include <QLocale>
|
2016-06-09 15:23:47 +03:00
|
|
|
#include <QString>
|
2014-03-07 10:23:52 +04:00
|
|
|
#include <QTextCodec>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <QTranslator>
|
2016-07-05 22:15:57 +03:00
|
|
|
#include <QtPlugin>
|
2008-02-12 17:49:42 +03:00
|
|
|
#include <cmsys/CommandLineArguments.hxx>
|
2013-12-19 01:38:56 +04:00
|
|
|
#include <cmsys/Encoding.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/SystemTools.hxx>
|
2007-11-27 09:04:02 +03:00
|
|
|
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmSystemTools.h" // IWYU pragma: keep
|
|
|
|
|
2016-09-05 23:12:36 +03:00
|
|
|
static const char* cmDocumentationName[][2] = { { CM_NULLPTR,
|
2016-05-16 17:34:04 +03:00
|
|
|
" cmake-gui - CMake GUI." },
|
2016-09-05 23:12:36 +03:00
|
|
|
{ CM_NULLPTR, CM_NULLPTR } };
|
2007-11-27 09:04:02 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static const char* cmDocumentationUsage[][2] = {
|
2016-09-05 23:12:36 +03:00
|
|
|
{ CM_NULLPTR, " cmake-gui [options]\n"
|
|
|
|
" cmake-gui [options] <path-to-source>\n"
|
|
|
|
" cmake-gui [options] <path-to-existing-build>" },
|
|
|
|
{ CM_NULLPTR, CM_NULLPTR }
|
2007-11-27 09:04:02 +03:00
|
|
|
};
|
|
|
|
|
2016-09-05 23:12:36 +03:00
|
|
|
static const char* cmDocumentationOptions[]
|
|
|
|
[2] = { { CM_NULLPTR, CM_NULLPTR } };
|
2007-11-02 18:50:17 +03:00
|
|
|
|
2015-05-19 16:44:19 +03:00
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
static int cmOSXInstall(std::string dir);
|
2016-06-09 15:23:47 +03:00
|
|
|
static void cmAddPluginPath();
|
2015-05-19 16:44:19 +03:00
|
|
|
#endif
|
|
|
|
|
2016-06-30 17:43:51 +03:00
|
|
|
#if defined(USE_QXcbIntegrationPlugin)
|
|
|
|
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
|
|
|
|
#endif
|
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2013-12-19 01:38:56 +04:00
|
|
|
cmsys::Encoding::CommandLineArguments encoding_args =
|
|
|
|
cmsys::Encoding::CommandLineArguments::Main(argc, argv);
|
|
|
|
int argc2 = encoding_args.argc();
|
|
|
|
char const* const* argv2 = encoding_args.argv();
|
|
|
|
|
|
|
|
cmSystemTools::FindCMakeResources(argv2[0]);
|
2009-02-21 22:23:32 +03:00
|
|
|
// check docs first so that X is not need to get docs
|
|
|
|
// do docs, if args were given
|
|
|
|
cmDocumentation doc;
|
2011-11-14 01:44:53 +04:00
|
|
|
doc.addCMakeStandardDocSections();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argc2 > 1 && doc.CheckOptions(argc2, argv2)) {
|
2009-02-21 22:23:32 +03:00
|
|
|
// Construct and print requested documentation.
|
|
|
|
cmake hcm;
|
2015-05-05 00:01:29 +03:00
|
|
|
hcm.SetHomeDirectory("");
|
|
|
|
hcm.SetHomeOutputDirectory("");
|
2009-02-21 22:23:32 +03:00
|
|
|
hcm.AddCMakePaths();
|
|
|
|
|
|
|
|
std::vector<cmDocumentationEntry> generators;
|
|
|
|
hcm.GetGeneratorDocumentation(generators);
|
|
|
|
doc.SetName("cmake");
|
2016-05-16 17:34:04 +03:00
|
|
|
doc.SetSection("Name", cmDocumentationName);
|
|
|
|
doc.SetSection("Usage", cmDocumentationUsage);
|
|
|
|
doc.AppendSection("Generators", generators);
|
|
|
|
doc.PrependSection("Options", cmDocumentationOptions);
|
2009-02-21 22:23:32 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
return (doc.PrintRequestedDocumentation(std::cout) ? 0 : 1);
|
|
|
|
}
|
2009-02-21 22:23:32 +03:00
|
|
|
|
2015-05-19 16:44:19 +03:00
|
|
|
#if defined(Q_OS_MAC)
|
2016-05-16 17:34:04 +03:00
|
|
|
if (argc2 == 2 && strcmp(argv2[1], "--install") == 0) {
|
2015-06-24 15:55:29 +03:00
|
|
|
return cmOSXInstall("/usr/local/bin");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (argc2 == 2 && cmHasLiteralPrefix(argv2[1], "--install=")) {
|
|
|
|
return cmOSXInstall(argv2[1] + 10);
|
|
|
|
}
|
2015-05-19 16:44:19 +03:00
|
|
|
#endif
|
|
|
|
|
2016-06-09 15:23:47 +03:00
|
|
|
// When we are on OSX and we are launching cmake-gui from a symlink, the
|
|
|
|
// application will fail to launch as it can't find the qt.conf file which
|
|
|
|
// tells it what the name of the plugin folder is. We need to add this path
|
|
|
|
// BEFORE the application is constructed as that is what triggers the
|
|
|
|
// searching for the platform plugins
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
cmAddPluginPath();
|
|
|
|
#endif
|
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
QApplication app(argc, argv);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2016-05-11 21:51:32 +03:00
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
|
2014-03-14 18:47:37 +04:00
|
|
|
#if defined(CMAKE_ENCODING_UTF8)
|
2014-03-07 10:23:52 +04:00
|
|
|
QTextCodec* utf8_codec = QTextCodec::codecForName("UTF-8");
|
|
|
|
QTextCodec::setCodecForLocale(utf8_codec);
|
|
|
|
#endif
|
|
|
|
|
2016-09-22 22:13:38 +03:00
|
|
|
#if QT_VERSION < 0x050000
|
2008-03-14 22:18:04 +03:00
|
|
|
// clean out standard Qt paths for plugins, which we don't use anyway
|
|
|
|
// when creating Mac bundles, it potentially causes problems
|
2016-05-16 17:34:04 +03:00
|
|
|
foreach (QString p, QApplication::libraryPaths()) {
|
2008-03-14 22:18:04 +03:00
|
|
|
QApplication::removeLibraryPath(p);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-09-22 22:13:38 +03:00
|
|
|
#endif
|
2012-08-13 21:42:58 +04:00
|
|
|
|
|
|
|
// tell the cmake library where cmake is
|
2008-02-06 22:45:32 +03:00
|
|
|
QDir cmExecDir(QApplication::applicationDirPath());
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
cmExecDir.cd("../../../");
|
|
|
|
#endif
|
2008-02-01 18:41:29 +03:00
|
|
|
|
2008-02-08 18:42:14 +03:00
|
|
|
// pick up translation files if they exists in the data directory
|
|
|
|
QDir translationsDir = cmExecDir;
|
2012-07-06 23:26:39 +04:00
|
|
|
translationsDir.cd(QString::fromLocal8Bit(".." CMAKE_DATA_DIR));
|
2008-02-08 18:42:14 +03:00
|
|
|
translationsDir.cd("i18n");
|
2008-02-01 18:41:29 +03:00
|
|
|
QTranslator translator;
|
|
|
|
QString transfile = QString("cmake_%1").arg(QLocale::system().name());
|
2008-02-08 18:42:14 +03:00
|
|
|
translator.load(transfile, translationsDir.path());
|
2008-02-01 18:41:29 +03:00
|
|
|
app.installTranslator(&translator);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-02-08 18:42:14 +03:00
|
|
|
// app setup
|
2007-11-02 18:50:17 +03:00
|
|
|
app.setApplicationName("CMakeSetup");
|
|
|
|
app.setOrganizationName("Kitware");
|
2009-12-11 08:35:33 +03:00
|
|
|
QIcon appIcon;
|
|
|
|
appIcon.addFile(":/Icons/CMakeSetup32.png");
|
|
|
|
appIcon.addFile(":/Icons/CMakeSetup128.png");
|
|
|
|
app.setWindowIcon(appIcon);
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
CMakeSetupDialog dialog;
|
|
|
|
dialog.show();
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2008-02-12 17:49:42 +03:00
|
|
|
cmsys::CommandLineArguments arg;
|
2013-12-19 01:38:56 +04:00
|
|
|
arg.Initialize(argc2, argv2);
|
2008-02-12 17:49:42 +03:00
|
|
|
std::string binaryDirectory;
|
|
|
|
std::string sourceDirectory;
|
|
|
|
typedef cmsys::CommandLineArguments argT;
|
2016-05-16 17:34:04 +03:00
|
|
|
arg.AddArgument("-B", argT::CONCAT_ARGUMENT, &binaryDirectory,
|
|
|
|
"Binary Directory");
|
|
|
|
arg.AddArgument("-H", argT::CONCAT_ARGUMENT, &sourceDirectory,
|
|
|
|
"Source Directory");
|
2008-02-12 17:49:42 +03:00
|
|
|
// do not complain about unknown options
|
|
|
|
arg.StoreUnusedArguments(true);
|
|
|
|
arg.Parse();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!sourceDirectory.empty() && !binaryDirectory.empty()) {
|
2012-07-06 23:26:39 +04:00
|
|
|
dialog.setSourceDirectory(QString::fromLocal8Bit(sourceDirectory.c_str()));
|
|
|
|
dialog.setBinaryDirectory(QString::fromLocal8Bit(binaryDirectory.c_str()));
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2008-02-12 17:49:42 +03:00
|
|
|
QStringList args = app.arguments();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.count() == 2) {
|
|
|
|
std::string filePath =
|
|
|
|
cmSystemTools::CollapseFullPath(args[1].toLocal8Bit().data());
|
2010-11-01 18:40:25 +03:00
|
|
|
|
|
|
|
// check if argument is a directory containing CMakeCache.txt
|
2015-01-30 01:19:40 +03:00
|
|
|
std::string buildFilePath =
|
2010-05-05 16:48:30 +04:00
|
|
|
cmSystemTools::CollapseFullPath("CMakeCache.txt", filePath.c_str());
|
2010-11-01 18:40:25 +03:00
|
|
|
|
|
|
|
// check if argument is a CMakeCache.txt file
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::GetFilenameName(filePath) == "CMakeCache.txt" &&
|
|
|
|
cmSystemTools::FileExists(filePath.c_str())) {
|
2010-11-01 18:40:25 +03:00
|
|
|
buildFilePath = filePath;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2010-11-01 18:40:25 +03:00
|
|
|
|
|
|
|
// check if argument is a directory containing CMakeLists.txt
|
2015-01-30 01:19:40 +03:00
|
|
|
std::string srcFilePath =
|
2010-05-05 16:48:30 +04:00
|
|
|
cmSystemTools::CollapseFullPath("CMakeLists.txt", filePath.c_str());
|
2010-11-01 18:40:25 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(buildFilePath.c_str())) {
|
|
|
|
dialog.setBinaryDirectory(QString::fromLocal8Bit(
|
|
|
|
cmSystemTools::GetFilenamePath(buildFilePath).c_str()));
|
|
|
|
} else if (cmSystemTools::FileExists(srcFilePath.c_str())) {
|
2012-07-06 23:26:39 +04:00
|
|
|
dialog.setSourceDirectory(QString::fromLocal8Bit(filePath.c_str()));
|
2016-05-16 17:34:04 +03:00
|
|
|
dialog.setBinaryDirectory(QString::fromLocal8Bit(
|
|
|
|
cmSystemTools::CollapseFullPath(".").c_str()));
|
2007-11-13 08:33:22 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2007-11-02 18:50:17 +03:00
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
|
2015-05-19 16:44:19 +03:00
|
|
|
#if defined(Q_OS_MAC)
|
2016-05-16 17:34:04 +03:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
2015-05-19 16:44:19 +03:00
|
|
|
static bool cmOSXInstall(std::string const& dir, std::string const& tool)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tool.empty()) {
|
2015-05-19 16:44:19 +03:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-19 16:44:19 +03:00
|
|
|
std::string link = dir + cmSystemTools::GetFilenameName(tool);
|
|
|
|
struct stat st;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (lstat(link.c_str(), &st) == 0 && S_ISLNK(st.st_mode)) {
|
2015-05-19 16:44:19 +03:00
|
|
|
char buf[4096];
|
2016-05-16 17:34:04 +03:00
|
|
|
ssize_t s = readlink(link.c_str(), buf, sizeof(buf) - 1);
|
|
|
|
if (s >= 0 && std::string(buf, s) == tool) {
|
2015-05-19 16:44:19 +03:00
|
|
|
std::cerr << "Exists: '" << link << "' -> '" << tool << "'\n";
|
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-15 20:23:02 +03:00
|
|
|
cmSystemTools::MakeDirectory(dir);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (symlink(tool.c_str(), link.c_str()) == 0) {
|
2015-05-19 16:44:19 +03:00
|
|
|
std::cerr << "Linked: '" << link << "' -> '" << tool << "'\n";
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-05-19 16:44:19 +03:00
|
|
|
int err = errno;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::cerr << "Failed: '" << link << "' -> '" << tool
|
|
|
|
<< "': " << strerror(err) << "\n";
|
2015-05-19 16:44:19 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-19 16:44:19 +03:00
|
|
|
}
|
|
|
|
static int cmOSXInstall(std::string dir)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmHasLiteralSuffix(dir, "/")) {
|
2015-05-19 16:44:19 +03:00
|
|
|
dir += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
return (cmOSXInstall(dir, cmSystemTools::GetCMakeCommand()) &&
|
|
|
|
cmOSXInstall(dir, cmSystemTools::GetCTestCommand()) &&
|
|
|
|
cmOSXInstall(dir, cmSystemTools::GetCPackCommand()) &&
|
|
|
|
cmOSXInstall(dir, cmSystemTools::GetCMakeGUICommand()) &&
|
|
|
|
cmOSXInstall(dir, cmSystemTools::GetCMakeCursesCommand()))
|
|
|
|
? 0
|
|
|
|
: 1;
|
2015-05-19 16:44:19 +03:00
|
|
|
}
|
2016-06-09 15:23:47 +03:00
|
|
|
|
|
|
|
// Locate the PlugIns directory and add it to the QApplication library paths.
|
|
|
|
// We need to resolve all symlinks so we have a known relative path between
|
|
|
|
// MacOS/CMake and the PlugIns directory.
|
|
|
|
//
|
|
|
|
// Note we are using cmSystemTools since Qt can't provide the path to the
|
|
|
|
// executable before the QApplication is created, and that is when plugin
|
|
|
|
// searching occurs.
|
|
|
|
static void cmAddPluginPath()
|
|
|
|
{
|
|
|
|
std::string const& path = cmSystemTools::GetCMakeGUICommand();
|
|
|
|
if (path.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::string const& realPath = cmSystemTools::GetRealPath(path);
|
|
|
|
QFileInfo appPath(QString::fromLocal8Bit(realPath.c_str()));
|
|
|
|
QDir pluginDir = appPath.dir();
|
|
|
|
bool const foundPluginDir = pluginDir.cd("../PlugIns");
|
|
|
|
if (foundPluginDir) {
|
|
|
|
QApplication::addLibraryPath(pluginDir.path());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 16:44:19 +03:00
|
|
|
#endif
|