⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 projectgenerator.cpp

📁 qtmake 文件的代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                    QString dep = tmp[dep_it];
                    dep = fixPathToQmake(dep);
                    QString file_dir = dep.section(Option::dir_sep, 0, -2),
                        file_no_path = dep.section(Option::dir_sep, -1);
                    if(!file_dir.isEmpty()) {
                        for(int inc_it = 0; inc_it < deplist.size(); ++inc_it) {
                            QMakeLocalFileName inc = deplist[inc_it];
                            if(inc.local() == file_dir && !v["INCLUDEPATH"].contains(inc.real()))
                                v["INCLUDEPATH"] += inc.real();
                        }
                    }
                    if(no_qt_files && file_no_path.indexOf(QRegExp("^q[a-z_0-9].h$")) != -1)
                        no_qt_files = false;
                    QString h_ext;
                    for(int hit = 0; hit < Option::h_ext.size(); ++hit) {
                        if(dep.endsWith(Option::h_ext.at(hit))) {
                            h_ext = Option::h_ext.at(hit);
                            break;
                        }
                    }
                    if(!h_ext.isEmpty()) {
                        for(int cppit = 0; cppit < Option::cpp_ext.size(); ++cppit) {
                            QString src(dep.left(dep.length() - h_ext.length()) +
                                        Option::cpp_ext.at(cppit));
                            if(exists(src)) {
                                bool exists = false;
                                QStringList &srcl = v["SOURCES"];
                                for(int src_it = 0; src_it < srcl.size(); ++src_it) {
                                    if(srcl[src_it].toLower() == src.toLower()) {
                                        exists = true;
                                        break;
                                    }
                                }
                                if(!exists)
                                    srcl.append(src);
                            }
                        }
                    } else if(dep.endsWith(Option::lex_ext) &&
                              file_no_path.startsWith(Option::lex_mod)) {
                        addConfig("lex_included");
                    }
                    if(!h.contains(dep))
                        h += dep;
                }
            }
        }
    }

    //strip out files that are actually output from internal compilers (ie temporary files)
    const QStringList &quc = project->variables()["QMAKE_EXTRA_COMPILERS"];
    for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
        QString tmp_out = project->variables()[(*it) + ".output"].first();
        if(tmp_out.isEmpty())
            continue;

        QStringList var_out = project->variables()[(*it) + ".variable_out"];
        bool defaults = var_out.isEmpty();
        for(int i = 0; i < var_out.size(); ++i) {
            QString v = var_out.at(i);
            if(v.startsWith("GENERATED_")) {
                defaults = true;
                break;
            }
        }
        if(defaults) {
            var_out << "SOURCES";
            var_out << "HEADERS";
            var_out << "FORMS";
        }
        const QStringList &tmp = project->variables()[(*it) + ".input"];
        for(QStringList::ConstIterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
            QStringList &inputs = project->variables()[(*it2)];
            for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
                QString path = replaceExtraCompilerVariables(tmp_out, (*input), QString());
                path = fixPathToQmake(path).section('/', -1);
                for(int i = 0; i < var_out.size(); ++i) {
                    QString v = var_out.at(i);
                    QStringList &list = project->variables()[v];
                    for(int src = 0; src < list.size(); ) {
                        if(list[src] == path || list[src].endsWith("/" + path))
                            list.removeAt(src);
                        else
                            ++src;
                    }
                }
            }
        }
    }
}

bool
ProjectGenerator::writeMakefile(QTextStream &t)
{
    t << "######################################################################" << endl;
    t << "# Automatically generated by qmake (" << qmake_version() << ") " << QDateTime::currentDateTime().toString() << endl;
    t << "######################################################################" << endl << endl;
    if(!Option::user_configs.isEmpty())
        t << "CONFIG += " << Option::user_configs.join(" ") << endl;
    int i;
    for(i = 0; i < Option::before_user_vars.size(); ++i)
        t << Option::before_user_vars[i] << endl;
    t << getWritableVar("TEMPLATE_ASSIGN", false);
    if(project->first("TEMPLATE_ASSIGN") == "subdirs") {
        t << endl << "# Directories" << "\n"
          << getWritableVar("SUBDIRS");
    } else {
        t << getWritableVar("TARGET")
          << getWritableVar("CONFIG", false)
          << getWritableVar("CONFIG_REMOVE", false)
          << getWritableVar("DEPENDPATH")
          << getWritableVar("INCLUDEPATH") << endl;

        t << "# Input" << "\n";
        t << getWritableVar("HEADERS")
          << getWritableVar("FORMS")
          << getWritableVar("LEXSOURCES")
          << getWritableVar("YACCSOURCES")
          << getWritableVar("SOURCES")
          << getWritableVar("RESOURCES")
          << getWritableVar("TRANSLATIONS");
    }
    for(i = 0; i < Option::after_user_vars.size(); ++i)
        t << Option::after_user_vars[i] << endl;
    return true;
}

