static ProjectNode *updateCMakeInputs(CMakeListsNode *root,
                                      const Utils::FileName &sourceDir,
                                      const Utils::FileName &buildDir,
                                      QList<FileNode *> &sourceInputs,
                                      QList<FileNode *> &buildInputs,
                                      QList<FileNode *> &rootInputs)
{
    const bool hasInputs = !sourceInputs.isEmpty() || !buildInputs.isEmpty() || !rootInputs.isEmpty();
    ProjectNode *cmakeVFolder
        = root->projectNode(CMakeInputsNode::inputsPathFromCMakeListsPath(root->filePath()));
    if (!cmakeVFolder) {
        if (hasInputs) {
            cmakeVFolder = new CMakeInputsNode(root->filePath());
            root->addProjectNodes({ cmakeVFolder });
        }
    } else {
        if (!hasInputs)
            root->removeProjectNodes({ cmakeVFolder });
    }
    if (!hasInputs)
        return nullptr;

    QList<FolderNode *> toKeep;
    toKeep.append(setupCMakeVFolder(cmakeVFolder, sourceDir, 1000,
                                    QCoreApplication::translate("CMakeProjectManager::Internal", "<Source Directory>"),
                                    sourceInputs));
    toKeep.append(setupCMakeVFolder(cmakeVFolder, buildDir, 100,
                                    QCoreApplication::translate("CMakeProjectManager::Internal", "<Build Directory>"),
                                    buildInputs));
    toKeep.append(setupCMakeVFolder(cmakeVFolder, Utils::FileName(), 10,
                                    QCoreApplication::translate("CMakeProjectManager::Internal", "<Other Locations>"),
                                    rootInputs));

    // Clean out unused nodes in "CMake Files":
    const QList<FolderNode *> tmp = filtered(cmakeVFolder->folderNodes(), [&toKeep](FolderNode *fn) {
        return !toKeep.contains(fn);
    });
    cmakeVFolder->removeFolderNodes(tmp);

    return cmakeVFolder;
}