2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include "projectgenerator.h"
|
|
|
|
#include "option.h"
|
|
|
|
#include <qdatetime.h>
|
|
|
|
#include <qdir.h>
|
|
|
|
#include <qfile.h>
|
|
|
|
#include <qfileinfo.h>
|
2020-04-03 15:11:36 +00:00
|
|
|
#include <qregularexpression.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2019-08-16 20:01:09 +00:00
|
|
|
static QString project_builtin_regx() //calculate the builtin regular expression..
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QString ret;
|
|
|
|
QStringList builtin_exts;
|
|
|
|
builtin_exts << Option::c_ext << Option::ui_ext << Option::yacc_ext << Option::lex_ext << ".ts" << ".xlf" << ".qrc";
|
|
|
|
builtin_exts += Option::h_ext + Option::cpp_ext;
|
|
|
|
for(int i = 0; i < builtin_exts.size(); ++i) {
|
|
|
|
if(!ret.isEmpty())
|
|
|
|
ret += "; ";
|
|
|
|
ret += QString("*") + builtin_exts[i];
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ProjectGenerator::init()
|
|
|
|
{
|
|
|
|
int file_count = 0;
|
|
|
|
verifyCompilers();
|
|
|
|
|
2012-09-05 16:29:19 +00:00
|
|
|
project->loadSpec();
|
|
|
|
project->evaluateFeatureFile("default_pre.prf");
|
|
|
|
project->evaluateFeatureFile("default_post.prf");
|
|
|
|
project->evaluateConfigFeatures();
|
2012-04-23 16:08:16 +00:00
|
|
|
project->values("CONFIG").clear();
|
2012-08-03 17:35:54 +00:00
|
|
|
Option::postProcessProject(project);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
ProValueMap &v = project->variables();
|
2012-09-05 16:29:19 +00:00
|
|
|
QString templ = Option::globals->user_template.isEmpty() ? QString("app") : Option::globals->user_template;
|
|
|
|
if (!Option::globals->user_template_prefix.isEmpty())
|
|
|
|
templ.prepend(Option::globals->user_template_prefix);
|
2011-04-27 10:05:43 +00:00
|
|
|
v["TEMPLATE_ASSIGN"] += templ;
|
|
|
|
|
|
|
|
//the scary stuff
|
|
|
|
if(project->first("TEMPLATE_ASSIGN") != "subdirs") {
|
|
|
|
QString builtin_regex = project_builtin_regx();
|
|
|
|
QStringList dirs = Option::projfile::project_dirs;
|
|
|
|
if(Option::projfile::do_pwd) {
|
|
|
|
if(!v["INCLUDEPATH"].contains("."))
|
|
|
|
v["INCLUDEPATH"] += ".";
|
|
|
|
dirs.prepend(qmake_getpwd());
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < dirs.count(); ++i) {
|
|
|
|
QString dir, regex, pd = dirs.at(i);
|
|
|
|
bool add_depend = false;
|
|
|
|
if(exists(pd)) {
|
|
|
|
QFileInfo fi(fileInfo(pd));
|
|
|
|
if(fi.isDir()) {
|
|
|
|
dir = pd;
|
|
|
|
add_depend = true;
|
|
|
|
if(dir.right(1) != Option::dir_sep)
|
|
|
|
dir += Option::dir_sep;
|
2012-05-04 18:02:35 +00:00
|
|
|
if (Option::recursive) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QStringList files = QDir(dir).entryList(QDir::Files);
|
2014-04-29 12:17:33 +00:00
|
|
|
for (int i = 0; i < files.count(); i++)
|
|
|
|
dirs.append(dir + files[i] + QDir::separator() + builtin_regex);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
regex = builtin_regex;
|
|
|
|
} else {
|
|
|
|
QString file = pd;
|
|
|
|
int s = file.lastIndexOf(Option::dir_sep);
|
|
|
|
if(s != -1)
|
|
|
|
dir = file.left(s+1);
|
|
|
|
if(addFile(file)) {
|
|
|
|
add_depend = true;
|
|
|
|
file_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { //regexp
|
|
|
|
regex = pd;
|
|
|
|
}
|
|
|
|
if(!regex.isEmpty()) {
|
|
|
|
int s = regex.lastIndexOf(Option::dir_sep);
|
|
|
|
if(s != -1) {
|
|
|
|
dir = regex.left(s+1);
|
|
|
|
regex = regex.right(regex.length() - (s+1));
|
|
|
|
}
|
2017-06-13 13:10:30 +00:00
|
|
|
const QDir d(dir);
|
2012-05-04 18:02:35 +00:00
|
|
|
if (Option::recursive) {
|
2017-06-13 13:10:30 +00:00
|
|
|
QStringList entries = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
2014-04-29 10:42:54 +00:00
|
|
|
for (int i = 0; i < entries.count(); i++)
|
|
|
|
dirs.append(dir + entries[i] + QDir::separator() + regex);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2017-06-13 13:10:30 +00:00
|
|
|
QStringList files = d.entryList(QDir::nameFiltersFromString(regex));
|
2011-04-27 10:05:43 +00:00
|
|
|
for(int i = 0; i < (int)files.count(); i++) {
|
2017-06-13 13:10:30 +00:00
|
|
|
QString file = d.absoluteFilePath(files[i]);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (addFile(file)) {
|
|
|
|
add_depend = true;
|
|
|
|
file_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(add_depend && !dir.isEmpty() && !v["DEPENDPATH"].contains(dir, Qt::CaseInsensitive)) {
|
|
|
|
QFileInfo fi(fileInfo(dir));
|
|
|
|
if(fi.absoluteFilePath() != qmake_getpwd())
|
|
|
|
v["DEPENDPATH"] += fileFixify(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!file_count) { //shall we try a subdir?
|
|
|
|
QStringList knownDirs = Option::projfile::project_dirs;
|
|
|
|
if(Option::projfile::do_pwd)
|
|
|
|
knownDirs.prepend(".");
|
|
|
|
const QString out_file = fileFixify(Option::output.fileName());
|
|
|
|
for(int i = 0; i < knownDirs.count(); ++i) {
|
|
|
|
QString pd = knownDirs.at(i);
|
|
|
|
if(exists(pd)) {
|
|
|
|
QString newdir = pd;
|
|
|
|
QFileInfo fi(fileInfo(newdir));
|
|
|
|
if(fi.isDir()) {
|
2016-12-12 11:57:47 +00:00
|
|
|
newdir = fileFixify(newdir, FileFixifyFromOutdir);
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList &subdirs = v["SUBDIRS"];
|
2011-04-27 10:05:43 +00:00
|
|
|
if(exists(fi.filePath() + QDir::separator() + fi.fileName() + Option::pro_ext) &&
|
|
|
|
!subdirs.contains(newdir, Qt::CaseInsensitive)) {
|
|
|
|
subdirs.append(newdir);
|
|
|
|
} else {
|
|
|
|
QStringList profiles = QDir(newdir).entryList(QStringList("*" + Option::pro_ext), QDir::Files);
|
|
|
|
for(int i = 0; i < (int)profiles.count(); i++) {
|
|
|
|
QString nd = newdir;
|
|
|
|
if(nd == ".")
|
|
|
|
nd = "";
|
2015-10-10 08:00:32 +00:00
|
|
|
else if (!nd.isEmpty() && !nd.endsWith(QDir::separator()))
|
2011-04-27 10:05:43 +00:00
|
|
|
nd += QDir::separator();
|
|
|
|
nd += profiles[i];
|
|
|
|
fileFixify(nd);
|
2014-04-29 12:17:33 +00:00
|
|
|
if (!subdirs.contains(nd, Qt::CaseInsensitive) && !out_file.endsWith(nd))
|
2011-04-27 10:05:43 +00:00
|
|
|
subdirs.append(nd);
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 18:02:35 +00:00
|
|
|
if (Option::recursive) {
|
2014-04-29 10:42:54 +00:00
|
|
|
QStringList dirs = QDir(newdir).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
2011-04-27 10:05:43 +00:00
|
|
|
for(int i = 0; i < (int)dirs.count(); i++) {
|
|
|
|
QString nd = fileFixify(newdir + QDir::separator() + dirs[i]);
|
2014-04-29 10:42:54 +00:00
|
|
|
if (!knownDirs.contains(nd, Qt::CaseInsensitive))
|
2011-04-27 10:05:43 +00:00
|
|
|
knownDirs.append(nd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { //regexp
|
|
|
|
QString regx = pd, dir;
|
|
|
|
int s = regx.lastIndexOf(Option::dir_sep);
|
|
|
|
if(s != -1) {
|
|
|
|
dir = regx.left(s+1);
|
|
|
|
regx = regx.right(regx.length() - (s+1));
|
|
|
|
}
|
2014-04-29 10:42:54 +00:00
|
|
|
QStringList files = QDir(dir).entryList(QDir::nameFiltersFromString(regx),
|
|
|
|
QDir::Dirs | QDir::NoDotAndDotDot);
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList &subdirs = v["SUBDIRS"];
|
2011-04-27 10:05:43 +00:00
|
|
|
for(int i = 0; i < (int)files.count(); i++) {
|
|
|
|
QString newdir(dir + files[i]);
|
|
|
|
QFileInfo fi(fileInfo(newdir));
|
2014-04-29 10:42:54 +00:00
|
|
|
{
|
2011-04-27 10:05:43 +00:00
|
|
|
newdir = fileFixify(newdir);
|
|
|
|
if(exists(fi.filePath() + QDir::separator() + fi.fileName() + Option::pro_ext) &&
|
|
|
|
!subdirs.contains(newdir)) {
|
|
|
|
subdirs.append(newdir);
|
|
|
|
} else {
|
|
|
|
QStringList profiles = QDir(newdir).entryList(QStringList("*" + Option::pro_ext), QDir::Files);
|
|
|
|
for(int i = 0; i < (int)profiles.count(); i++) {
|
|
|
|
QString nd = newdir + QDir::separator() + files[i];
|
|
|
|
fileFixify(nd);
|
|
|
|
if(files[i] != "." && files[i] != ".." && !subdirs.contains(nd, Qt::CaseInsensitive)) {
|
|
|
|
if(newdir + files[i] != Option::output_dir + Option::output.fileName())
|
|
|
|
subdirs.append(nd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 18:02:35 +00:00
|
|
|
if (Option::recursive && !knownDirs.contains(newdir, Qt::CaseInsensitive))
|
2011-04-27 10:05:43 +00:00
|
|
|
knownDirs.append(newdir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-06 10:21:38 +00:00
|
|
|
v["TEMPLATE_ASSIGN"] = ProStringList("subdirs");
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//setup deplist
|
2020-07-06 09:11:44 +00:00
|
|
|
QList<QMakeLocalFileName> deplist;
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-09-06 10:21:38 +00:00
|
|
|
const ProStringList &d = v["DEPENDPATH"];
|
2011-04-27 10:05:43 +00:00
|
|
|
for(int i = 0; i < d.size(); ++i)
|
2012-09-06 10:21:38 +00:00
|
|
|
deplist.append(QMakeLocalFileName(d[i].toQString()));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
setDependencyPaths(deplist);
|
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList &h = v["HEADERS"];
|
2011-04-27 10:05:43 +00:00
|
|
|
bool no_qt_files = true;
|
2018-08-02 22:22:24 +00:00
|
|
|
static const char *srcs[] = { "SOURCES", "YACCSOURCES", "LEXSOURCES", "FORMS", nullptr };
|
2012-08-20 11:04:39 +00:00
|
|
|
for (int i = 0; srcs[i]; i++) {
|
2012-09-06 10:21:38 +00:00
|
|
|
const ProStringList &l = v[srcs[i]];
|
2011-04-27 10:05:43 +00:00
|
|
|
QMakeSourceFileInfo::SourceFileType type = QMakeSourceFileInfo::TYPE_C;
|
|
|
|
QMakeSourceFileInfo::addSourceFiles(l, QMakeSourceFileInfo::SEEK_DEPS, type);
|
|
|
|
for(int i = 0; i < l.size(); ++i) {
|
2012-09-06 10:21:38 +00:00
|
|
|
QStringList tmp = QMakeSourceFileInfo::dependencies(l.at(i).toQString());
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!tmp.isEmpty()) {
|
|
|
|
for(int dep_it = 0; dep_it < tmp.size(); ++dep_it) {
|
|
|
|
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(), Qt::CaseInsensitive))
|
|
|
|
v["INCLUDEPATH"] += inc.real();
|
|
|
|
}
|
|
|
|
}
|
2020-04-03 15:11:36 +00:00
|
|
|
if (no_qt_files && file_no_path.contains(QRegularExpression("^q[a-z_0-9].h$")))
|
2011-04-27 10:05:43 +00:00
|
|
|
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)) {
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList &srcl = v["SOURCES"];
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!srcl.contains(src, Qt::CaseInsensitive))
|
|
|
|
srcl.append(src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(dep.endsWith(Option::lex_ext) &&
|
|
|
|
file_no_path.startsWith(Option::lex_mod)) {
|
|
|
|
addConfig("lex_included");
|
|
|
|
}
|
|
|
|
if(!h.contains(dep, Qt::CaseInsensitive))
|
|
|
|
h += dep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//strip out files that are actually output from internal compilers (ie temporary files)
|
2012-09-06 10:21:38 +00:00
|
|
|
const ProStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
|
|
|
|
for (ProStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
|
|
|
|
QString tmp_out = project->first(ProKey(*it + ".output")).toQString();
|
2011-04-27 10:05:43 +00:00
|
|
|
if(tmp_out.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList var_out = project->values(ProKey(*it + ".variable_out"));
|
2011-04-27 10:05:43 +00:00
|
|
|
bool defaults = var_out.isEmpty();
|
|
|
|
for(int i = 0; i < var_out.size(); ++i) {
|
2012-09-06 10:21:38 +00:00
|
|
|
ProString v = var_out.at(i);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(v.startsWith("GENERATED_")) {
|
|
|
|
defaults = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(defaults) {
|
|
|
|
var_out << "SOURCES";
|
|
|
|
var_out << "HEADERS";
|
|
|
|
var_out << "FORMS";
|
|
|
|
}
|
2012-09-06 10:21:38 +00:00
|
|
|
const ProStringList &tmp = project->values(ProKey(*it + ".input"));
|
|
|
|
for (ProStringList::ConstIterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
|
|
|
|
ProStringList &inputs = project->values((*it2).toKey());
|
|
|
|
for (ProStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
|
2014-11-20 15:20:16 +00:00
|
|
|
QString path = replaceExtraCompilerVariables(tmp_out, (*input).toQString(), QString(), NoShell);
|
2011-04-27 10:05:43 +00:00
|
|
|
path = fixPathToQmake(path).section('/', -1);
|
|
|
|
for(int i = 0; i < var_out.size(); ++i) {
|
2012-09-06 10:21:38 +00:00
|
|
|
ProString v = var_out.at(i);
|
|
|
|
ProStringList &list = project->values(v.toKey());
|
2011-04-27 10:05:43 +00:00
|
|
|
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)
|
|
|
|
{
|
2019-04-30 10:51:36 +00:00
|
|
|
t << "######################################################################" << Qt::endl;
|
|
|
|
t << "# Automatically generated by qmake (" QMAKE_VERSION_STR ") " << QDateTime::currentDateTime().toString() << Qt::endl;
|
|
|
|
t << "######################################################################" << Qt::endl << Qt::endl;
|
2017-02-03 17:12:52 +00:00
|
|
|
if (!Option::globals->extra_cmds[QMakeEvalBefore].isEmpty())
|
2019-04-30 10:51:36 +00:00
|
|
|
t << Option::globals->extra_cmds[QMakeEvalBefore] << Qt::endl;
|
2011-04-27 10:05:43 +00:00
|
|
|
t << getWritableVar("TEMPLATE_ASSIGN", false);
|
|
|
|
if(project->first("TEMPLATE_ASSIGN") == "subdirs") {
|
2019-04-30 10:51:36 +00:00
|
|
|
t << Qt::endl << "# Directories" << "\n"
|
2011-04-27 10:05:43 +00:00
|
|
|
<< getWritableVar("SUBDIRS");
|
|
|
|
} else {
|
2012-02-24 08:10:52 +00:00
|
|
|
//figure out target
|
|
|
|
QString ofn = QFileInfo(static_cast<QFile *>(t.device())->fileName()).completeBaseName();
|
|
|
|
if (ofn.isEmpty() || ofn == "-")
|
|
|
|
ofn = "unknown";
|
2012-09-06 10:21:38 +00:00
|
|
|
project->values("TARGET_ASSIGN") = ProStringList(ofn);
|
2012-02-24 08:10:52 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
t << getWritableVar("TARGET_ASSIGN")
|
|
|
|
<< getWritableVar("CONFIG", false)
|
|
|
|
<< getWritableVar("CONFIG_REMOVE", false)
|
2019-04-30 10:51:36 +00:00
|
|
|
<< getWritableVar("INCLUDEPATH") << Qt::endl;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2019-01-29 11:09:22 +00:00
|
|
|
t << "# You can make your code fail to compile if you use deprecated APIs.\n"
|
2016-10-24 19:04:37 +00:00
|
|
|
"# In order to do so, uncomment the following line.\n"
|
2019-01-29 11:09:22 +00:00
|
|
|
"# Please consult the documentation of the deprecated API in order to know\n"
|
|
|
|
"# how to port your code away from it.\n"
|
2016-10-24 19:04:37 +00:00
|
|
|
"# You can also select to disable deprecated APIs only up to a certain version of Qt.\n"
|
|
|
|
"#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0\n\n";
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
t << "# Input" << "\n";
|
|
|
|
t << getWritableVar("HEADERS")
|
|
|
|
<< getWritableVar("FORMS")
|
|
|
|
<< getWritableVar("LEXSOURCES")
|
|
|
|
<< getWritableVar("YACCSOURCES")
|
|
|
|
<< getWritableVar("SOURCES")
|
|
|
|
<< getWritableVar("RESOURCES")
|
|
|
|
<< getWritableVar("TRANSLATIONS");
|
|
|
|
}
|
2017-02-03 17:12:52 +00:00
|
|
|
if (!Option::globals->extra_cmds[QMakeEvalAfter].isEmpty())
|
2019-04-30 10:51:36 +00:00
|
|
|
t << Option::globals->extra_cmds[QMakeEvalAfter] << Qt::endl;
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProjectGenerator::addConfig(const QString &cfg, bool add)
|
|
|
|
{
|
2012-09-06 10:21:38 +00:00
|
|
|
ProKey where = "CONFIG";
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!add)
|
|
|
|
where = "CONFIG_REMOVE";
|
2012-04-23 16:08:16 +00:00
|
|
|
if (!project->values(where).contains(cfg)) {
|
|
|
|
project->values(where) += cfg;
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProjectGenerator::addFile(QString file)
|
|
|
|
{
|
2015-04-13 19:18:36 +00:00
|
|
|
file = fileFixify(file, FileFixifyToIndir);
|
2011-04-27 10:05:43 +00:00
|
|
|
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;
|
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
ProKey where;
|
2011-04-27 10:05:43 +00:00
|
|
|
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()) {
|
|
|
|
for(int cit = 0; cit < Option::c_ext.size(); ++cit) {
|
|
|
|
if(file.endsWith(Option::c_ext[cit])) {
|
|
|
|
where = "SOURCES";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(where.isEmpty()) {
|
|
|
|
if(file.endsWith(Option::ui_ext))
|
|
|
|
where = "FORMS";
|
|
|
|
else if(file.endsWith(Option::lex_ext))
|
|
|
|
where = "LEXSOURCES";
|
|
|
|
else if(file.endsWith(Option::yacc_ext))
|
|
|
|
where = "YACCSOURCES";
|
|
|
|
else if(file.endsWith(".ts") || file.endsWith(".xlf"))
|
|
|
|
where = "TRANSLATIONS";
|
|
|
|
else if(file.endsWith(".qrc"))
|
|
|
|
where = "RESOURCES";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString newfile = fixPathToQmake(fileFixify(file));
|
|
|
|
|
2012-09-06 10:21:38 +00:00
|
|
|
ProStringList &endList = project->values(where);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(!endList.contains(newfile, Qt::CaseInsensitive)) {
|
|
|
|
endList += newfile;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
2012-09-06 10:21:38 +00:00
|
|
|
ProjectGenerator::getWritableVar(const char *vk, bool)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-09-06 10:21:38 +00:00
|
|
|
const ProKey v(vk);
|
|
|
|
ProStringList &vals = project->values(v);
|
2011-04-27 10:05:43 +00:00
|
|
|
if(vals.isEmpty())
|
|
|
|
return "";
|
|
|
|
|
|
|
|
// If values contain spaces, ensure that they are quoted
|
2012-09-06 10:21:38 +00:00
|
|
|
for (ProStringList::iterator it = vals.begin(); it != vals.end(); ++it) {
|
2011-04-27 10:05:43 +00:00
|
|
|
if ((*it).contains(' ') && !(*it).startsWith(' '))
|
2012-09-06 10:21:38 +00:00
|
|
|
*it = "\"" + *it + "\"";
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 + " += ";
|
2012-05-18 18:00:23 +00:00
|
|
|
QString join = vals.join(' ');
|
2011-04-27 10:05:43 +00:00
|
|
|
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
|
|
|
|
{
|
2018-07-17 13:11:07 +00:00
|
|
|
ProString fileName = file.fileName();
|
|
|
|
if (!fileName.endsWith(Option::pro_ext)) {
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
fileName = fileInfo(Option::output_dir).fileName();
|
|
|
|
file.setFileName(fileName + Option::pro_ext);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
return MakefileGenerator::openOutput(file, build);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
ProjectGenerator::fixPathToQmake(const QString &file)
|
|
|
|
{
|
|
|
|
QString ret = file;
|
|
|
|
if(Option::dir_sep != QLatin1String("/"))
|
2014-11-27 14:02:50 +00:00
|
|
|
ret.replace(Option::dir_sep, QLatin1String("/"));
|
2011-04-27 10:05:43 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|