forked from qt-creator/qt-creator
CMake: Minor code cosmetic
Drop top-level static of consts, namespaces. Change-Id: Ibc902e41278b78843a8f5aeced8321e76296ca1b Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@@ -40,6 +41,8 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
|
|
||||||
const char CMAKE_INFORMATION_ID[] = "Id";
|
const char CMAKE_INFORMATION_ID[] = "Id";
|
||||||
@@ -107,17 +110,17 @@ public:
|
|||||||
///////////////////////////
|
///////////////////////////
|
||||||
// CMakeTool
|
// CMakeTool
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
CMakeTool::CMakeTool(Detection d, const Utils::Id &id)
|
CMakeTool::CMakeTool(Detection d, const Id &id)
|
||||||
: m_id(id)
|
: m_id(id)
|
||||||
, m_isAutoDetected(d == AutoDetection)
|
, m_isAutoDetected(d == AutoDetection)
|
||||||
, m_introspection(std::make_unique<Internal::IntrospectionData>())
|
, m_introspection(std::make_unique<Internal::IntrospectionData>())
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_id.isValid(), m_id = Utils::Id::fromString(QUuid::createUuid().toString()));
|
QTC_ASSERT(m_id.isValid(), m_id = Id::fromString(QUuid::createUuid().toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
CMakeTool::CMakeTool(const QVariantMap &map, bool fromSdk) :
|
CMakeTool::CMakeTool(const QVariantMap &map, bool fromSdk) :
|
||||||
CMakeTool(fromSdk ? CMakeTool::AutoDetection : CMakeTool::ManualDetection,
|
CMakeTool(fromSdk ? CMakeTool::AutoDetection : CMakeTool::ManualDetection,
|
||||||
Utils::Id::fromSetting(map.value(CMAKE_INFORMATION_ID)))
|
Id::fromSetting(map.value(CMAKE_INFORMATION_ID)))
|
||||||
{
|
{
|
||||||
m_displayName = map.value(CMAKE_INFORMATION_DISPLAYNAME).toString();
|
m_displayName = map.value(CMAKE_INFORMATION_DISPLAYNAME).toString();
|
||||||
m_isAutoRun = map.value(CMAKE_INFORMATION_AUTORUN, true).toBool();
|
m_isAutoRun = map.value(CMAKE_INFORMATION_AUTORUN, true).toBool();
|
||||||
@@ -129,9 +132,9 @@ CMakeTool::CMakeTool(const QVariantMap &map, bool fromSdk) :
|
|||||||
if (!fromSdk)
|
if (!fromSdk)
|
||||||
m_isAutoDetected = map.value(CMAKE_INFORMATION_AUTODETECTED, false).toBool();
|
m_isAutoDetected = map.value(CMAKE_INFORMATION_AUTODETECTED, false).toBool();
|
||||||
|
|
||||||
setFilePath(Utils::FilePath::fromString(map.value(CMAKE_INFORMATION_COMMAND).toString()));
|
setFilePath(FilePath::fromString(map.value(CMAKE_INFORMATION_COMMAND).toString()));
|
||||||
|
|
||||||
m_qchFilePath = Utils::FilePath::fromVariant(map.value(CMAKE_INFORMATION_QCH_FILE_PATH));
|
m_qchFilePath = FilePath::fromVariant(map.value(CMAKE_INFORMATION_QCH_FILE_PATH));
|
||||||
|
|
||||||
if (m_qchFilePath.isEmpty())
|
if (m_qchFilePath.isEmpty())
|
||||||
m_qchFilePath = searchQchFile(m_executable);
|
m_qchFilePath = searchQchFile(m_executable);
|
||||||
@@ -139,12 +142,12 @@ CMakeTool::CMakeTool(const QVariantMap &map, bool fromSdk) :
|
|||||||
|
|
||||||
CMakeTool::~CMakeTool() = default;
|
CMakeTool::~CMakeTool() = default;
|
||||||
|
|
||||||
Utils::Id CMakeTool::createId()
|
Id CMakeTool::createId()
|
||||||
{
|
{
|
||||||
return Utils::Id::fromString(QUuid::createUuid().toString());
|
return Id::fromString(QUuid::createUuid().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeTool::setFilePath(const Utils::FilePath &executable)
|
void CMakeTool::setFilePath(const FilePath &executable)
|
||||||
{
|
{
|
||||||
if (m_executable == executable)
|
if (m_executable == executable)
|
||||||
return;
|
return;
|
||||||
@@ -155,7 +158,7 @@ void CMakeTool::setFilePath(const Utils::FilePath &executable)
|
|||||||
CMakeToolManager::notifyAboutUpdate(this);
|
CMakeToolManager::notifyAboutUpdate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath CMakeTool::filePath() const
|
FilePath CMakeTool::filePath() const
|
||||||
{
|
{
|
||||||
return m_executable;
|
return m_executable;
|
||||||
}
|
}
|
||||||
@@ -189,12 +192,12 @@ bool CMakeTool::isValid() const
|
|||||||
return m_introspection->m_didRun && !m_introspection->m_fileApis.isEmpty();
|
return m_introspection->m_didRun && !m_introspection->m_fileApis.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeTool::runCMake(Utils::SynchronousProcess &cmake, const QStringList &args, int timeoutS) const
|
void CMakeTool::runCMake(SynchronousProcess &cmake, const QStringList &args, int timeoutS) const
|
||||||
{
|
{
|
||||||
cmake.setTimeoutS(timeoutS);
|
cmake.setTimeoutS(timeoutS);
|
||||||
cmake.setDisableUnixTerminal();
|
cmake.setDisableUnixTerminal();
|
||||||
Utils::Environment env = Utils::Environment::systemEnvironment();
|
Environment env = Environment::systemEnvironment();
|
||||||
Utils::Environment::setupEnglishOutput(&env);
|
Environment::setupEnglishOutput(&env);
|
||||||
cmake.setEnvironment(env);
|
cmake.setEnvironment(env);
|
||||||
cmake.setTimeOutMessageBoxEnabled(false);
|
cmake.setTimeOutMessageBoxEnabled(false);
|
||||||
|
|
||||||
@@ -217,24 +220,24 @@ QVariantMap CMakeTool::toMap() const
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath CMakeTool::cmakeExecutable() const
|
FilePath CMakeTool::cmakeExecutable() const
|
||||||
{
|
{
|
||||||
return cmakeExecutable(m_executable);
|
return cmakeExecutable(m_executable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeTool::setQchFilePath(const Utils::FilePath &path)
|
void CMakeTool::setQchFilePath(const FilePath &path)
|
||||||
{
|
{
|
||||||
m_qchFilePath = path;
|
m_qchFilePath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath CMakeTool::qchFilePath() const
|
FilePath CMakeTool::qchFilePath() const
|
||||||
{
|
{
|
||||||
return m_qchFilePath;
|
return m_qchFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath CMakeTool::cmakeExecutable(const Utils::FilePath &path)
|
FilePath CMakeTool::cmakeExecutable(const FilePath &path)
|
||||||
{
|
{
|
||||||
if (Utils::HostOsInfo::isMacHost()) {
|
if (HostOsInfo::isMacHost()) {
|
||||||
const QString executableString = path.toString();
|
const QString executableString = path.toString();
|
||||||
const int appIndex = executableString.lastIndexOf(".app");
|
const int appIndex = executableString.lastIndexOf(".app");
|
||||||
const int appCutIndex = appIndex + 4;
|
const int appCutIndex = appIndex + 4;
|
||||||
@@ -242,17 +245,16 @@ Utils::FilePath CMakeTool::cmakeExecutable(const Utils::FilePath &path)
|
|||||||
const bool containsApp = appIndex >= 0 && !endsWithApp
|
const bool containsApp = appIndex >= 0 && !endsWithApp
|
||||||
&& executableString.at(appCutIndex) == '/';
|
&& executableString.at(appCutIndex) == '/';
|
||||||
if (endsWithApp || containsApp) {
|
if (endsWithApp || containsApp) {
|
||||||
const Utils::FilePath toTest = Utils::FilePath::fromString(
|
const FilePath toTest = FilePath::fromString(executableString.left(appCutIndex))
|
||||||
executableString.left(appCutIndex))
|
.pathAppended("Contents/bin/cmake");
|
||||||
.pathAppended("Contents/bin/cmake");
|
|
||||||
if (toTest.exists())
|
if (toTest.exists())
|
||||||
return toTest.canonicalPath();
|
return toTest.canonicalPath();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Utils::FilePath resolvedPath = path.canonicalPath();
|
const FilePath resolvedPath = path.canonicalPath();
|
||||||
// Evil hack to make snap-packages of CMake work. See QTCREATORBUG-23376
|
// Evil hack to make snap-packages of CMake work. See QTCREATORBUG-23376
|
||||||
if (Utils::HostOsInfo::isLinuxHost() && resolvedPath.fileName() == "snap")
|
if (HostOsInfo::isLinuxHost() && resolvedPath.fileName() == "snap")
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
return resolvedPath;
|
return resolvedPath;
|
||||||
@@ -279,21 +281,21 @@ TextEditor::Keywords CMakeTool::keywords()
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (m_introspection->m_functions.isEmpty() && m_introspection->m_didRun) {
|
if (m_introspection->m_functions.isEmpty() && m_introspection->m_didRun) {
|
||||||
Utils::SynchronousProcess proc;
|
SynchronousProcess proc;
|
||||||
runCMake(proc, {"--help-command-list"}, 5);
|
runCMake(proc, {"--help-command-list"}, 5);
|
||||||
if (proc.result() == Utils::QtcProcess::Finished)
|
if (proc.result() == QtcProcess::Finished)
|
||||||
m_introspection->m_functions = proc.stdOut().split('\n');
|
m_introspection->m_functions = proc.stdOut().split('\n');
|
||||||
|
|
||||||
runCMake(proc, {"--help-commands"}, 5);
|
runCMake(proc, {"--help-commands"}, 5);
|
||||||
if (proc.result() == Utils::QtcProcess::Finished)
|
if (proc.result() == QtcProcess::Finished)
|
||||||
parseFunctionDetailsOutput(proc.stdOut());
|
parseFunctionDetailsOutput(proc.stdOut());
|
||||||
|
|
||||||
runCMake(proc, {"--help-property-list"}, 5);
|
runCMake(proc, {"--help-property-list"}, 5);
|
||||||
if (proc.result() == Utils::QtcProcess::Finished)
|
if (proc.result() == QtcProcess::Finished)
|
||||||
m_introspection->m_variables = parseVariableOutput(proc.stdOut());
|
m_introspection->m_variables = parseVariableOutput(proc.stdOut());
|
||||||
|
|
||||||
runCMake(proc, {"--help-variable-list"}, 5);
|
runCMake(proc, {"--help-variable-list"}, 5);
|
||||||
if (proc.result() == Utils::QtcProcess::Finished) {
|
if (proc.result() == QtcProcess::Finished) {
|
||||||
m_introspection->m_variables.append(parseVariableOutput(proc.stdOut()));
|
m_introspection->m_variables.append(parseVariableOutput(proc.stdOut()));
|
||||||
m_introspection->m_variables = Utils::filteredUnique(m_introspection->m_variables);
|
m_introspection->m_variables = Utils::filteredUnique(m_introspection->m_variables);
|
||||||
Utils::sort(m_introspection->m_variables);
|
Utils::sort(m_introspection->m_variables);
|
||||||
@@ -345,7 +347,7 @@ CMakeTool::PathMapper CMakeTool::pathMapper() const
|
|||||||
{
|
{
|
||||||
if (m_pathMapper)
|
if (m_pathMapper)
|
||||||
return m_pathMapper;
|
return m_pathMapper;
|
||||||
return [](const Utils::FilePath &fn) { return fn; };
|
return [](const FilePath &fn) { return fn; };
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::optional<CMakeTool::ReaderType> CMakeTool::readerType() const
|
Utils::optional<CMakeTool::ReaderType> CMakeTool::readerType() const
|
||||||
@@ -359,12 +361,12 @@ Utils::optional<CMakeTool::ReaderType> CMakeTool::readerType() const
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FilePath CMakeTool::searchQchFile(const Utils::FilePath &executable)
|
FilePath CMakeTool::searchQchFile(const FilePath &executable)
|
||||||
{
|
{
|
||||||
if (executable.isEmpty())
|
if (executable.isEmpty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
Utils::FilePath prefixDir = executable.parentDir().parentDir();
|
FilePath prefixDir = executable.parentDir().parentDir();
|
||||||
QDir docDir{prefixDir.pathAppended("doc/cmake").toString()};
|
QDir docDir{prefixDir.pathAppended("doc/cmake").toString()};
|
||||||
if (!docDir.exists())
|
if (!docDir.exists())
|
||||||
docDir.setPath(prefixDir.pathAppended("share/doc/cmake").toString());
|
docDir.setPath(prefixDir.pathAppended("share/doc/cmake").toString());
|
||||||
@@ -374,7 +376,7 @@ Utils::FilePath CMakeTool::searchQchFile(const Utils::FilePath &executable)
|
|||||||
const QStringList files = docDir.entryList(QStringList("*.qch"));
|
const QStringList files = docDir.entryList(QStringList("*.qch"));
|
||||||
for (const QString &docFile : files) {
|
for (const QString &docFile : files) {
|
||||||
if (docFile.startsWith("cmake", Qt::CaseInsensitive)) {
|
if (docFile.startsWith("cmake", Qt::CaseInsensitive)) {
|
||||||
return Utils::FilePath::fromString(docDir.absoluteFilePath(docFile));
|
return FilePath::fromString(docDir.absoluteFilePath(docFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -485,10 +487,10 @@ QStringList CMakeTool::parseVariableOutput(const QString &output)
|
|||||||
|
|
||||||
void CMakeTool::fetchFromCapabilities() const
|
void CMakeTool::fetchFromCapabilities() const
|
||||||
{
|
{
|
||||||
Utils::SynchronousProcess cmake;
|
SynchronousProcess cmake;
|
||||||
runCMake(cmake, {"-E", "capabilities"});
|
runCMake(cmake, {"-E", "capabilities"});
|
||||||
|
|
||||||
if (cmake.result() == Utils::QtcProcess::Finished) {
|
if (cmake.result() == QtcProcess::Finished) {
|
||||||
m_introspection->m_didRun = true;
|
m_introspection->m_didRun = true;
|
||||||
parseFromCapabilities(cmake.stdOut());
|
parseFromCapabilities(cmake.stdOut());
|
||||||
} else {
|
} else {
|
||||||
|
@@ -32,11 +32,8 @@
|
|||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/id.h>
|
#include <utils/id.h>
|
||||||
#include <utils/optional.h>
|
#include <utils/optional.h>
|
||||||
#include <utils/qtcprocess.h>
|
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QProcess)
|
namespace Utils { class SynchronousProcess; }
|
||||||
|
|
||||||
namespace ProjectExplorer { class Kit; }
|
|
||||||
|
|
||||||
namespace CMakeProjectManager {
|
namespace CMakeProjectManager {
|
||||||
|
|
||||||
|
@@ -48,11 +48,11 @@ namespace Internal {
|
|||||||
// CMakeToolSettingsUpgraders:
|
// CMakeToolSettingsUpgraders:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
class CMakeToolSettingsUpgraderV0 : public Utils::VersionUpgrader
|
class CMakeToolSettingsUpgraderV0 : public VersionUpgrader
|
||||||
{
|
{
|
||||||
// Necessary to make Version 1 supported.
|
// Necessary to make Version 1 supported.
|
||||||
public:
|
public:
|
||||||
CMakeToolSettingsUpgraderV0() : Utils::VersionUpgrader(0, "4.6") { }
|
CMakeToolSettingsUpgraderV0() : VersionUpgrader(0, "4.6") { }
|
||||||
|
|
||||||
// NOOP
|
// NOOP
|
||||||
QVariantMap upgrade(const QVariantMap &data) final { return data; }
|
QVariantMap upgrade(const QVariantMap &data) final { return data; }
|
||||||
@@ -62,38 +62,38 @@ public:
|
|||||||
// Helpers:
|
// Helpers:
|
||||||
// --------------------------------------------------------------------
|
// --------------------------------------------------------------------
|
||||||
|
|
||||||
static const char CMAKE_TOOL_COUNT_KEY[] = "CMakeTools.Count";
|
const char CMAKE_TOOL_COUNT_KEY[] = "CMakeTools.Count";
|
||||||
static const char CMAKE_TOOL_DATA_KEY[] = "CMakeTools.";
|
const char CMAKE_TOOL_DATA_KEY[] = "CMakeTools.";
|
||||||
static const char CMAKE_TOOL_DEFAULT_KEY[] = "CMakeTools.Default";
|
const char CMAKE_TOOL_DEFAULT_KEY[] = "CMakeTools.Default";
|
||||||
static const char CMAKE_TOOL_FILENAME[] = "cmaketools.xml";
|
const char CMAKE_TOOL_FILENAME[] = "cmaketools.xml";
|
||||||
|
|
||||||
static std::vector<std::unique_ptr<CMakeTool>> autoDetectCMakeTools()
|
static std::vector<std::unique_ptr<CMakeTool>> autoDetectCMakeTools()
|
||||||
{
|
{
|
||||||
Utils::Environment env = Environment::systemEnvironment();
|
Environment env = Environment::systemEnvironment();
|
||||||
|
|
||||||
Utils::FilePaths path = env.path();
|
FilePaths path = env.path();
|
||||||
path = Utils::filteredUnique(path);
|
path = Utils::filteredUnique(path);
|
||||||
|
|
||||||
if (HostOsInfo::isWindowsHost()) {
|
if (HostOsInfo::isWindowsHost()) {
|
||||||
for (auto envVar : {"ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"}) {
|
for (auto envVar : {"ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"}) {
|
||||||
if (qEnvironmentVariableIsSet(envVar)) {
|
if (qEnvironmentVariableIsSet(envVar)) {
|
||||||
const QString progFiles = qEnvironmentVariable(envVar);
|
const QString progFiles = qEnvironmentVariable(envVar);
|
||||||
path.append(Utils::FilePath::fromString(progFiles + "/CMake"));
|
path.append(FilePath::fromString(progFiles + "/CMake"));
|
||||||
path.append(Utils::FilePath::fromString(progFiles + "/CMake/bin"));
|
path.append(FilePath::fromString(progFiles + "/CMake/bin"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HostOsInfo::isMacHost()) {
|
if (HostOsInfo::isMacHost()) {
|
||||||
path.append(Utils::FilePath::fromString("/Applications/CMake.app/Contents/bin"));
|
path.append(FilePath::fromString("/Applications/CMake.app/Contents/bin"));
|
||||||
path.append(Utils::FilePath::fromString("/usr/local/bin"));
|
path.append(FilePath::fromString("/usr/local/bin"));
|
||||||
path.append(Utils::FilePath::fromString("/opt/local/bin"));
|
path.append(FilePath::fromString("/opt/local/bin"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList execs = env.appendExeExtensions(QLatin1String("cmake"));
|
const QStringList execs = env.appendExeExtensions(QLatin1String("cmake"));
|
||||||
|
|
||||||
FilePaths suspects;
|
FilePaths suspects;
|
||||||
foreach (const Utils::FilePath &base, path) {
|
foreach (const FilePath &base, path) {
|
||||||
if (base.isEmpty())
|
if (base.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ CMakeToolSettingsAccessor::CMakeTools CMakeToolSettingsAccessor::restoreCMakeToo
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CMakeToolSettingsAccessor::saveCMakeTools(const QList<CMakeTool *> &cmakeTools,
|
void CMakeToolSettingsAccessor::saveCMakeTools(const QList<CMakeTool *> &cmakeTools,
|
||||||
const Utils::Id &defaultId,
|
const Id &defaultId,
|
||||||
QWidget *parent)
|
QWidget *parent)
|
||||||
{
|
{
|
||||||
QVariantMap data;
|
QVariantMap data;
|
||||||
@@ -244,8 +244,7 @@ CMakeToolSettingsAccessor::cmakeTools(const QVariantMap &data, bool fromSdk) con
|
|||||||
result.cmakeTools.emplace_back(std::move(item));
|
result.cmakeTools.emplace_back(std::move(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
result.defaultToolId = Utils::Id::fromSetting(data.value(CMAKE_TOOL_DEFAULT_KEY,
|
result.defaultToolId = Id::fromSetting(data.value(CMAKE_TOOL_DEFAULT_KEY, Id().toSetting()));
|
||||||
Utils::Id().toSetting()));
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user