2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeproject.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
#include "cmakebuildconfiguration.h"
|
2019-04-12 14:49:59 +02:00
|
|
|
#include "cmakebuildstep.h"
|
2016-01-06 15:51:44 +01:00
|
|
|
#include "cmakekitinformation.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeprojectconstants.h"
|
|
|
|
|
#include "cmakeprojectnodes.h"
|
2015-03-10 10:22:38 +01:00
|
|
|
#include "cmakeprojectmanager.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-12-04 03:36:12 +10:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2017-02-06 16:59:53 +01:00
|
|
|
#include <cpptools/cpprawprojectpart.h>
|
|
|
|
|
#include <cpptools/cppprojectupdater.h>
|
2016-10-06 11:31:23 +02:00
|
|
|
#include <cpptools/generatedcodemodelsupport.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
2016-12-04 03:36:12 +10:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
2019-04-12 14:49:59 +02:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
2013-07-07 23:49:13 +02:00
|
|
|
#include <projectexplorer/buildtargetinfo.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/deploymentdata.h>
|
|
|
|
|
#include <projectexplorer/headerpath.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2017-09-28 11:32:39 +02:00
|
|
|
#include <projectexplorer/kitmanager.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2010-11-01 14:14:17 +01:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2013-01-17 15:12:46 +01:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
2019-01-04 12:35:28 +01:00
|
|
|
#include <qtsupport/qtcppkitinfo.h>
|
2013-01-17 15:12:46 +01:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2016-04-18 13:06:41 +02:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2016-10-06 11:31:23 +02:00
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2019-05-29 18:54:45 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2012-11-19 14:18:14 +01:00
|
|
|
#include <utils/stringutils.h>
|
2013-01-01 18:18:03 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2019-06-20 15:49:05 +02:00
|
|
|
#include <QElapsedTimer>
|
2016-06-14 17:43:11 +02:00
|
|
|
#include <QSet>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
using namespace ProjectExplorer;
|
2015-02-01 18:44:47 +02:00
|
|
|
using namespace Utils;
|
2008-12-12 17:22:02 +01:00
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
namespace CMakeProjectManager {
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
static CMakeBuildConfiguration *activeBc(const CMakeProject *p)
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<CMakeBuildConfiguration *>(p->activeTarget() ? p->activeTarget()->activeBuildConfiguration() : nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-12 17:22:02 +01:00
|
|
|
// QtCreator CMake Generator wishlist:
|
|
|
|
|
// Which make targets we need to build to get all executables
|
|
|
|
|
// What is the actual compiler executable
|
|
|
|
|
// DEFINES
|
|
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
/*!
|
|
|
|
|
\class CMakeProject
|
|
|
|
|
*/
|
2019-08-05 15:56:03 +02:00
|
|
|
CMakeProject::CMakeProject(const FilePath &fileName)
|
|
|
|
|
: Project(Constants::CMAKEMIMETYPE, fileName)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-10-06 11:31:23 +02:00
|
|
|
setId(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
2017-01-30 14:59:10 +01:00
|
|
|
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
2017-04-07 14:35:49 +02:00
|
|
|
setDisplayName(projectDirectory().fileName());
|
2019-06-03 17:36:02 +02:00
|
|
|
setCanBuildProducts();
|
2019-08-08 17:28:11 +02:00
|
|
|
setKnowsAllBuildExecutables(false);
|
2019-08-13 12:11:07 +02:00
|
|
|
setHasMakeInstallEquivalent(true);
|
2019-08-09 11:22:49 +02:00
|
|
|
|
|
|
|
|
setBuildSystem(std::make_unique<CMakeBuildSystem>(this));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2019-08-06 12:41:46 +02:00
|
|
|
CMakeProject::~CMakeProject() = default;
|
2016-04-18 13:06:41 +02:00
|
|
|
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks CMakeProject::projectIssues(const Kit *k) const
|
2016-01-06 15:51:44 +01:00
|
|
|
{
|
2019-05-27 16:09:44 +02:00
|
|
|
Tasks result = Project::projectIssues(k);
|
2018-04-18 13:39:05 +02:00
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
if (!CMakeKitAspect::cmakeTool(k))
|
2018-04-18 13:39:05 +02:00
|
|
|
result.append(createProjectTask(Task::TaskType::Error, tr("No cmake tool set.")));
|
2019-02-06 12:50:51 +01:00
|
|
|
if (ToolChainKitAspect::toolChains(k).isEmpty())
|
2018-04-18 13:39:05 +02:00
|
|
|
result.append(createProjectTask(Task::TaskType::Warning, tr("No compilers set in kit.")));
|
|
|
|
|
|
|
|
|
|
return result;
|
2016-01-06 15:51:44 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
void CMakeProject::runCMake()
|
|
|
|
|
{
|
2017-11-21 11:06:41 +01:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
if (isParsing() || !bc)
|
2017-07-28 11:16:18 +02:00
|
|
|
return;
|
2016-01-20 12:19:16 +01:00
|
|
|
|
2017-11-21 11:06:41 +01:00
|
|
|
BuildDirParameters parameters(bc);
|
2019-08-05 15:56:03 +02:00
|
|
|
bc->m_buildDirManager
|
|
|
|
|
.setParametersAndRequestParse(parameters,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION
|
|
|
|
|
| BuildDirManager::REPARSE_FORCE_CMAKE_RUN);
|
2017-07-28 11:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeProject::runCMakeAndScanProjectTree()
|
|
|
|
|
{
|
2017-11-21 11:06:41 +01:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
if (isParsing() || !bc)
|
2017-07-28 11:16:18 +02:00
|
|
|
return;
|
|
|
|
|
|
2017-11-21 11:06:41 +01:00
|
|
|
BuildDirParameters parameters(bc);
|
2019-08-05 15:56:03 +02:00
|
|
|
bc->m_buildDirManager.setParametersAndRequestParse(parameters,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION
|
|
|
|
|
| BuildDirManager::REPARSE_SCAN);
|
2011-03-31 17:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 15:18:25 +01:00
|
|
|
void CMakeProject::buildCMakeTarget(const QString &buildTarget)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!buildTarget.isEmpty(), return);
|
2017-09-28 11:32:39 +02:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
2016-11-14 15:18:25 +01:00
|
|
|
if (bc)
|
|
|
|
|
bc->buildTarget(buildTarget);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 14:33:44 +02:00
|
|
|
ProjectImporter *CMakeProject::projectImporter() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_projectImporter)
|
|
|
|
|
m_projectImporter = std::make_unique<CMakeProjectImporter>(projectFilePath());
|
|
|
|
|
return m_projectImporter.get();
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
bool CMakeProject::persistCMakeState()
|
|
|
|
|
{
|
2019-08-05 15:56:03 +02:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
return bc ? bc->m_buildDirManager.persistCMakeState() : false;
|
2017-09-28 11:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeProject::clearCMakeCache()
|
|
|
|
|
{
|
2019-08-05 15:56:03 +02:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
if (bc)
|
|
|
|
|
bc->m_buildDirManager.clearCache();
|
2017-09-28 11:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-02 17:46:19 +02:00
|
|
|
bool CMakeProject::setupTarget(Target *t)
|
|
|
|
|
{
|
2013-07-07 23:49:13 +02:00
|
|
|
t->updateDefaultBuildConfigurations();
|
2014-07-31 16:36:46 +02:00
|
|
|
if (t->buildConfigurations().isEmpty())
|
|
|
|
|
return false;
|
2013-07-07 23:49:13 +02:00
|
|
|
t->updateDefaultDeployConfigurations();
|
2012-10-02 17:46:19 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const
|
2010-09-24 13:17:43 +02:00
|
|
|
{
|
2015-09-10 16:17:38 +02:00
|
|
|
if (!activeTarget())
|
2016-01-15 16:12:54 +01:00
|
|
|
return QStringList();
|
|
|
|
|
QFileInfo fi(sourceFile);
|
2019-05-28 13:49:26 +02:00
|
|
|
FilePath project = projectDirectory();
|
|
|
|
|
FilePath baseDirectory = FilePath::fromString(fi.absolutePath());
|
2013-01-08 17:21:18 +01:00
|
|
|
|
|
|
|
|
while (baseDirectory.isChildOf(project)) {
|
2019-05-28 13:49:26 +02:00
|
|
|
const FilePath cmakeListsTxt = baseDirectory.pathAppended("CMakeLists.txt");
|
2014-10-24 13:15:54 +02:00
|
|
|
if (cmakeListsTxt.exists())
|
2013-01-08 17:21:18 +01:00
|
|
|
break;
|
2019-06-20 14:58:33 +02:00
|
|
|
baseDirectory = baseDirectory.parentDir();
|
2013-01-08 17:21:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDir srcDirRoot = QDir(project.toString());
|
|
|
|
|
QString relativePath = srcDirRoot.relativeFilePath(baseDirectory.toString());
|
2013-08-16 17:45:16 +02:00
|
|
|
QDir buildDir = QDir(activeTarget()->activeBuildConfiguration()->buildDirectory().toString());
|
2016-01-15 16:12:54 +01:00
|
|
|
QString generatedFilePath = buildDir.absoluteFilePath(relativePath);
|
2013-01-08 17:21:18 +01:00
|
|
|
|
2016-10-06 11:31:23 +02:00
|
|
|
if (fi.suffix() == "ui") {
|
|
|
|
|
generatedFilePath += "/ui_";
|
2016-01-15 16:12:54 +01:00
|
|
|
generatedFilePath += fi.completeBaseName();
|
2016-10-06 11:31:23 +02:00
|
|
|
generatedFilePath += ".h";
|
2016-01-15 16:12:54 +01:00
|
|
|
return QStringList(QDir::cleanPath(generatedFilePath));
|
2016-10-06 11:31:23 +02:00
|
|
|
} else if (fi.suffix() == "scxml") {
|
|
|
|
|
generatedFilePath += "/";
|
2016-01-15 16:58:22 +01:00
|
|
|
generatedFilePath += QDir::cleanPath(fi.completeBaseName());
|
2017-02-22 15:09:35 +01:00
|
|
|
return QStringList({generatedFilePath + ".h",
|
|
|
|
|
generatedFilePath + ".cpp"});
|
2016-01-15 16:12:54 +01:00
|
|
|
} else {
|
|
|
|
|
// TODO: Other types will be added when adapters for their compilers become available.
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
2010-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-12 14:49:59 +02:00
|
|
|
ProjectExplorer::DeploymentKnowledge CMakeProject::deploymentKnowledge() const
|
|
|
|
|
{
|
2019-06-18 16:21:56 +02:00
|
|
|
return !files([](const ProjectExplorer::Node *n) {
|
|
|
|
|
return n->filePath().fileName() == "QtCreatorDeployment.txt";
|
|
|
|
|
})
|
|
|
|
|
.isEmpty()
|
|
|
|
|
? DeploymentKnowledge::Approximative
|
|
|
|
|
: DeploymentKnowledge::Bad;
|
2019-04-12 14:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MakeInstallCommand CMakeProject::makeInstallCommand(const Target *target,
|
|
|
|
|
const QString &installRoot)
|
|
|
|
|
{
|
|
|
|
|
MakeInstallCommand cmd;
|
|
|
|
|
if (const BuildConfiguration * const bc = target->activeBuildConfiguration()) {
|
|
|
|
|
if (const auto cmakeStep = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD)
|
|
|
|
|
->firstOfType<CMakeBuildStep>()) {
|
2019-05-29 18:54:45 +02:00
|
|
|
if (CMakeTool *tool = CMakeKitAspect::cmakeTool(target->kit()))
|
|
|
|
|
cmd.command = tool->cmakeExecutable();
|
2019-04-12 14:49:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cmd.arguments << "--build" << "." << "--target" << "install";
|
|
|
|
|
cmd.environment.set("DESTDIR", QDir::toNativeSeparators(installRoot));
|
|
|
|
|
return cmd;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-06 12:41:46 +02:00
|
|
|
bool CMakeProject::mustUpdateCMakeStateBeforeBuild() const
|
2017-07-28 11:16:18 +02:00
|
|
|
{
|
2019-08-06 12:41:46 +02:00
|
|
|
return buildSystem()->isWaitingForParse();
|
2010-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
} // namespace CMakeProjectManager
|