forked from qt-creator/qt-creator
CMake: use FilePaths to parse source and build dir
Change-Id: I59523a525fd07402e3ade6cd6b7eaee69aa5abe0 Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -426,27 +426,25 @@ RawProjectParts generateRawProjectParts(const PreprocessedData &input,
|
|||||||
return rpps;
|
return rpps;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath directorySourceDir(const Configuration &c, const QDir &sourceDir, int directoryIndex)
|
FilePath directorySourceDir(const Configuration &c, const FilePath &sourceDir, int directoryIndex)
|
||||||
{
|
{
|
||||||
const size_t di = static_cast<size_t>(directoryIndex);
|
const size_t di = static_cast<size_t>(directoryIndex);
|
||||||
QTC_ASSERT(di < c.directories.size(), return FilePath());
|
QTC_ASSERT(di < c.directories.size(), return FilePath());
|
||||||
|
|
||||||
return FilePath::fromString(
|
return sourceDir.resolvePath(c.directories[di].sourcePath).cleanPath();
|
||||||
QDir::cleanPath(sourceDir.absoluteFilePath(c.directories[di].sourcePath)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath directoryBuildDir(const Configuration &c, const QDir &buildDir, int directoryIndex)
|
FilePath directoryBuildDir(const Configuration &c, const FilePath &buildDir, int directoryIndex)
|
||||||
{
|
{
|
||||||
const size_t di = static_cast<size_t>(directoryIndex);
|
const size_t di = static_cast<size_t>(directoryIndex);
|
||||||
QTC_ASSERT(di < c.directories.size(), return FilePath());
|
QTC_ASSERT(di < c.directories.size(), return FilePath());
|
||||||
|
|
||||||
return FilePath::fromString(
|
return buildDir.resolvePath(c.directories[di].buildPath).cleanPath();
|
||||||
QDir::cleanPath(buildDir.absoluteFilePath(c.directories[di].buildPath)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void addProjects(const QHash<Utils::FilePath, ProjectNode *> &cmakeListsNodes,
|
void addProjects(const QHash<Utils::FilePath, ProjectNode *> &cmakeListsNodes,
|
||||||
const Configuration &config,
|
const Configuration &config,
|
||||||
const QDir &sourceDir)
|
const FilePath &sourceDir)
|
||||||
{
|
{
|
||||||
for (const FileApiDetails::Project &p : config.projects) {
|
for (const FileApiDetails::Project &p : config.projects) {
|
||||||
if (p.parent == -1)
|
if (p.parent == -1)
|
||||||
@@ -504,15 +502,12 @@ void addCompileGroups(ProjectNode *targetRoot,
|
|||||||
targetRoot->forEachGenericNode(
|
targetRoot->forEachGenericNode(
|
||||||
[&alreadyListed](const Node *n) { alreadyListed.insert(n->filePath()); });
|
[&alreadyListed](const Node *n) { alreadyListed.insert(n->filePath()); });
|
||||||
|
|
||||||
const QDir topSourceDir(topSourceDirectory.toString());
|
|
||||||
|
|
||||||
std::vector<std::unique_ptr<FileNode>> buildFileNodes;
|
std::vector<std::unique_ptr<FileNode>> buildFileNodes;
|
||||||
std::vector<std::unique_ptr<FileNode>> otherFileNodes;
|
std::vector<std::unique_ptr<FileNode>> otherFileNodes;
|
||||||
std::vector<std::vector<std::unique_ptr<FileNode>>> sourceGroupFileNodes{td.sourceGroups.size()};
|
std::vector<std::vector<std::unique_ptr<FileNode>>> sourceGroupFileNodes{td.sourceGroups.size()};
|
||||||
|
|
||||||
for (const SourceInfo &si : td.sources) {
|
for (const SourceInfo &si : td.sources) {
|
||||||
const FilePath sourcePath = FilePath::fromString(
|
const FilePath sourcePath = topSourceDirectory.resolvePath(si.path).cleanPath();
|
||||||
QDir::cleanPath(topSourceDir.absoluteFilePath(si.path)));
|
|
||||||
|
|
||||||
// Filter out already known files:
|
// Filter out already known files:
|
||||||
const int count = alreadyListed.count();
|
const int count = alreadyListed.count();
|
||||||
@@ -574,9 +569,8 @@ void addCompileGroups(ProjectNode *targetRoot,
|
|||||||
void addTargets(const QHash<Utils::FilePath, ProjectExplorer::ProjectNode *> &cmakeListsNodes,
|
void addTargets(const QHash<Utils::FilePath, ProjectExplorer::ProjectNode *> &cmakeListsNodes,
|
||||||
const Configuration &config,
|
const Configuration &config,
|
||||||
const std::vector<TargetDetails> &targetDetails,
|
const std::vector<TargetDetails> &targetDetails,
|
||||||
const FilePath &topSourceDir,
|
const FilePath &sourceDir,
|
||||||
const QDir &sourceDir,
|
const FilePath &buildDir,
|
||||||
const QDir &buildDir,
|
|
||||||
QSet<FilePath> &knownHeaderNodes)
|
QSet<FilePath> &knownHeaderNodes)
|
||||||
{
|
{
|
||||||
for (const FileApiDetails::Target &t : config.targets) {
|
for (const FileApiDetails::Target &t : config.targets) {
|
||||||
@@ -591,7 +585,7 @@ void addTargets(const QHash<Utils::FilePath, ProjectExplorer::ProjectNode *> &cm
|
|||||||
tNode->setTargetInformation(td.artifacts, td.type);
|
tNode->setTargetInformation(td.artifacts, td.type);
|
||||||
tNode->setBuildDirectory(directoryBuildDir(config, buildDir, t.directory));
|
tNode->setBuildDirectory(directoryBuildDir(config, buildDir, t.directory));
|
||||||
|
|
||||||
addCompileGroups(tNode, topSourceDir, dir, tNode->buildDirectory(), td, knownHeaderNodes);
|
addCompileGroups(tNode, sourceDir, dir, tNode->buildDirectory(), td, knownHeaderNodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,9 +595,6 @@ std::pair<std::unique_ptr<CMakeProjectNode>, QSet<FilePath>> generateRootProject
|
|||||||
std::pair<std::unique_ptr<CMakeProjectNode>, QSet<FilePath>> result;
|
std::pair<std::unique_ptr<CMakeProjectNode>, QSet<FilePath>> result;
|
||||||
result.first = std::make_unique<CMakeProjectNode>(sourceDirectory);
|
result.first = std::make_unique<CMakeProjectNode>(sourceDirectory);
|
||||||
|
|
||||||
const QDir sourceDir(sourceDirectory.toString());
|
|
||||||
const QDir buildDir(buildDirectory.toString());
|
|
||||||
|
|
||||||
const FileApiDetails::Project topLevelProject
|
const FileApiDetails::Project topLevelProject
|
||||||
= findOrDefault(data.codemodel.projects, equal(&FileApiDetails::Project::parent, -1));
|
= findOrDefault(data.codemodel.projects, equal(&FileApiDetails::Project::parent, -1));
|
||||||
if (!topLevelProject.name.isEmpty())
|
if (!topLevelProject.name.isEmpty())
|
||||||
@@ -616,14 +607,13 @@ std::pair<std::unique_ptr<CMakeProjectNode>, QSet<FilePath>> generateRootProject
|
|||||||
data.cmakeListNodes.clear(); // Remove all the nullptr in the vector...
|
data.cmakeListNodes.clear(); // Remove all the nullptr in the vector...
|
||||||
|
|
||||||
QSet<FilePath> knownHeaders;
|
QSet<FilePath> knownHeaders;
|
||||||
addProjects(cmakeListsNodes, data.codemodel, sourceDir);
|
addProjects(cmakeListsNodes, data.codemodel, sourceDirectory);
|
||||||
|
|
||||||
addTargets(cmakeListsNodes,
|
addTargets(cmakeListsNodes,
|
||||||
data.codemodel,
|
data.codemodel,
|
||||||
data.targetDetails,
|
data.targetDetails,
|
||||||
sourceDirectory,
|
sourceDirectory,
|
||||||
sourceDir,
|
buildDirectory,
|
||||||
buildDir,
|
|
||||||
knownHeaders);
|
knownHeaders);
|
||||||
|
|
||||||
// addHeaderNodes(root.get(), knownHeaders, allFiles);
|
// addHeaderNodes(root.get(), knownHeaders, allFiles);
|
||||||
|
|||||||
Reference in New Issue
Block a user