bool
ProjectGenerator::addConfig(const QString &cfg, bool add)
{
    QString where = "CONFIG";
    if(!add)
        where = "CONFIG_REMOVE";
    if(!project->variables()[where].contains(cfg)) {
        project->variables()[where] += cfg;
        return true;
    }
    return false;
}

bool
ProjectGenerator::addFile(QString file)
{
    file = fileFixify(file, qmake_getpwd());
    QString dir;
    int s = file.lastIndexOf(Option::dir_sep);
    if(s != -1)
        dir = file.left(s+1);
    if(file.mid(dir.length(), Option::h_moc_mod.length()) == Option::h_moc_mod)
        return false;

    QString where;
    for(int cppit = 0; cppit < Option::cpp_ext.size(); ++cppit) {
        if(file.endsWith(Option::cpp_ext[cppit])) {
            where = "SOURCES";
            break;
        }
    }
    if(where.isEmpty()) {
        for(int hit = 0; hit < Option::h_ext.size(); ++hit)
            if(file.endsWith(Option::h_ext.at(hit))) {
                where = "HEADERS";
                break;
            }
    }
    if(where.isEmpty()) {
        if(file.endsWith(Option::ui_ext))
            where = "FORMS";
        else if(file.endsWith(".c"))
            where = "SOURCES";
        else if(file.endsWith(Option::lex_ext))
            where = "LEXSOURCES";
        else if(file.endsWith(Option::yacc_ext))
            where = "YACCSOURCES";
        else if(file.endsWith(".ts"))
            where = "TRANSLATIONS";
        else if(file.endsWith(".qrc"))
            where = "RESOURCES";
    }

    QString newfile = fixPathToQmake(fileFixify(file));
    if(!where.isEmpty() && !project->variables()[where].contains(file)) {
        project->variables()[where] += newfile;
        return true;
    }
    return false;
}

QString
ProjectGenerator::getWritableVar(const QString &v, bool)
{
    QStringList &vals = project->variables()[v];
    if(vals.isEmpty())
        return "";

    QString ret;
    if(v.endsWith("_REMOVE"))
        ret = v.left(v.length() - 7) + " -= ";
    else if(v.endsWith("_ASSIGN"))
        ret = v.left(v.length() - 7) + " = ";
    else
        ret = v + " += ";
    QString join = vals.join(" ");
    if(ret.length() + join.length() > 80) {
        QString spaces;
        for(int i = 0; i < ret.length(); i++)
            spaces += " ";
        join = vals.join(" \\\n" + spaces);
    }
    return ret + join + "\n";
}

bool
ProjectGenerator::openOutput(QFile &file, const QString &build) const
{
    QString outdir;
    if(!file.fileName().isEmpty()) {
        QFileInfo fi(fileInfo(file.fileName()));
        if(fi.isDir())
            outdir = fi.path() + QDir::separator();
    }
    if(!outdir.isEmpty() || file.fileName().isEmpty()) {
        QString dir = qmake_getpwd();
        int s = dir.lastIndexOf('/');
        if(s != -1)
            dir = dir.right(dir.length() - (s + 1));
        file.setFileName(outdir + dir + Option::pro_ext);
    }
    return MakefileGenerator::openOutput(file, build);
}


QString
ProjectGenerator::fixPathToQmake(const QString &file)
{
    QString ret = file;
    if(Option::dir_sep != QLatin1String("/"))
        ret = ret.replace(Option::dir_sep, QLatin1String("/"));
    return ret;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -