📄 msvc_dsp.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 "msvc_dsp.h"#include "option.h"#include <qdir.h>#include <qset.h>#include <stdlib.h>DspMakefileGenerator::DspMakefileGenerator() : Win32MakefileGenerator(), init_flag(false){}bool DspMakefileGenerator::writeMakefile(QTextStream &t){ if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) { /* for now just dump, I need to generated an empty dsp or something.. */ fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n", var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData()); return true; } // Generate workspace file if(project->first("TEMPLATE") == "vcsubdirs") { if (!project->isActiveConfig("build_pass")) { debug_msg(1, "Generator: MSVC: Writing workspave file"); writeSubDirs(t); } else { debug_msg(1, "Generator: MSVC: Not writing workspace file for build_pass configs"); } return true; } else if (project->first("TEMPLATE") == "vcapp" || project->first("TEMPLATE") == "vclib") { if(!project->isActiveConfig("build_pass")) return writeDspParts(t); return true; } return project->isActiveConfig("build_pass");}bool DspMakefileGenerator::hasBuiltinCompiler(const QString &filename) const{ for (int i = 0; i < Option::cpp_ext.count(); ++i) if (filename.endsWith(Option::cpp_ext.at(i))) return true; for (int i = 0; i < Option::c_ext.count(); ++i) if (filename.endsWith(Option::c_ext.at(i))) return true; return false;}QString DspMakefileGenerator::replaceExtraCompilerVariables(const QString &var, const QStringList &in, const QStringList &out){ QString ret = MakefileGenerator::replaceExtraCompilerVariables(var, in, out); ret.replace("$(DEFINES)", varGlue("PRL_EXPORT_DEFINES"," -D"," -D","") + varGlue("DEFINES"," -D"," -D","")); QString incpath = this->var("MSVCDSP_INCPATH"); incpath.replace("/I", "-I"); ret.replace("$(INCPATH)", incpath); return ret;}// if config is part of a multibuild thenthe gule (this) has the correct MSVCDSP_PROJECTQString DspMakefileGenerator::configName(DspMakefileGenerator * config){ return var("MSVCDSP_PROJECT") + config->var("MSVCDSP_CONFIG_NAME");}bool DspMakefileGenerator::writeDspHeader(QTextStream &t){ DspMakefileGenerator * config = this; if (mergedProjects.count()) config = mergedProjects.at(0); t << "# Microsoft Developer Studio Project File - Name=\"" << var("MSVCDSP_PROJECT") << "\" - Package Owner=<4>" << endl; t << "# Microsoft Developer Studio Generated Build File, Format Version 6.00" << endl; t << "# ** DO NOT EDIT **" << endl; t << endl; t << "# TARGTYPE \"Win32 (x86) " << var("MSVCDSP_TARGETTYPE") << "\" " << var("MSVCDSP_DSPTYPE") << endl; t << endl; t << "CFG=\"" << configName(config) << "\"" << endl; t << "!MESSAGE This is not a valid makefile. To build this project using NMAKE," << endl; t << "!MESSAGE use the Export Makefile command and run" << endl; t << "!MESSAGE " << endl; t << "!MESSAGE NMAKE /f " << escapeFilePath(var("TARGET")) << ".mak." << endl; t << "!MESSAGE " << endl; t << "!MESSAGE You can specify a configuration when running NMAKE" << endl; t << "!MESSAGE by defining the macro CFG on the command line. For example:" << endl; t << "!MESSAGE " << endl; t << "!MESSAGE NMAKE /f " << escapeFilePath(var("TARGET")) << ".mak CFG=\"" << configName(config) << "\"" << endl; t << "!MESSAGE " << endl; t << "!MESSAGE Possible choices for configuration are:" << endl; t << "!MESSAGE " << endl; if (mergedProjects.count()) { for (int i = 0; i < mergedProjects.count(); ++i) { DspMakefileGenerator * config = mergedProjects.at(i); t << "!MESSAGE \"" << configName(config) << "\" (based on \"Win32 (x86) " << config->var("MSVCDSP_TARGETTYPE") << "\")" << endl; } } else { t << "!MESSAGE \"" << configName(config) << "\" (based on \"Win32 (x86) " << config->var("MSVCDSP_TARGETTYPE") << "\")" << endl; } t << "!MESSAGE " << endl; t << endl; t << "# Begin Project" << endl; t << "# PROP AllowPerConfigDependencies 0" << endl; t << "# PROP Scc_ProjName \"\"" << endl; t << "# PROP Scc_LocalPath \"\"" << endl; t << "CPP=" << config->var("QMAKE_CC") << endl; t << "MTL=" << config->var("QMAKE_IDL") << endl; t << "RSC=" << config->var("QMAKE_RC") << endl; t << "BSC32=bscmake.exe" << endl; return true;}bool DspMakefileGenerator::writeDspParts(QTextStream &t){ //bool staticLibTarget = var("MSVCDSP_DSPTYPE") == "0x0104"; writeDspHeader(t); writeDspConfig(t, this); t << endl; t << "# Begin Target" << endl; t << endl; t << "# Name \"" << configName(this) << "\"" << endl; t << endl; QStringList listNames = QString("SOURCES|DEF_FILE").split("|"); QStringList allListNames = listNames; writeFileGroup(t, listNames, "Source Files", "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"); listNames = QStringList("HEADERS"); allListNames += listNames; writeFileGroup(t, QStringList("HEADERS"), "Header Files", "h;hpp;hxx;hm;inl"); listNames = QString("FORMS|INTERFACES|FORMS3").split("|"); allListNames += listNames; writeFileGroup(t, listNames, "Form Files", "ui"); listNames = QStringList("IMAGES"); allListNames += listNames; writeFileGroup(t, QStringList("IMAGES"), "Image Files", ""); listNames = QString("RC_FILE|RESOURCES").split("|"); allListNames += listNames; writeFileGroup(t, listNames, "Resources", "rc;qrc"); listNames = QStringList("TRANSLATIONS"); allListNames += listNames; writeFileGroup(t, listNames, "Translations", "ts"); listNames = QStringList("LEXSOURCES"); allListNames += listNames; writeFileGroup(t, listNames, "Lexables", "l"); listNames = QStringList("YACCSOURCES"); allListNames += listNames; writeFileGroup(t, listNames, "Yaccables", "y"); listNames = QStringList("TYPELIBS"); allListNames += listNames; writeFileGroup(t, listNames, "Type Libraries", "tlb;olb"); if (!project->isEmpty("QMAKE_EXTRA_COMPILERS")) { const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS"); for (QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) { const QStringList &inputs = project->values((*it)+".input"); for (QStringList::ConstIterator input = inputs.begin(); input != inputs.end(); ++input) { if (!allListNames.contains((*input)) && *input != "UIC3_HEADERS") writeFileGroup(t, QStringList((*input)), (*input) + " Files", ""); } } } project->values("SWAPPED_BUILD_STEPS") = swappedBuildSteps.keys(); writeFileGroup(t, QString("GENERATED_SOURCES|GENERATED_FILES|SWAPPED_BUILD_STEPS").split("|"), "Generated", ""); t << "# End Target" << endl; t << "# End Project" << endl; return true;}voidDspMakefileGenerator::init(){ if(init_flag) return; QStringList::Iterator it; init_flag = true; platform = "Win32"; if(!project->values("QMAKE_PLATFORM").isEmpty()) platform = varGlue("QMAKE_PLATFORM", "", " ", ""); // this should probably not be here, but I'm using it to wrap the .t files if(project->first("TEMPLATE") == "vcapp") project->values("QMAKE_APP_FLAG").append("1"); else if(project->first("TEMPLATE") == "vclib") project->values("QMAKE_LIB_FLAG").append("1"); if(project->values("QMAKESPEC").isEmpty()) project->values("QMAKESPEC").append(qgetenv("QMAKESPEC")); project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS")); processVars(); if(!project->values("VERSION").isEmpty()) { QString version = project->values("VERSION").first(); int firstDot = version.indexOf("."); QString major = version.left(firstDot); QString minor = version.right(version.length() - firstDot - 1); minor.replace(".", ""); project->values("MSVCDSP_LFLAGS").append("/VERSION:" + major + "." + minor); } QString msvcdsp_project; if(!project->isEmpty("TARGET")) { project->values("TARGET") = unescapeFilePaths(project->values("TARGET")); msvcdsp_project = project->first("TARGET"); } MakefileGenerator::init(); if(msvcdsp_project.isEmpty()) msvcdsp_project = Option::output.fileName(); msvcdsp_project = msvcdsp_project.right(msvcdsp_project.length() - msvcdsp_project.lastIndexOf("\\") - 1); int dotFind = msvcdsp_project.lastIndexOf("."); if(dotFind != -1) msvcdsp_project = msvcdsp_project.left(dotFind); msvcdsp_project.replace("-", ""); project->values("MSVCDSP_PROJECT").append(msvcdsp_project); QStringList &proj = project->values("MSVCDSP_PROJECT"); for(QStringList::Iterator it = proj.begin(); it != proj.end(); ++it) (*it).replace(QRegExp("\\.[a-zA-Z0-9_]*$"), ""); if(!project->values("QMAKE_APP_FLAG").isEmpty()) { if(project->isActiveConfig("console")) { project->values("MSVCDSP_TARGETTYPE").append("Console Application"); project->values("MSVCDSP_DSPTYPE").append("0x0103"); project->values("MSVCDSP_DEFINES").append(" /D \"_CONSOLE\" "); } else { project->values("MSVCDSP_TARGETTYPE").append("Application"); project->values("MSVCDSP_DSPTYPE").append("0x0101"); project->values("MSVCDSP_DEFINES").append(" /D \"_WINDOWS\" "); } } else { if(project->isActiveConfig("dll")) { project->values("MSVCDSP_TARGETTYPE").append("Dynamic-Link Library"); project->values("MSVCDSP_DSPTYPE").append("0x0102"); project->values("MSVCDSP_DEFINES").append(" /D \"_USRDLL\" "); } else { project->values("MSVCDSP_TARGETTYPE").append("Static Library"); project->values("MSVCDSP_DSPTYPE").append("0x0104"); project->values("MSVCDSP_DEFINES").append(" /D \"_LIB\" "); } } project->values("MSVCDSP_LFLAGS") += project->values("QMAKE_LFLAGS"); if(!project->values("QMAKE_LIBDIR").isEmpty()) project->values("MSVCDSP_LFLAGS").append(valGlue( escapeFilePaths(project->values("QMAKE_LIBDIR")), "/LIBPATH:"," /LIBPATH:","")); project->values("MSVCDSP_DEFINES").append(varGlue("DEFINES","/D ","" " /D ",""));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -