📄 msvc_dsp.cpp
字号:
/****************************************************************************** $Id: qt/msvc_dsp.cpp 3.3.4 edited Aug 17 11:23 $**** Implementation of DspMakefileGenerator class.**** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.**** This file is part of qmake.**** This file may be distributed under the terms of the Q Public License** as defined by Trolltech AS of Norway and appearing in the file** LICENSE.QPL included in the packaging of this file.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid Qt Enterprise Edition licenses may use this** file in accordance with the Qt Commercial License Agreement provided** with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for** information about Qt Commercial License Agreements.** See http://www.trolltech.com/qpl/ for QPL licensing information.** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "msvc_dsp.h"#include "option.h"#include <qdir.h>#include <qregexp.h>#include <stdlib.h>#include <time.h>DspMakefileGenerator::DspMakefileGenerator(QMakeProject *p) : Win32MakefileGenerator(p), init_flag(FALSE){}boolDspMakefileGenerator::writeMakefile(QTextStream &t){ if(!project->variables()["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").latin1()); return TRUE; } if(project->first("TEMPLATE") == "vcapp" || project->first("TEMPLATE") == "vclib") { return writeDspParts(t); } else if(project->first("TEMPLATE") == "subdirs") { writeHeader(t); writeSubDirs(t); return TRUE; } return FALSE;}boolDspMakefileGenerator::writeDspParts(QTextStream &t){ QString dspfile; if ( !project->variables()["DSP_TEMPLATE"].isEmpty() ) { dspfile = project->first("DSP_TEMPLATE"); } else { dspfile = project->first("MSVCDSP_TEMPLATE"); } if (dspfile.startsWith("\"") && dspfile.endsWith("\"")) dspfile = dspfile.mid(1, dspfile.length() - 2); QString dspfile_loc = findTemplate(dspfile); QFile file(dspfile_loc); if(!file.open(IO_ReadOnly)) { fprintf(stderr, "Cannot open dsp file: %s\n", dspfile.latin1()); return FALSE; } QTextStream dsp(&file); QString platform = "Win32"; if ( !project->variables()["QMAKE_PLATFORM"].isEmpty() ) platform = varGlue("QMAKE_PLATFORM", "", " ", ""); // Setup PCH variables precompH = project->first("PRECOMPILED_HEADER"); QString namePCH = QFileInfo(precompH).fileName(); usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header"); if (usePCH) { // Created files QString origTarget = project->first("QMAKE_ORIG_TARGET"); origTarget.replace(QRegExp("-"), "_"); precompObj = "\"$(IntDir)\\" + origTarget + Option::obj_ext + "\""; precompPch = "\"$(IntDir)\\" + origTarget + ".pch\""; // Add PRECOMPILED_HEADER to HEADERS if (!project->variables()["HEADERS"].contains(precompH)) project->variables()["HEADERS"] += precompH; // Add precompile compiler options project->variables()["PRECOMPILED_FLAGS_REL"] = "/Yu\"" + namePCH + "\" /FI\"" + namePCH + "\" "; project->variables()["PRECOMPILED_FLAGS_DEB"] = "/Yu\"" + namePCH + "\" /FI\"" + namePCH + "\" "; // Return to variable pool project->variables()["PRECOMPILED_OBJECT"] = precompObj; project->variables()["PRECOMPILED_PCH"] = precompPch; } int rep; QString line; while ( !dsp.eof() ) { line = dsp.readLine(); while((rep = line.find(QRegExp("\\$\\$[a-zA-Z0-9_-]*"))) != -1) { QString torep = line.mid(rep, line.find(QRegExp("[^\\$a-zA-Z0-9_-]"), rep) - rep); QString variable = torep.right(torep.length()-2); t << line.left(rep); //output the left side line = line.right(line.length() - (rep + torep.length())); //now past the variable if(variable == "MSVCDSP_SOURCES") { if(project->variables()["SOURCES"].isEmpty()) continue; QString mocpath = var( "QMAKE_MOC" ); mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " "; QStringList list = project->variables()["SOURCES"] + project->variables()["DEF_FILE"]; if(!project->isActiveConfig("flat")) list.sort(); QStringList::Iterator it; for( it = list.begin(); it != list.end(); ++it) { beginGroupForFile((*it), t); t << "# Begin Source File\n\nSOURCE=" << (*it) << endl; if (usePCH && (*it).endsWith(".c")) t << "# SUBTRACT CPP /FI\"" << namePCH << "\" /Yu\"" << namePCH << "\" /Fp" << endl; if ( project->isActiveConfig("moc") && (*it).endsWith(Option::cpp_moc_ext)) { QString base = (*it); base.replace(QRegExp("\\..*$"), "").upper(); base.replace(QRegExp("[^a-zA-Z]"), "_"); QString build = "\n\n# Begin Custom Build - Moc'ing " + findMocSource((*it)) + "...\n" "InputPath=.\\" + (*it) + "\n\n" "\"" + (*it) + "\"" " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n" "\t" + mocpath + findMocSource((*it)) + " -o " + (*it) + "\n\n" "# End Custom Build\n\n"; t << "USERDEP_" << base << "=\".\\" << findMocSource((*it)) << "\" \"$(QTDIR)\\bin\\moc.exe\"" << endl << endl; t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build << "!ENDIF " << endl << endl; } t << "# End Source File" << endl; } endGroups(t); } else if(variable == "MSVCDSP_IMAGES") { if(project->variables()["IMAGES"].isEmpty()) continue; t << "# Begin Source File\n\nSOURCE=" << project->first("QMAKE_IMAGE_COLLECTION") << endl; t << "# End Source File" << endl; } else if(variable == "MSVCDSP_HEADERS") { if(project->variables()["HEADERS"].isEmpty()) continue; QStringList list = project->variables()["HEADERS"]; if(!project->isActiveConfig("flat")) list.sort(); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {// beginGroupForFile((*it), t); t << "# Begin Source File\n\nSOURCE=" << (*it) << endl << endl; QString compilePCH; QStringList customDependencies; QString createMOC; QString buildCmdsR, buildCmdsD; QString buildCmds = "\nBuildCmds= \\\n"; // Create unique baseID QString base = (*it); { base.replace(QRegExp("\\..*$"), "").upper(); base.replace(QRegExp("[^a-zA-Z]"), "_"); } if (usePCH && precompH.endsWith(*it)) { QString basicBuildCmd = QString("\tcl.exe /TP /W3 /FD /c /D \"WIN32\" /Yc /Fp\"%1\" /Fo\"%2\" %3 %4 %5 %6 %7 %8 %9 /D \"") .arg(precompPch) .arg(precompObj) .arg(var("MSVCDSP_INCPATH")) .arg(var("MSVCDSP_DEFINES")) .arg(var("MSVCDSP_CXXFLAGS")); buildCmdsR = basicBuildCmd .arg("/D \"NDEBUG\"") .arg(var("QMAKE_CXXFLAGS_RELEASE")) .arg(var("MSVCDSP_MTDEF")) .arg(var("MSVCDSP_RELDEFS")); buildCmdsD = basicBuildCmd .arg("/D \"_DEBUG\" /Od") .arg(var("QMAKE_CXXFLAGS_DEBUG")) .arg(var("MSVCDSP_MTDEFD")) .arg(var("MSVCDSP_DEBUG_OPT")); if (project->first("TEMPLATE") == "vcapp") { // App buildCmdsR += var("MSVCDSP_WINCONDEF"); buildCmdsD += var("MSVCDSP_WINCONDEF"); } else if (project->isActiveConfig("dll")) { // Dll buildCmdsR += "_WINDOWS\" /D \"_USRDLL"; buildCmdsD += "_WINDOWS\" /D \"_USRDLL"; } else { // Lib buildCmdsR += "_LIB"; buildCmdsD += "_LIB"; } buildCmdsR += "\" /Fd\"$(IntDir)\\\\\" " + (*it) + " \\\n"; buildCmdsD += "\" /Fd\"$(IntDir)\\\\\" " + (*it) + " \\\n"; compilePCH = precompPch + " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n $(BuildCmds)\n\n"; QStringList &tmp = findDependencies(precompH); if(!tmp.isEmpty()) // Got Deps for PCH customDependencies += tmp; } if (project->isActiveConfig("moc") && !findMocDestination((*it)).isEmpty()) { QString mocpath = var( "QMAKE_MOC" ); mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " "; buildCmds += "\t" + mocpath + (*it) + " -o " + findMocDestination((*it)) + " \\\n"; createMOC = "\"" + findMocDestination((*it)) + "\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n $(BuildCmds)\n\n"; customDependencies += "\"$(QTDIR)\\bin\\moc.exe\""; } if (!createMOC.isEmpty() || !compilePCH.isEmpty()) { bool doMOC = !createMOC.isEmpty(); bool doPCH = !compilePCH.isEmpty(); QString build = "\n\n# Begin Custom Build - "+ QString(doMOC?"Moc'ing ":"") + QString((doMOC&&doPCH)?" and ":"") + QString(doPCH?"Creating PCH cpp from ":"") + (*it) + "...\nInputPath=.\\" + (*it) + "\n\n" + buildCmds + "%1\n" + createMOC + compilePCH + "# End Custom Build\n\n"; t << "USERDEP_" << base << "=" << valGlue(customDependencies, "\"", "\" \"", "\"") << endl << endl; t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build.arg(buildCmdsR) << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build.arg(buildCmdsD) << "!ENDIF " << endl << endl; } t << "# End Source File" << endl; }// endGroups(t); } else if(variable == "MSVCDSP_FORMSOURCES" || variable == "MSVCDSP_FORMHEADERS") { if(project->variables()["FORMS"].isEmpty()) continue; QString uiSourcesDir; QString uiHeadersDir; if(!project->variables()["UI_DIR"].isEmpty()) { uiSourcesDir = project->first("UI_DIR"); uiHeadersDir = project->first("UI_DIR"); } else { if ( !project->variables()["UI_SOURCES_DIR"].isEmpty() ) uiSourcesDir = project->first("UI_SOURCES_DIR"); else uiSourcesDir = ""; if ( !project->variables()["UI_HEADERS_DIR"].isEmpty() ) uiHeadersDir = project->first("UI_HEADERS_DIR"); else uiHeadersDir = ""; } QStringList list = project->variables()["FORMS"]; if(!project->isActiveConfig("flat")) list.sort(); QString ext = variable == "MSVCDSP_FORMSOURCES" ? ".cpp" : ".h"; for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) { QString base = (*it); int dot = base.findRev("."); base.replace( dot, base.length() - dot, ext ); QString fname = base; int lbs = fname.findRev( "\\" ); QString fpath; if ( lbs != -1 ) fpath = fname.left( lbs + 1 ); fname = fname.right( fname.length() - lbs - 1 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -