📄 winmakefile.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the qmake application of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "winmakefile.h"#include "option.h"#include "project.h"#include "meta.h"#include <qtextstream.h>#include <qstring.h>#include <qhash.h>#include <qregexp.h>#include <qstringlist.h>#include <qdir.h>#include <stdlib.h>Win32MakefileGenerator::Win32MakefileGenerator() : MakefileGenerator(){}intWin32MakefileGenerator::findHighestVersion(const QString &d, const QString &stem, const QString &ext){ QString bd = Option::fixPathToLocalOS(d, true); if(!exists(bd)) return -1; QString dllStem = stem + QTDLL_POSTFIX; QMakeMetaInfo libinfo; bool libInfoRead = libinfo.readLib(bd + Option::dir_sep + dllStem); // If the library, for which we're trying to find the highest version // number, is a static library if (libInfoRead && libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib")) return -1; if(!project->values("QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE").isEmpty()) return project->values("QMAKE_" + stem.toUpper() + "_VERSION_OVERRIDE").first().toInt(); int biggest=-1; if(!project->isActiveConfig("no_versionlink")) { QDir dir(bd); QStringList entries = dir.entryList(); QRegExp regx(QString("((lib)?%1([0-9]*)).(%2|prl)$").arg(dllStem).arg(ext), Qt::CaseInsensitive); for(QStringList::Iterator it = entries.begin(); it != entries.end(); ++it) { if(regx.exactMatch((*it))) { if (!regx.cap(3).isEmpty()) { bool ok = true; int num = regx.cap(3).toInt(&ok); biggest = qMax(biggest, (!ok ? -1 : num)); } } } } if(libInfoRead && !libinfo.values("QMAKE_PRL_CONFIG").contains("staticlib") && !libinfo.isEmpty("QMAKE_PRL_VERSION")) biggest = qMax(biggest, libinfo.first("QMAKE_PRL_VERSION").replace(".", "").toInt()); return biggest;}boolWin32MakefileGenerator::findLibraries(const QString &where){ QStringList &l = project->values(where); QList<QMakeLocalFileName> dirs; { QStringList &libpaths = project->values("QMAKE_LIBDIR"); for(QStringList::Iterator libpathit = libpaths.begin(); libpathit != libpaths.end(); ++libpathit) dirs.append(QMakeLocalFileName((*libpathit))); } for(QStringList::Iterator it = l.begin(); it != l.end();) { QChar quote; bool modified_opt = false, remove = false; QString opt = (*it).trimmed(); if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0]) { quote = opt[0]; opt = opt.mid(1, opt.length()-2); } if(opt.startsWith("/LIBPATH:")) { dirs.append(QMakeLocalFileName(opt.mid(9))); } else if(opt.startsWith("-L") || opt.startsWith("/L")) { QString libpath = opt.mid(2); QMakeLocalFileName l(libpath); if(!dirs.contains(l)) { dirs.append(l); modified_opt = true; if (!quote.isNull()) { libpath = quote + libpath + quote; quote = QChar(); } (*it) = "/LIBPATH:" + libpath; } } else if(opt.startsWith("-l") || opt.startsWith("/l")) { QString lib = opt.right(opt.length() - 2), out; if(!lib.isEmpty()) { QString suffix; if(!project->isEmpty("QMAKE_" + lib.toUpper() + "_SUFFIX")) suffix = project->first("QMAKE_" + lib.toUpper() + "_SUFFIX"); for(QList<QMakeLocalFileName>::Iterator it = dirs.begin(); it != dirs.end(); ++it) { QString extension; int ver = findHighestVersion((*it).local(), lib); if(ver > 0) extension += QString::number(ver); extension += suffix; extension += ".lib"; if(QMakeMetaInfo::libExists((*it).local() + Option::dir_sep + lib) || exists((*it).local() + Option::dir_sep + lib + extension)) { out = (*it).real() + Option::dir_sep + lib + extension; break; } } } if(out.isEmpty()) out = lib + ".lib"; modified_opt = true; (*it) = out; } else if(!exists(Option::fixPathToLocalOS(opt))) { QList<QMakeLocalFileName> lib_dirs; QString file = opt; int slsh = file.lastIndexOf(Option::dir_sep); if(slsh != -1) { lib_dirs.append(QMakeLocalFileName(file.left(slsh+1))); file = file.right(file.length() - slsh - 1); } else { lib_dirs = dirs; } if(file.endsWith(".lib")) { file = file.left(file.length() - 4); if(!file.at(file.length()-1).isNumber()) { QString suffix; if(!project->isEmpty("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX")) suffix = project->first("QMAKE_" + file.section(Option::dir_sep, -1).toUpper() + "_SUFFIX"); for(QList<QMakeLocalFileName>::Iterator dep_it = lib_dirs.begin(); dep_it != lib_dirs.end(); ++dep_it) { QString lib_tmpl(file + "%1" + suffix + ".lib"); int ver = findHighestVersion((*dep_it).local(), file); if(ver != -1) { if(ver) lib_tmpl = lib_tmpl.arg(ver); else lib_tmpl = lib_tmpl.arg(""); if(slsh != -1) { QString dir = (*dep_it).real(); if(!dir.endsWith(Option::dir_sep)) dir += Option::dir_sep; lib_tmpl.prepend(dir); } modified_opt = true; (*it) = lib_tmpl; break; } } } } } if(remove) { it = l.erase(it); } else { if(!quote.isNull() && modified_opt) (*it) = quote + (*it) + quote; ++it; } } return true;}voidWin32MakefileGenerator::processPrlFiles(){ QHash<QString, bool> processed; QList<QMakeLocalFileName> libdirs; { QStringList &libpaths = project->values("QMAKE_LIBDIR"); for(QStringList::Iterator libpathit = libpaths.begin(); libpathit != libpaths.end(); ++libpathit) libdirs.append(QMakeLocalFileName((*libpathit))); } for(bool ret = false; true; ret = false) { //read in any prl files included.. QStringList l_out; QString where = "QMAKE_LIBS"; if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS")) where = project->first("QMAKE_INTERNAL_PRL_LIBS"); QStringList l = project->values(where); for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) { QString opt = (*it).trimmed(); if((opt[0] == '\'' || opt[0] == '"') && opt[(int)opt.length()-1] == opt[0]) opt = opt.mid(1, opt.length()-2); if(opt.startsWith("/")) { if(opt.startsWith("/LIBPATH:")) { QMakeLocalFileName l(opt.mid(9)); if(!libdirs.contains(l)) libdirs.append(l); } } else if(!processed.contains(opt)) { if(processPrlFile(opt)) { processed.insert(opt, true); ret = true; } else if(QDir::isRelativePath(opt) || opt.startsWith("-l")) { QString tmp; if (opt.startsWith("-l")) tmp = opt.mid(2); else tmp = opt; for(QList<QMakeLocalFileName>::Iterator it = libdirs.begin(); it != libdirs.end(); ++it) { QString prl = (*it).local() + Option::dir_sep + tmp; // the original is used as the key QString orgprl = prl; if(processed.contains(prl)) { break; } else if(processPrlFile(prl)) { processed.insert(orgprl, true); ret = true; break; } } } } if(!opt.isEmpty()) l_out.append(opt); } if(ret) l = l_out; else break; }}void Win32MakefileGenerator::processVars(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -