qmake/generators/win32/msvc_vcproj.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the qmake application of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "msvc_vcproj.h"
       
    43 #include "option.h"
       
    44 #include "xmloutput.h"
       
    45 #include <qdir.h>
       
    46 #include <qdiriterator.h>
       
    47 #include <qcryptographichash.h>
       
    48 #include <qregexp.h>
       
    49 #include <qhash.h>
       
    50 #include <quuid.h>
       
    51 #include <stdlib.h>
       
    52 
       
    53 //#define DEBUG_SOLUTION_GEN
       
    54 //#define DEBUG_PROJECT_GEN
       
    55 
       
    56 QT_BEGIN_NAMESPACE
       
    57 // Filter GUIDs (Do NOT change these!) ------------------------------
       
    58 const char _GUIDSourceFiles[]          = "{4FC737F1-C7A5-4376-A066-2A32D752A2FF}";
       
    59 const char _GUIDHeaderFiles[]          = "{93995380-89BD-4b04-88EB-625FBE52EBFB}";
       
    60 const char _GUIDGeneratedFiles[]       = "{71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}";
       
    61 const char _GUIDResourceFiles[]        = "{D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}";
       
    62 const char _GUIDLexYaccFiles[]         = "{E12AE0D2-192F-4d59-BD23-7D3FA58D3183}";
       
    63 const char _GUIDTranslationFiles[]     = "{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}";
       
    64 const char _GUIDFormFiles[]            = "{99349809-55BA-4b9d-BF79-8FDBB0286EB3}";
       
    65 const char _GUIDExtraCompilerFiles[]   = "{E0D8C965-CC5F-43d7-AD63-FAEF0BBC0F85}";
       
    66 QT_END_NAMESPACE
       
    67 
       
    68 #ifdef Q_OS_WIN32
       
    69 #include <qt_windows.h>
       
    70 
       
    71 QT_BEGIN_NAMESPACE
       
    72 
       
    73 struct {
       
    74     DotNET version;
       
    75     const char *versionStr;
       
    76     const char *regKey;
       
    77 } dotNetCombo[] = {
       
    78 #ifdef Q_OS_WIN64
       
    79     {NET2008, "MSVC.NET 2008 (9.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir"},
       
    80     {NET2008, "MSVC.NET 2008 Express Edition (9.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir"},
       
    81     {NET2005, "MSVC.NET 2005 (8.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"},
       
    82     {NET2005, "MSVC.NET 2005 Express Edition (8.0)", "Software\\Wow6432Node\\Microsoft\\VCExpress\\8.0\\Setup\\VC\\ProductDir"},
       
    83     {NET2003, "MSVC.NET 2003 (7.1)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir"},
       
    84     {NET2002, "MSVC.NET 2002 (7.0)", "Software\\Wow6432Node\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir"},
       
    85 #else
       
    86     {NET2008, "MSVC.NET 2008 (9.0)", "Software\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir"},
       
    87     {NET2008, "MSVC.NET 2008 Express Edition (9.0)", "Software\\Microsoft\\VCExpress\\9.0\\Setup\\VC\\ProductDir"},
       
    88     {NET2005, "MSVC.NET 2005 (8.0)", "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir"},
       
    89     {NET2005, "MSVC.NET 2005 Express Edition (8.0)", "Software\\Microsoft\\VCExpress\\8.0\\Setup\\VC\\ProductDir"},
       
    90     {NET2003, "MSVC.NET 2003 (7.1)", "Software\\Microsoft\\VisualStudio\\7.1\\Setup\\VC\\ProductDir"},
       
    91     {NET2002, "MSVC.NET 2002 (7.0)", "Software\\Microsoft\\VisualStudio\\7.0\\Setup\\VC\\ProductDir"},
       
    92 #endif
       
    93     {NETUnknown, "", ""},
       
    94 };
       
    95 
       
    96 static QString keyPath(const QString &rKey)
       
    97 {
       
    98     int idx = rKey.lastIndexOf(QLatin1Char('\\'));
       
    99     if (idx == -1)
       
   100         return QString();
       
   101     return rKey.left(idx + 1);
       
   102 }
       
   103 
       
   104 static QString keyName(const QString &rKey)
       
   105 {
       
   106     int idx = rKey.lastIndexOf(QLatin1Char('\\'));
       
   107     if (idx == -1)
       
   108         return rKey;
       
   109 
       
   110     QString res(rKey.mid(idx + 1));
       
   111     if (res == "Default" || res == ".")
       
   112         res = "";
       
   113     return res;
       
   114 }
       
   115 
       
   116 static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey)
       
   117 {
       
   118 
       
   119     QString rSubkeyName = keyName(rSubkey);
       
   120     QString rSubkeyPath = keyPath(rSubkey);
       
   121 
       
   122     HKEY handle = 0;
       
   123     LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle);
       
   124 
       
   125     if (res != ERROR_SUCCESS)
       
   126         return QString();
       
   127 
       
   128     // get the size and type of the value
       
   129     DWORD dataType;
       
   130     DWORD dataSize;
       
   131     res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize);
       
   132     if (res != ERROR_SUCCESS) {
       
   133         RegCloseKey(handle);
       
   134         return QString();
       
   135     }
       
   136 
       
   137     // get the value
       
   138     QByteArray data(dataSize, 0);
       
   139     res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0,
       
   140                           reinterpret_cast<unsigned char*>(data.data()), &dataSize);
       
   141     if (res != ERROR_SUCCESS) {
       
   142         RegCloseKey(handle);
       
   143         return QString();
       
   144     }
       
   145 
       
   146     QString result;
       
   147     switch (dataType) {
       
   148         case REG_EXPAND_SZ:
       
   149         case REG_SZ: {
       
   150             result = QString::fromWCharArray(((const wchar_t *)data.constData()));
       
   151             break;
       
   152         }
       
   153 
       
   154         case REG_MULTI_SZ: {
       
   155             QStringList l;
       
   156             int i = 0;
       
   157             for (;;) {
       
   158                 QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i);
       
   159                 i += s.length() + 1;
       
   160 
       
   161                 if (s.isEmpty())
       
   162                     break;
       
   163                 l.append(s);
       
   164             }
       
   165             result = l.join(", ");
       
   166             break;
       
   167         }
       
   168 
       
   169         case REG_NONE:
       
   170         case REG_BINARY: {
       
   171             result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2);
       
   172             break;
       
   173         }
       
   174 
       
   175         case REG_DWORD_BIG_ENDIAN:
       
   176         case REG_DWORD: {
       
   177             Q_ASSERT(data.size() == sizeof(int));
       
   178             int i;
       
   179             memcpy((char*)&i, data.constData(), sizeof(int));
       
   180             result = QString::number(i);
       
   181             break;
       
   182         }
       
   183 
       
   184         default:
       
   185             qWarning("QSettings: unknown data %d type in windows registry", dataType);
       
   186             break;
       
   187     }
       
   188 
       
   189     RegCloseKey(handle);
       
   190     return result;
       
   191 }
       
   192 QT_END_NAMESPACE
       
   193 #endif
       
   194 
       
   195 QT_BEGIN_NAMESPACE
       
   196 DotNET which_dotnet_version()
       
   197 {
       
   198 #ifndef Q_OS_WIN32
       
   199     return NET2002; // Always generate 7.0 versions on other platforms
       
   200 #else
       
   201     // Only search for the version once
       
   202     static DotNET current_version = NETUnknown;
       
   203     if(current_version != NETUnknown)
       
   204         return current_version;
       
   205 
       
   206     // Fallback to .NET 2002
       
   207     current_version = NET2002;
       
   208 
       
   209     QStringList warnPath;
       
   210     int installed = 0;
       
   211     int i = 0;
       
   212     for(; dotNetCombo[i].version; ++i) {
       
   213         QString path = readRegistryKey(HKEY_LOCAL_MACHINE, dotNetCombo[i].regKey);
       
   214         if(!path.isEmpty()) {
       
   215             ++installed;
       
   216             current_version = dotNetCombo[i].version;
       
   217                         warnPath += QString("%1").arg(dotNetCombo[i].versionStr);
       
   218         }
       
   219     }
       
   220 
       
   221     if (installed < 2)
       
   222         return current_version;
       
   223 
       
   224     // More than one version installed, search directory path
       
   225     QString paths = qgetenv("PATH");
       
   226     QStringList pathlist = paths.toLower().split(";");
       
   227 
       
   228     i = installed = 0;
       
   229     for(; dotNetCombo[i].version; ++i) {
       
   230         QString productPath = readRegistryKey(HKEY_LOCAL_MACHINE, dotNetCombo[i].regKey).toLower();
       
   231                 if (productPath.isEmpty())
       
   232                         continue;
       
   233         QStringList::iterator it;
       
   234         for(it = pathlist.begin(); it != pathlist.end(); ++it) {
       
   235             if((*it).contains(productPath)) {
       
   236                 ++installed;
       
   237                 current_version = dotNetCombo[i].version;
       
   238                 warnPath += QString("%1 in path").arg(dotNetCombo[i].versionStr);
       
   239                                 break;
       
   240             }
       
   241         }
       
   242     }
       
   243         switch(installed) {
       
   244         case 1:
       
   245                 break;
       
   246         case 0:
       
   247                 warn_msg(WarnLogic, "Generator: MSVC.NET: Found more than one version of Visual Studio, but"
       
   248                                  " none in your path! Fallback to lowest version (%s)", warnPath.join(", ").toLatin1().data());
       
   249                 break;
       
   250         default:
       
   251                 warn_msg(WarnLogic, "Generator: MSVC.NET: Found more than one version of Visual Studio in"
       
   252                                  " your path! Fallback to lowest version (%s)", warnPath.join(", ").toLatin1().data());
       
   253                 break;
       
   254         }
       
   255 
       
   256     return current_version;
       
   257 #endif
       
   258 };
       
   259 
       
   260 // Flatfile Tags ----------------------------------------------------
       
   261 const char _slnHeader70[]       = "Microsoft Visual Studio Solution File, Format Version 7.00";
       
   262 const char _slnHeader71[]       = "Microsoft Visual Studio Solution File, Format Version 8.00";
       
   263 const char _slnHeader80[]       = "Microsoft Visual Studio Solution File, Format Version 9.00";
       
   264 const char _slnHeader90[]       = "Microsoft Visual Studio Solution File, Format Version 10.00";
       
   265                                   // The following UUID _may_ change for later servicepacks...
       
   266                                   // If so we need to search through the registry at
       
   267                                   // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\Projects
       
   268                                   // to find the subkey that contains a "PossibleProjectExtension"
       
   269                                   // containing "vcproj"...
       
   270                                   // Use the hardcoded value for now so projects generated on other
       
   271                                   // platforms are actually usable.
       
   272 const char _slnMSVCvcprojGUID[] = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
       
   273 const char _slnProjectBeg[]     = "\nProject(\"";
       
   274 const char _slnProjectMid[]     = "\") = ";
       
   275 const char _slnProjectEnd[]     = "\nEndProject";
       
   276 const char _slnGlobalBeg[]      = "\nGlobal";
       
   277 const char _slnGlobalEnd[]      = "\nEndGlobal";
       
   278 const char _slnSolutionConf[]   = "\n\tGlobalSection(SolutionConfiguration) = preSolution"
       
   279                                   "\n\t\tConfigName.0 = Debug|Win32"
       
   280                                   "\n\t\tConfigName.1 = Release|Win32"
       
   281                                   "\n\tEndGlobalSection";
       
   282 const char _slnProjDepBeg[]     = "\n\tGlobalSection(ProjectDependencies) = postSolution";
       
   283 const char _slnProjDepEnd[]     = "\n\tEndGlobalSection";
       
   284 const char _slnProjConfBeg[]    = "\n\tGlobalSection(ProjectConfiguration) = postSolution";
       
   285 const char _slnProjRelConfTag1[]= ".Release|%1.ActiveCfg = Release|";
       
   286 const char _slnProjRelConfTag2[]= ".Release|%1.Build.0 = Release|";
       
   287 const char _slnProjDbgConfTag1[]= ".Debug|%1.ActiveCfg = Debug|";
       
   288 const char _slnProjDbgConfTag2[]= ".Debug|%1.Build.0 = Debug|";
       
   289 const char _slnProjConfEnd[]    = "\n\tEndGlobalSection";
       
   290 const char _slnExtSections[]    = "\n\tGlobalSection(ExtensibilityGlobals) = postSolution"
       
   291                                   "\n\tEndGlobalSection"
       
   292                                   "\n\tGlobalSection(ExtensibilityAddIns) = postSolution"
       
   293                                   "\n\tEndGlobalSection";
       
   294 // ------------------------------------------------------------------
       
   295 
       
   296 VcprojGenerator::VcprojGenerator() : Win32MakefileGenerator(), init_flag(false)
       
   297 {
       
   298 }
       
   299 bool VcprojGenerator::writeMakefile(QTextStream &t)
       
   300 {
       
   301     initProject(); // Fills the whole project with proper data
       
   302 
       
   303     // Generate solution file
       
   304     if(project->first("TEMPLATE") == "vcsubdirs") {
       
   305         if (!project->isActiveConfig("build_pass")) {
       
   306             debug_msg(1, "Generator: MSVC.NET: Writing solution file");
       
   307             writeSubDirs(t);
       
   308         } else {
       
   309             debug_msg(1, "Generator: MSVC.NET: Not writing solution file for build_pass configs");
       
   310         }
       
   311         return true;
       
   312     } else
       
   313     // Generate single configuration project file
       
   314     if (project->first("TEMPLATE") == "vcapp" ||
       
   315         project->first("TEMPLATE") == "vclib") {
       
   316         if(!project->isActiveConfig("build_pass")) {
       
   317             debug_msg(1, "Generator: MSVC.NET: Writing single configuration project file");
       
   318             XmlOutput xmlOut(t);
       
   319             xmlOut << vcProject;
       
   320         }
       
   321         return true;
       
   322     }
       
   323     return project->isActiveConfig("build_pass");
       
   324 }
       
   325 
       
   326 bool VcprojGenerator::writeProjectMakefile()
       
   327 {
       
   328     usePlatformDir();
       
   329     QTextStream t(&Option::output);
       
   330 
       
   331     // Check if all requirements are fulfilled
       
   332     if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
       
   333         fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
       
   334                 var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData());
       
   335         return true;
       
   336     }
       
   337 
       
   338     // Generate project file
       
   339     if(project->first("TEMPLATE") == "vcapp" ||
       
   340        project->first("TEMPLATE") == "vclib") {
       
   341         if (!mergedProjects.count()) {
       
   342             warn_msg(WarnLogic, "Generator: MSVC.NET: no single configuration created, cannot output project!");
       
   343             return false;
       
   344         }
       
   345 
       
   346         debug_msg(1, "Generator: MSVC.NET: Writing project file");
       
   347         VCProject mergedProject;
       
   348         for (int i = 0; i < mergedProjects.count(); ++i) {
       
   349             VCProjectSingleConfig *singleProject = &(mergedProjects.at(i)->vcProject);
       
   350             mergedProject.SingleProjects += *singleProject;
       
   351             for (int j = 0; j < singleProject->ExtraCompilersFiles.count(); ++j) {
       
   352                 const QString &compilerName = singleProject->ExtraCompilersFiles.at(j).Name;
       
   353                 if (!mergedProject.ExtraCompilers.contains(compilerName))
       
   354                     mergedProject.ExtraCompilers += compilerName;
       
   355             }
       
   356         }
       
   357 
       
   358         if(mergedProjects.count() > 1 &&
       
   359            mergedProjects.at(0)->vcProject.Name ==
       
   360            mergedProjects.at(1)->vcProject.Name)
       
   361             mergedProjects.at(0)->writePrlFile();
       
   362         mergedProject.Name = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
       
   363         mergedProject.Version = mergedProjects.at(0)->vcProject.Version;
       
   364         mergedProject.ProjectGUID = project->isEmpty("QMAKE_UUID") ? getProjectUUID().toString().toUpper() : project->first("QMAKE_UUID");
       
   365         mergedProject.Keyword = project->first("VCPROJ_KEYWORD");
       
   366         mergedProject.SccProjectName = mergedProjects.at(0)->vcProject.SccProjectName;
       
   367         mergedProject.SccLocalPath = mergedProjects.at(0)->vcProject.SccLocalPath;
       
   368         mergedProject.PlatformName = mergedProjects.at(0)->vcProject.PlatformName;
       
   369 
       
   370         XmlOutput xmlOut(t);
       
   371         xmlOut << mergedProject;
       
   372         return true;
       
   373     } else if(project->first("TEMPLATE") == "vcsubdirs") {
       
   374         return writeMakefile(t);
       
   375     }
       
   376     return false;
       
   377 }
       
   378 
       
   379 struct VcsolutionDepend {
       
   380     QString uuid;
       
   381     QString vcprojFile, orig_target, target;
       
   382     Target targetType;
       
   383     QStringList dependencies;
       
   384 };
       
   385 
       
   386 QUuid VcprojGenerator::getProjectUUID(const QString &filename)
       
   387 {
       
   388     bool validUUID = true;
       
   389 
       
   390     // Read GUID from variable-space
       
   391     QUuid uuid = project->first("GUID");
       
   392 
       
   393     // If none, create one based on the MD5 of absolute project path
       
   394     if(uuid.isNull() || !filename.isEmpty()) {
       
   395         QString abspath = Option::fixPathToLocalOS(filename.isEmpty()?project->first("QMAKE_MAKEFILE"):filename);
       
   396         QByteArray digest = QCryptographicHash::hash(abspath.toUtf8(), QCryptographicHash::Md5);
       
   397         memcpy((unsigned char*)(&uuid), digest.constData(), sizeof(QUuid));
       
   398         validUUID = !uuid.isNull();
       
   399         uuid.data4[0] = (uuid.data4[0] & 0x3F) | 0x80; // UV_DCE variant
       
   400         uuid.data3 = (uuid.data3 & 0x0FFF) | (QUuid::Name<<12);
       
   401     }
       
   402 
       
   403     // If still not valid, generate new one, and suggest adding to .pro
       
   404     if(uuid.isNull() || !validUUID) {
       
   405         uuid = QUuid::createUuid();
       
   406         fprintf(stderr,
       
   407                 "qmake couldn't create a GUID based on filepath, and we couldn't\nfind a valid GUID in the .pro file (Consider adding\n'GUID = %s'  to the .pro file)\n",
       
   408                 uuid.toString().toUpper().toLatin1().constData());
       
   409     }
       
   410 
       
   411     // Store GUID in variable-space
       
   412     project->values("GUID") = QStringList(uuid.toString().toUpper());
       
   413     return uuid;
       
   414 }
       
   415 
       
   416 QUuid VcprojGenerator::increaseUUID(const QUuid &id)
       
   417 {
       
   418     QUuid result(id);
       
   419     qint64 dataFirst = (result.data4[0] << 24) +
       
   420                        (result.data4[1] << 16) +
       
   421                        (result.data4[2] << 8) +
       
   422                         result.data4[3];
       
   423     qint64 dataLast =  (result.data4[4] << 24) +
       
   424                        (result.data4[5] << 16) +
       
   425                        (result.data4[6] <<  8) +
       
   426                         result.data4[7];
       
   427 
       
   428     if(!(dataLast++))
       
   429         dataFirst++;
       
   430 
       
   431     result.data4[0] = uchar((dataFirst >> 24) & 0xff);
       
   432     result.data4[1] = uchar((dataFirst >> 16) & 0xff);
       
   433     result.data4[2] = uchar((dataFirst >>  8) & 0xff);
       
   434     result.data4[3] = uchar(dataFirst         & 0xff);
       
   435     result.data4[4] = uchar((dataLast  >> 24) & 0xff);
       
   436     result.data4[5] = uchar((dataLast  >> 16) & 0xff);
       
   437     result.data4[6] = uchar((dataLast  >>  8) & 0xff);
       
   438     result.data4[7] = uchar(dataLast          & 0xff);
       
   439     return result;
       
   440 }
       
   441 
       
   442 void VcprojGenerator::writeSubDirs(QTextStream &t)
       
   443 {
       
   444     // Check if all requirements are fulfilled
       
   445     if(!project->values("QMAKE_FAILED_REQUIREMENTS").isEmpty()) {
       
   446         fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
       
   447                 var("QMAKE_FAILED_REQUIREMENTS").toLatin1().constData());
       
   448         return;
       
   449     }
       
   450 
       
   451     switch(which_dotnet_version()) {
       
   452     case NET2008:
       
   453         t << _slnHeader90;
       
   454         break;
       
   455     case NET2005:
       
   456         t << _slnHeader80;
       
   457         break;
       
   458     case NET2003:
       
   459         t << _slnHeader71;
       
   460         break;
       
   461     case NET2002:
       
   462         t << _slnHeader70;
       
   463         break;
       
   464     default:
       
   465         t << _slnHeader70;
       
   466         warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .sln", which_dotnet_version());
       
   467         break;
       
   468     }
       
   469 
       
   470     QHash<QString, VcsolutionDepend*> solution_depends;
       
   471     QList<VcsolutionDepend*> solution_cleanup;
       
   472 
       
   473     QStringList subdirs = project->values("SUBDIRS");
       
   474     QString oldpwd = qmake_getpwd();
       
   475 
       
   476     // Make sure that all temp projects are configured
       
   477     // for release so that the depends are created
       
   478     // without the debug <lib>dxxx.lib name mangling
       
   479     QStringList old_after_vars = Option::after_user_vars;
       
   480     Option::after_user_vars.append("CONFIG+=release");
       
   481 
       
   482     for(int i = 0; i < subdirs.size(); ++i) {
       
   483         QString tmp = subdirs.at(i);
       
   484         if(!project->isEmpty(tmp + ".file")) {
       
   485             if(!project->isEmpty(tmp + ".subdir"))
       
   486                 warn_msg(WarnLogic, "Cannot assign both file and subdir for subdir %s",
       
   487                          tmp.toLatin1().constData());
       
   488             tmp = project->first(tmp + ".file");
       
   489         } else if(!project->isEmpty(tmp + ".subdir")) {
       
   490             tmp = project->first(tmp + ".subdir");
       
   491         }
       
   492         QFileInfo fi(fileInfo(Option::fixPathToLocalOS(tmp, true)));
       
   493         if(fi.exists()) {
       
   494             if(fi.isDir()) {
       
   495                 QString profile = tmp;
       
   496                 if(!profile.endsWith(Option::dir_sep))
       
   497                     profile += Option::dir_sep;
       
   498                 profile += fi.baseName() + Option::pro_ext;
       
   499                 subdirs.append(profile);
       
   500             } else {
       
   501                 QMakeProject tmp_proj;
       
   502                 QString dir = fi.path(), fn = fi.fileName();
       
   503                 if(!dir.isEmpty()) {
       
   504                     if(!qmake_setpwd(dir))
       
   505                         fprintf(stderr, "Cannot find directory: %s\n", dir.toLatin1().constData());
       
   506                 }
       
   507                 if(tmp_proj.read(fn)) {
       
   508                     // Check if all requirements are fulfilled
       
   509                     if(!tmp_proj.variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
       
   510                         fprintf(stderr, "Project file(%s) not added to Solution because all requirements not met:\n\t%s\n",
       
   511                                 fn.toLatin1().constData(), tmp_proj.values("QMAKE_FAILED_REQUIREMENTS").join(" ").toLatin1().constData());
       
   512                         continue;
       
   513                     }
       
   514                     if(tmp_proj.first("TEMPLATE") == "vcsubdirs") {
       
   515                         QStringList tmp_proj_subdirs = tmp_proj.variables()["SUBDIRS"];
       
   516                         for(int x = 0; x < tmp_proj_subdirs.size(); ++x) {
       
   517                             QString tmpdir = tmp_proj_subdirs.at(x);
       
   518                             if(!tmp_proj.isEmpty(tmpdir + ".file")) {
       
   519                                 if(!tmp_proj.isEmpty(tmpdir + ".subdir"))
       
   520                                     warn_msg(WarnLogic, "Cannot assign both file and subdir for subdir %s",
       
   521                                             tmpdir.toLatin1().constData());
       
   522                                 tmpdir = tmp_proj.first(tmpdir + ".file");
       
   523                             } else if(!tmp_proj.isEmpty(tmpdir + ".subdir")) {
       
   524                                 tmpdir = tmp_proj.first(tmpdir + ".subdir");
       
   525                             }
       
   526                             subdirs += fileFixify(tmpdir);
       
   527                         }
       
   528                     } else if(tmp_proj.first("TEMPLATE") == "vcapp" || tmp_proj.first("TEMPLATE") == "vclib") {
       
   529                         // Initialize a 'fake' project to get the correct variables
       
   530                         // and to be able to extract all the dependencies
       
   531                         Option::QMAKE_MODE old_mode = Option::qmake_mode;
       
   532                         Option::qmake_mode = Option::QMAKE_GENERATE_NOTHING;
       
   533                         VcprojGenerator tmp_vcproj;
       
   534                         tmp_vcproj.setNoIO(true);
       
   535                         tmp_vcproj.setProjectFile(&tmp_proj);
       
   536                         Option::qmake_mode = old_mode;
       
   537                         if(Option::debug_level) {
       
   538                             QMap<QString, QStringList> &vars = tmp_proj.variables();
       
   539                             for(QMap<QString, QStringList>::Iterator it = vars.begin();
       
   540                                 it != vars.end(); ++it) {
       
   541                                 if(it.key().left(1) != "." && !it.value().isEmpty())
       
   542                                     debug_msg(1, "%s: %s === %s", fn.toLatin1().constData(), it.key().toLatin1().constData(),
       
   543                                                 it.value().join(" :: ").toLatin1().constData());
       
   544                             }
       
   545                         }
       
   546 
       
   547                         // We assume project filename is [QMAKE_ORIG_TARGET].vcproj
       
   548                         QString vcproj = unescapeFilePath(tmp_vcproj.project->first("QMAKE_ORIG_TARGET") + project->first("VCPROJ_EXTENSION"));
       
   549                         QString vcprojDir = qmake_getpwd();
       
   550 
       
   551                         // If file doesn't exsist, then maybe the users configuration
       
   552                         // doesn't allow it to be created. Skip to next...
       
   553                         if(!exists(vcprojDir + Option::dir_sep + vcproj)) {
       
   554 
       
   555                             // Try to find the directory which fits relative
       
   556                             // to the output path, which represents the shadow
       
   557                             // path in case we are shadow building
       
   558                             QStringList list = fi.path().split(QLatin1Char('/'));
       
   559                             QString tmpDir = QFileInfo(Option::output).path() + Option::dir_sep;
       
   560                             bool found = false;
       
   561                             for (int i = list.size() - 1; i >= 0; --i) {
       
   562                                 QString curr;
       
   563                                 for (int j = i; j < list.size(); ++j)
       
   564                                     curr += list.at(j) + Option::dir_sep;
       
   565                                 if (exists(tmpDir + curr + vcproj)) {
       
   566                                     vcprojDir = QDir::cleanPath(tmpDir + curr);
       
   567                                     found = true;
       
   568                                     break;
       
   569                                 }
       
   570                             }
       
   571                             if (!found) {
       
   572                                 warn_msg(WarnLogic, "Ignored (not found) '%s'", QString(vcprojDir + Option::dir_sep + vcproj).toLatin1().constData());
       
   573                                 goto nextfile; // # Dirty!
       
   574                             }
       
   575                         }
       
   576 
       
   577                         VcsolutionDepend *newDep = new VcsolutionDepend;
       
   578                         newDep->vcprojFile = vcprojDir + Option::dir_sep + vcproj;
       
   579                         newDep->orig_target = unescapeFilePath(tmp_proj.first("QMAKE_ORIG_TARGET"));
       
   580                         newDep->target = tmp_proj.first("MSVCPROJ_TARGET").section(Option::dir_sep, -1);
       
   581                         newDep->targetType = tmp_vcproj.projectTarget;
       
   582                         newDep->uuid = tmp_proj.isEmpty("QMAKE_UUID") ? getProjectUUID(Option::fixPathToLocalOS(vcprojDir + QDir::separator() + vcproj)).toString().toUpper(): tmp_proj.first("QMAKE_UUID");
       
   583 
       
   584                         // We want to store it as the .lib name.
       
   585                         if(newDep->target.endsWith(".dll"))
       
   586                             newDep->target = newDep->target.left(newDep->target.length()-3) + "lib";
       
   587 
       
   588                         // All ActiveQt Server projects are dependent on idc.exe
       
   589                         if(tmp_proj.variables()["CONFIG"].contains("qaxserver"))
       
   590                             newDep->dependencies << "idc.exe";
       
   591 
       
   592                         // All extra compilers which has valid input are considered dependencies
       
   593                         const QStringList &quc = tmp_proj.variables()["QMAKE_EXTRA_COMPILERS"];
       
   594                         for(QStringList::ConstIterator it = quc.constBegin(); it != quc.constEnd(); ++it) {
       
   595                             const QStringList &invar = tmp_proj.variables().value((*it) + ".input");
       
   596                             for(QStringList::ConstIterator iit = invar.constBegin(); iit != invar.constEnd(); ++iit) {
       
   597                                 const QStringList fileList = tmp_proj.variables().value(*iit);
       
   598                                 if (!fileList.isEmpty()) {
       
   599                                     const QStringList &cmdsParts = tmp_proj.variables().value((*it) + ".commands");
       
   600                                     bool startOfLine = true;
       
   601                                     foreach(QString cmd, cmdsParts) {
       
   602                                         if (!startOfLine) {
       
   603                                             if (cmd.contains("\r"))
       
   604                                                 startOfLine = true;
       
   605                                             continue;
       
   606                                         }
       
   607                                         if (cmd.isEmpty())
       
   608                                             continue;
       
   609 
       
   610                                         startOfLine = false;
       
   611                                         // Extra compiler commands might be defined in variables, so
       
   612                                         // expand them (don't care about the in/out files)
       
   613                                         cmd = tmp_vcproj.replaceExtraCompilerVariables(cmd, QStringList(), QStringList());
       
   614                                         // Pull out command based on spaces and quoting, if the
       
   615                                         // command starts with that
       
   616                                         cmd = cmd.left(cmd.indexOf(cmd.at(0) == '"' ? '"' : ' ', 1));
       
   617                                         QString dep = cmd.section('/', -1).section('\\', -1);
       
   618                                         if (!newDep->dependencies.contains(dep))
       
   619                                             newDep->dependencies << dep;
       
   620                                     }
       
   621                                 }
       
   622                             }
       
   623                         }
       
   624 
       
   625                         // Add all unknown libs to the deps
       
   626                         QStringList where = QStringList() << "QMAKE_LIBS" << "QMAKE_LIBS_PRIVATE";
       
   627                         if(!tmp_proj.isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
       
   628                             where = tmp_proj.variables()["QMAKE_INTERNAL_PRL_LIBS"];
       
   629                         for(QStringList::iterator wit = where.begin();
       
   630                             wit != where.end(); ++wit) {
       
   631                             QStringList &l = tmp_proj.variables()[(*wit)];
       
   632                             for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
       
   633                                 QString opt = (*it);
       
   634                                 if(!opt.startsWith("/") &&   // Not a switch
       
   635                                     opt != newDep->target && // Not self
       
   636                                     opt != "opengl32.lib" && // We don't care about these libs
       
   637                                     opt != "glu32.lib" &&    // to make depgen alittle faster
       
   638                                     opt != "kernel32.lib" &&
       
   639                                     opt != "user32.lib" &&
       
   640                                     opt != "gdi32.lib" &&
       
   641                                     opt != "comdlg32.lib" &&
       
   642                                     opt != "advapi32.lib" &&
       
   643                                     opt != "shell32.lib" &&
       
   644                                     opt != "ole32.lib" &&
       
   645                                     opt != "oleaut32.lib" &&
       
   646                                     opt != "uuid.lib" &&
       
   647                                     opt != "imm32.lib" &&
       
   648                                     opt != "winmm.lib" &&
       
   649                                     opt != "wsock32.lib" &&
       
   650                                     opt != "ws2_32.lib" &&
       
   651                                     opt != "winspool.lib" &&
       
   652                                     opt != "delayimp.lib")
       
   653                                 {
       
   654                                     newDep->dependencies << opt.section(Option::dir_sep, -1);
       
   655                                 }
       
   656                             }
       
   657                         }
       
   658 #ifdef DEBUG_SOLUTION_GEN
       
   659                         qDebug("Deps for %20s: [%s]", newDep->target.toLatin1().constData(), newDep->dependencies.join(" :: ").toLatin1().constData());
       
   660 #endif
       
   661                         solution_cleanup.append(newDep);
       
   662                         solution_depends.insert(newDep->target, newDep);
       
   663                         t << _slnProjectBeg << _slnMSVCvcprojGUID << _slnProjectMid
       
   664                             << "\"" << newDep->orig_target << "\", \"" << newDep->vcprojFile
       
   665                             << "\", \"" << newDep->uuid << "\"";
       
   666                         t << _slnProjectEnd;
       
   667                     }
       
   668                 }
       
   669 nextfile:
       
   670                 qmake_setpwd(oldpwd);
       
   671             }
       
   672         }
       
   673     }
       
   674     t << _slnGlobalBeg;
       
   675     if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH")) {
       
   676         QString slnConfCE = _slnSolutionConf;
       
   677         QString platform = QString("|") + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
       
   678         slnConfCE.replace(QString("|Win32"), platform);
       
   679         t << slnConfCE;
       
   680     } else {
       
   681         t << _slnSolutionConf;
       
   682     }
       
   683     t << _slnProjDepBeg;
       
   684 
       
   685     // Restore previous after_user_var options
       
   686     Option::after_user_vars = old_after_vars;
       
   687 
       
   688     // Figure out dependencies
       
   689     for(QList<VcsolutionDepend*>::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) {
       
   690         int cnt = 0;
       
   691         for(QStringList::iterator dit = (*it)->dependencies.begin();  dit != (*it)->dependencies.end(); ++dit) {
       
   692             if(VcsolutionDepend *vc = solution_depends[*dit])
       
   693                 t << "\n\t\t" << (*it)->uuid << "." << cnt++ << " = " << vc->uuid;
       
   694         }
       
   695     }
       
   696     t << _slnProjDepEnd;
       
   697     t << _slnProjConfBeg;
       
   698     for(QList<VcsolutionDepend*>::Iterator it = solution_cleanup.begin(); it != solution_cleanup.end(); ++it) {
       
   699         QString platform = "Win32";
       
   700         if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"))
       
   701             platform = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
       
   702         t << "\n\t\t" << (*it)->uuid << QString(_slnProjDbgConfTag1).arg(platform) << platform;
       
   703         t << "\n\t\t" << (*it)->uuid << QString(_slnProjDbgConfTag2).arg(platform) << platform;
       
   704         t << "\n\t\t" << (*it)->uuid << QString(_slnProjRelConfTag1).arg(platform) << platform;
       
   705         t << "\n\t\t" << (*it)->uuid << QString(_slnProjRelConfTag2).arg(platform) << platform;
       
   706     }
       
   707     t << _slnProjConfEnd;
       
   708     t << _slnExtSections;
       
   709     t << _slnGlobalEnd;
       
   710 
       
   711 
       
   712     while (!solution_cleanup.isEmpty())
       
   713         delete solution_cleanup.takeFirst();
       
   714 }
       
   715 
       
   716 // ------------------------------------------------------------------------------------------------
       
   717 // ------------------------------------------------------------------------------------------------
       
   718 
       
   719 bool VcprojGenerator::hasBuiltinCompiler(const QString &file)
       
   720 {
       
   721     // Source files
       
   722     for (int i = 0; i < Option::cpp_ext.count(); ++i)
       
   723         if (file.endsWith(Option::cpp_ext.at(i)))
       
   724             return true;
       
   725     for (int i = 0; i < Option::c_ext.count(); ++i)
       
   726         if (file.endsWith(Option::c_ext.at(i)))
       
   727             return true;
       
   728     if (file.endsWith(".rc")
       
   729         || file.endsWith(".idl"))
       
   730         return true;
       
   731     return false;
       
   732 }
       
   733 
       
   734 void VcprojGenerator::init()
       
   735 {
       
   736     if(init_flag)
       
   737         return;
       
   738     if(project->first("TEMPLATE") == "vcsubdirs") { //too much work for subdirs
       
   739         init_flag = true;
       
   740         return;
       
   741     }
       
   742 
       
   743     debug_msg(1, "Generator: MSVC.NET: Initializing variables");
       
   744 
       
   745     // this should probably not be here, but I'm using it to wrap the .t files
       
   746     if (project->first("TEMPLATE") == "vcapp")
       
   747         project->values("QMAKE_APP_FLAG").append("1");
       
   748     else if (project->first("TEMPLATE") == "vclib")
       
   749         project->values("QMAKE_LIB_FLAG").append("1");
       
   750     if (project->values("QMAKESPEC").isEmpty())
       
   751         project->values("QMAKESPEC").append(qgetenv("QMAKESPEC"));
       
   752 
       
   753     processVars();
       
   754     initOld();           // Currently calling old DSP code to set variables. CLEAN UP!
       
   755 
       
   756     // Figure out what we're trying to build
       
   757     if(project->first("TEMPLATE") == "vcapp") {
       
   758         projectTarget = Application;
       
   759     } else if(project->first("TEMPLATE") == "vclib") {
       
   760         if(project->isActiveConfig("staticlib")) {
       
   761             if (!project->values("RES_FILE").isEmpty())
       
   762                 project->values("MSVCPROJ_LIBS") += escapeFilePaths(project->values("RES_FILE"));
       
   763             projectTarget = StaticLib;
       
   764         } else
       
   765             projectTarget = SharedLib;
       
   766     }
       
   767 
       
   768     // Setup PCH variables
       
   769     precompH = project->first("PRECOMPILED_HEADER");
       
   770     precompCPP = project->first("PRECOMPILED_SOURCE");
       
   771     usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
       
   772     if (usePCH) {
       
   773         precompHFilename = fileInfo(precompH).fileName();
       
   774         // Created files
       
   775         QString origTarget = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
       
   776         precompObj = origTarget + Option::obj_ext;
       
   777         precompPch = origTarget + ".pch";
       
   778         // Add PRECOMPILED_HEADER to HEADERS
       
   779         if (!project->values("HEADERS").contains(precompH))
       
   780             project->values("HEADERS") += precompH;
       
   781         // Return to variable pool
       
   782         project->values("PRECOMPILED_OBJECT") = QStringList(precompObj);
       
   783         project->values("PRECOMPILED_PCH")    = QStringList(precompPch);
       
   784 
       
   785         autogenPrecompCPP = precompCPP.isEmpty() && project->isActiveConfig("autogen_precompile_source");
       
   786         if (autogenPrecompCPP) {
       
   787             precompCPP = precompH
       
   788                 + (Option::cpp_ext.count() ? Option::cpp_ext.at(0) : QLatin1String(".cpp"));
       
   789             project->values("GENERATED_SOURCES") += precompCPP;
       
   790         } else if (!precompCPP.isEmpty()) {
       
   791             project->values("SOURCES") += precompCPP;
       
   792         }
       
   793     }
       
   794 
       
   795     // Add all input files for a custom compiler into a map for uniqueness,
       
   796     // unless the compiler is configure as a combined stage, then use the first one
       
   797     const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
       
   798     for(QStringList::ConstIterator it = quc.constBegin(); it != quc.constEnd(); ++it) {
       
   799         const QStringList &invar = project->variables().value((*it) + ".input");
       
   800         const QString compiler_out = project->first((*it) + ".output");
       
   801         for(QStringList::ConstIterator iit = invar.constBegin(); iit != invar.constEnd(); ++iit) {
       
   802             QStringList fileList = project->variables().value(*iit);
       
   803             if (!fileList.isEmpty()) {
       
   804                 if (project->values((*it) + ".CONFIG").indexOf("combine") != -1)
       
   805                     fileList = QStringList(fileList.first());
       
   806                 for(QStringList::ConstIterator fit = fileList.constBegin(); fit != fileList.constEnd(); ++fit) {
       
   807                     QString file = (*fit);
       
   808                     if (verifyExtraCompiler((*it), file)) {
       
   809                         if (!hasBuiltinCompiler(file)) {
       
   810                             extraCompilerSources[file] += *it;
       
   811                         } else {
       
   812                             QString out = Option::fixPathToTargetOS(replaceExtraCompilerVariables(
       
   813                                             compiler_out, file, QString()), false);
       
   814                             extraCompilerSources[out] += *it;
       
   815                             extraCompilerOutputs[out] = QStringList(file); // Can only have one
       
   816                         }
       
   817                     }
       
   818                 }
       
   819             }
       
   820         }
       
   821     }
       
   822 
       
   823 #if 0 // Debugging
       
   824     Q_FOREACH(QString aKey, extraCompilerSources.keys()) {
       
   825         qDebug("Extracompilers for %s are (%s)", aKey.toLatin1().constData(), extraCompilerSources.value(aKey).join(", ").toLatin1().constData());
       
   826     }
       
   827     Q_FOREACH(QString aKey, extraCompilerOutputs.keys()) {
       
   828         qDebug("Object mapping for %s is (%s)", aKey.toLatin1().constData(), extraCompilerOutputs.value(aKey).join(", ").toLatin1().constData());
       
   829     }
       
   830     qDebug("");
       
   831 #endif
       
   832 }
       
   833 
       
   834 bool VcprojGenerator::mergeBuildProject(MakefileGenerator *other)
       
   835 {
       
   836     VcprojGenerator *otherVC = static_cast<VcprojGenerator*>(other);
       
   837     if (!otherVC) {
       
   838         warn_msg(WarnLogic, "VcprojGenerator: Cannot merge other types of projects! (ignored)");
       
   839         return false;
       
   840     }
       
   841     mergedProjects += otherVC;
       
   842     return true;
       
   843 }
       
   844 
       
   845 void VcprojGenerator::initProject()
       
   846 {
       
   847     // Initialize XML sub elements
       
   848     // - Do this first since project elements may need
       
   849     // - to know of certain configuration options
       
   850     initConfiguration();
       
   851     initRootFiles();
       
   852     initSourceFiles();
       
   853     initHeaderFiles();
       
   854     initGeneratedFiles();
       
   855     initLexYaccFiles();
       
   856     initTranslationFiles();
       
   857     initFormFiles();
       
   858     initResourceFiles();
       
   859     initExtraCompilerOutputs();
       
   860 
       
   861     // Own elements -----------------------------
       
   862     vcProject.Name = unescapeFilePath(project->first("QMAKE_ORIG_TARGET"));
       
   863     switch(which_dotnet_version()) {
       
   864     case NET2008:
       
   865         vcProject.Version = "9,00";
       
   866         break;
       
   867     case NET2005:
       
   868                 //### using ',' because of a bug in 2005 B2
       
   869                 //### VS uses '.' or ',' depending on the regional settings! Using ',' always works.
       
   870         vcProject.Version = "8,00";
       
   871         break;
       
   872     case NET2003:
       
   873         vcProject.Version = "7.10";
       
   874         break;
       
   875     case NET2002:
       
   876         vcProject.Version = "7.00";
       
   877         break;
       
   878     default:
       
   879         vcProject.Version = "7.00";
       
   880         warn_msg(WarnLogic, "Generator: MSVC.NET: Unknown version (%d) of MSVC detected for .vcproj", which_dotnet_version());
       
   881         break;
       
   882     }
       
   883 
       
   884     vcProject.Keyword = project->first("VCPROJ_KEYWORD");
       
   885     if (project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
       
   886         vcProject.PlatformName = (vcProject.Configuration.idl.TargetEnvironment == midlTargetWin64 ? "Win64" : "Win32");
       
   887     } else {
       
   888         vcProject.PlatformName = project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
       
   889     }
       
   890     // These are not used by Qt, but may be used by customers
       
   891     vcProject.SccProjectName = project->first("SCCPROJECTNAME");
       
   892     vcProject.SccLocalPath = project->first("SCCLOCALPATH");
       
   893     vcProject.flat_files = project->isActiveConfig("flat");
       
   894 }
       
   895 
       
   896 void VcprojGenerator::initConfiguration()
       
   897 {
       
   898     // Initialize XML sub elements
       
   899     // - Do this first since main configuration elements may need
       
   900     // - to know of certain compiler/linker options
       
   901     VCConfiguration &conf = vcProject.Configuration;
       
   902     conf.CompilerVersion = which_dotnet_version();
       
   903 
       
   904     initCompilerTool();
       
   905 
       
   906     // Only on configuration per build
       
   907     bool isDebug = project->isActiveConfig("debug");
       
   908 
       
   909     if(projectTarget == StaticLib)
       
   910         initLibrarianTool();
       
   911     else {
       
   912         conf.linker.GenerateDebugInformation = isDebug ? _True : _False;
       
   913         initLinkerTool();
       
   914     }
       
   915     initResourceTool();
       
   916     initIDLTool();
       
   917 
       
   918     // Own elements -----------------------------
       
   919     QString temp = project->first("BuildBrowserInformation");
       
   920     switch (projectTarget) {
       
   921     case SharedLib:
       
   922         conf.ConfigurationType = typeDynamicLibrary;
       
   923         break;
       
   924     case StaticLib:
       
   925         conf.ConfigurationType = typeStaticLibrary;
       
   926         break;
       
   927     case Application:
       
   928     default:
       
   929         conf.ConfigurationType = typeApplication;
       
   930         break;
       
   931     }
       
   932 
       
   933     conf.Name = project->values("BUILD_NAME").join(" ");
       
   934     if (conf.Name.isEmpty())
       
   935         conf.Name = isDebug ? "Debug" : "Release";
       
   936     if (project->isEmpty("CE_SDK") || project->isEmpty("CE_ARCH")) {
       
   937         conf.Name += (conf.idl.TargetEnvironment == midlTargetWin64 ? "|Win64" : "|Win32");
       
   938     } else {
       
   939         conf.Name += "|" + project->values("CE_SDK").join(" ") + " (" + project->first("CE_ARCH") + ")";
       
   940     }
       
   941     conf.ATLMinimizesCRunTimeLibraryUsage = (project->first("ATLMinimizesCRunTimeLibraryUsage").isEmpty() ? _False : _True);
       
   942     conf.BuildBrowserInformation = triState(temp.isEmpty() ? (short)unset : temp.toShort());
       
   943     temp = project->first("CharacterSet");
       
   944     conf.CharacterSet = charSet(temp.isEmpty() ? (short)charSetNotSet : temp.toShort());
       
   945     conf.DeleteExtensionsOnClean = project->first("DeleteExtensionsOnClean");
       
   946     conf.ImportLibrary = conf.linker.ImportLibrary;
       
   947     conf.IntermediateDirectory = project->first("OBJECTS_DIR");
       
   948     conf.OutputDirectory = ".";
       
   949     conf.PrimaryOutput = project->first("PrimaryOutput");
       
   950     conf.WholeProgramOptimization = conf.compiler.WholeProgramOptimization;
       
   951     temp = project->first("UseOfATL");
       
   952     if(!temp.isEmpty())
       
   953         conf.UseOfATL = useOfATL(temp.toShort());
       
   954     temp = project->first("UseOfMfc");
       
   955     if(!temp.isEmpty())
       
   956         conf.UseOfMfc = useOfMfc(temp.toShort());
       
   957 
       
   958     // Configuration does not need parameters from
       
   959     // these sub XML items;
       
   960     initCustomBuildTool();
       
   961     initPreBuildEventTools();
       
   962     initPostBuildEventTools();
       
   963     // Only deploy for CE projects
       
   964     if (!project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH"))
       
   965         initDeploymentTool();
       
   966     initPreLinkEventTools();
       
   967 
       
   968     // Set definite values in both configurations
       
   969     if (isDebug) {
       
   970         conf.compiler.PreprocessorDefinitions.removeAll("NDEBUG");
       
   971     } else {
       
   972         conf.compiler.PreprocessorDefinitions += "NDEBUG";
       
   973     }
       
   974 
       
   975 }
       
   976 
       
   977 void VcprojGenerator::initCompilerTool()
       
   978 {
       
   979     QString placement = project->first("OBJECTS_DIR");
       
   980     if(placement.isEmpty())
       
   981         placement = ".\\";
       
   982 
       
   983     VCConfiguration &conf = vcProject.Configuration;
       
   984     conf.compiler.AssemblerListingLocation = placement ;
       
   985     conf.compiler.ProgramDataBaseFileName = ".\\" ;
       
   986     conf.compiler.ObjectFile = placement ;
       
   987     // PCH
       
   988     if (usePCH) {
       
   989         conf.compiler.UsePrecompiledHeader     = pchUseUsingSpecific;
       
   990         conf.compiler.PrecompiledHeaderFile    = "$(IntDir)\\" + precompPch;
       
   991         conf.compiler.PrecompiledHeaderThrough = project->first("PRECOMPILED_HEADER");
       
   992         conf.compiler.ForcedIncludeFiles       = project->values("PRECOMPILED_HEADER");
       
   993         // Minimal build option triggers an Internal Compiler Error
       
   994         // when used in conjunction with /FI and /Yu, so remove it
       
   995         project->values("QMAKE_CFLAGS_DEBUG").removeAll("-Gm");
       
   996         project->values("QMAKE_CFLAGS_DEBUG").removeAll("/Gm");
       
   997         project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("-Gm");
       
   998         project->values("QMAKE_CXXFLAGS_DEBUG").removeAll("/Gm");
       
   999     }
       
  1000 
       
  1001     conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS"));
       
  1002     if(project->isActiveConfig("debug")){
       
  1003         // Debug version
       
  1004         conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS_DEBUG"));
       
  1005         if((projectTarget == Application) || (projectTarget == StaticLib))
       
  1006             conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS_MT_DBG"));
       
  1007         else
       
  1008             conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS_MT_DLLDBG"));
       
  1009     } else {
       
  1010         // Release version
       
  1011         conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS_RELEASE"));
       
  1012         conf.compiler.PreprocessorDefinitions += "QT_NO_DEBUG";
       
  1013         conf.compiler.PreprocessorDefinitions += "NDEBUG";
       
  1014         if((projectTarget == Application) || (projectTarget == StaticLib))
       
  1015             conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS_MT"));
       
  1016         else
       
  1017             conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS_MT_DLL"));
       
  1018     }
       
  1019 
       
  1020     // Common for both release and debug
       
  1021     if(project->isActiveConfig("warn_off"))
       
  1022         conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS_WARN_OFF"));
       
  1023     else if(project->isActiveConfig("warn_on"))
       
  1024         conf.compiler.parseOptions(project->values("QMAKE_CXXFLAGS_WARN_ON"));
       
  1025     if(project->isActiveConfig("windows"))
       
  1026         conf.compiler.PreprocessorDefinitions += project->values("MSVCPROJ_WINCONDEF");
       
  1027 
       
  1028     // Can this be set for ALL configs?
       
  1029     // If so, use qmake.conf!
       
  1030     if(projectTarget == SharedLib)
       
  1031         conf.compiler.PreprocessorDefinitions += "_WINDOWS";
       
  1032 
       
  1033     conf.compiler.PreprocessorDefinitions += project->values("DEFINES");
       
  1034     conf.compiler.PreprocessorDefinitions += project->values("PRL_EXPORT_DEFINES");
       
  1035     conf.compiler.parseOptions(project->values("MSVCPROJ_INCPATH"));
       
  1036 }
       
  1037 
       
  1038 void VcprojGenerator::initLibrarianTool()
       
  1039 {
       
  1040     VCConfiguration &conf = vcProject.Configuration;
       
  1041     conf.librarian.OutputFile = project->first("DESTDIR");
       
  1042     if(conf.librarian.OutputFile.isEmpty())
       
  1043         conf.librarian.OutputFile = ".\\";
       
  1044 
       
  1045     if(!conf.librarian.OutputFile.endsWith("\\"))
       
  1046         conf.librarian.OutputFile += '\\';
       
  1047 
       
  1048     conf.librarian.OutputFile += project->first("MSVCPROJ_TARGET");
       
  1049     conf.librarian.AdditionalOptions += project->values("QMAKE_LIBFLAGS");
       
  1050 }
       
  1051 
       
  1052 void VcprojGenerator::initLinkerTool()
       
  1053 {
       
  1054     findLibraries(); // Need to add the highest version of the libs
       
  1055     VCConfiguration &conf = vcProject.Configuration;
       
  1056     conf.linker.parseOptions(project->values("MSVCPROJ_LFLAGS"));
       
  1057 
       
  1058     foreach(QString libs, project->values("MSVCPROJ_LIBS")) {
       
  1059         if (libs.left(9).toUpper() == "/LIBPATH:") {
       
  1060             QStringList l = QStringList(libs);
       
  1061             conf.linker.parseOptions(l);
       
  1062         } else {
       
  1063             conf.linker.AdditionalDependencies += libs;
       
  1064         }
       
  1065     }
       
  1066 
       
  1067     switch (projectTarget) {
       
  1068     case Application:
       
  1069         conf.linker.OutputFile = project->first("DESTDIR");
       
  1070         break;
       
  1071     case SharedLib:
       
  1072         conf.linker.parseOptions(project->values("MSVCPROJ_LIBOPTIONS"));
       
  1073         conf.linker.OutputFile = project->first("DESTDIR");
       
  1074         break;
       
  1075     case StaticLib: //unhandled - added to remove warnings..
       
  1076         break;
       
  1077     }
       
  1078 
       
  1079     if(conf.linker.OutputFile.isEmpty())
       
  1080         conf.linker.OutputFile = ".\\";
       
  1081 
       
  1082     if(!conf.linker.OutputFile.endsWith("\\"))
       
  1083         conf.linker.OutputFile += '\\';
       
  1084 
       
  1085     conf.linker.OutputFile += project->first("MSVCPROJ_TARGET");
       
  1086 
       
  1087     if(project->isActiveConfig("debug")){
       
  1088         conf.linker.parseOptions(project->values("QMAKE_LFLAGS_DEBUG"));
       
  1089     } else {
       
  1090         conf.linker.parseOptions(project->values("QMAKE_LFLAGS_RELEASE"));
       
  1091     }
       
  1092 
       
  1093     if(project->isActiveConfig("dll")){
       
  1094         conf.linker.parseOptions(project->values("QMAKE_LFLAGS_QT_DLL"));
       
  1095     }
       
  1096 
       
  1097     if(project->isActiveConfig("console")){
       
  1098         conf.linker.parseOptions(project->values("QMAKE_LFLAGS_CONSOLE"));
       
  1099     } else {
       
  1100         conf.linker.parseOptions(project->values("QMAKE_LFLAGS_WINDOWS"));
       
  1101     }
       
  1102 
       
  1103 }
       
  1104 
       
  1105 void VcprojGenerator::initResourceTool()
       
  1106 {
       
  1107     VCConfiguration &conf = vcProject.Configuration;
       
  1108     conf.resource.PreprocessorDefinitions = conf.compiler.PreprocessorDefinitions;
       
  1109 
       
  1110     // We need to add _DEBUG for the debug version of the project, since the normal compiler defines
       
  1111     // do not contain it. (The compiler defines this symbol automatically, which is wy we don't need
       
  1112     // to add it for the compiler) However, the resource tool does not do this.
       
  1113     if(project->isActiveConfig("debug"))
       
  1114         conf.resource.PreprocessorDefinitions += "_DEBUG";
       
  1115     if(project->isActiveConfig("staticlib"))
       
  1116         conf.resource.ResourceOutputFileName = project->first("DESTDIR") + "/$(InputName).res";
       
  1117 }
       
  1118 
       
  1119 
       
  1120 void VcprojGenerator::initIDLTool()
       
  1121 {
       
  1122 }
       
  1123 
       
  1124 void VcprojGenerator::initCustomBuildTool()
       
  1125 {
       
  1126 }
       
  1127 
       
  1128 void VcprojGenerator::initPreBuildEventTools()
       
  1129 {
       
  1130 }
       
  1131 
       
  1132 QString VcprojGenerator::fixCommandLine(DotNET version, const QString &input) const
       
  1133 {
       
  1134     QString result = input;
       
  1135 
       
  1136     if (version >= NET2005)
       
  1137         result = result.replace(QLatin1Char('\n'), QLatin1String("&#x000D;&#x000A;"));
       
  1138 
       
  1139     return result;
       
  1140 }
       
  1141 
       
  1142 void VcprojGenerator::initPostBuildEventTools()
       
  1143 {
       
  1144     VCConfiguration &conf = vcProject.Configuration;
       
  1145     if(!project->values("QMAKE_POST_LINK").isEmpty()) {
       
  1146         QString cmdline = fixCommandLine(conf.CompilerVersion, var("QMAKE_POST_LINK"));
       
  1147         conf.postBuild.CommandLine = cmdline;
       
  1148         if (conf.CompilerVersion < NET2005)
       
  1149             cmdline = cmdline.replace("\n", "&&");
       
  1150         conf.postBuild.Description = cmdline;
       
  1151     }
       
  1152 
       
  1153     QString signature = !project->isEmpty("SIGNATURE_FILE") ? var("SIGNATURE_FILE") : var("DEFAULT_SIGNATURE");
       
  1154     bool useSignature = !signature.isEmpty() && !project->isActiveConfig("staticlib") &&
       
  1155                         !project->isEmpty("CE_SDK") && !project->isEmpty("CE_ARCH");
       
  1156     if(useSignature)
       
  1157         conf.postBuild.CommandLine.prepend(QLatin1String("signtool sign /F ") + signature + " \"$(TargetPath)\"\n" +
       
  1158             (!conf.postBuild.CommandLine.isEmpty() ? " && " : ""));
       
  1159 
       
  1160     if(!project->values("MSVCPROJ_COPY_DLL").isEmpty()) {
       
  1161         if(!conf.postBuild.CommandLine.isEmpty())
       
  1162             conf.postBuild.CommandLine += " && ";
       
  1163         conf.postBuild.Description += var("MSVCPROJ_COPY_DLL_DESC");
       
  1164         conf.postBuild.CommandLine += var("MSVCPROJ_COPY_DLL");
       
  1165     }
       
  1166 }
       
  1167 
       
  1168 void VcprojGenerator::initDeploymentTool()
       
  1169 {
       
  1170     VCConfiguration &conf = vcProject.Configuration;
       
  1171     QString targetPath = project->values("deploy.path").join(" ");
       
  1172     if (targetPath.isEmpty())
       
  1173         targetPath = QString("%CSIDL_PROGRAM_FILES%\\") + project->first("TARGET");
       
  1174     if (targetPath.endsWith("/") || targetPath.endsWith("\\"))
       
  1175         targetPath.chop(1);
       
  1176 
       
  1177     // Only deploy Qt libs for shared build
       
  1178     if (!project->values("QMAKE_QT_DLL").isEmpty()) {
       
  1179         QStringList& arg = project->values("MSVCPROJ_LIBS");
       
  1180         for (QStringList::ConstIterator it = arg.constBegin(); it != arg.constEnd(); ++it) {
       
  1181             if (it->contains(project->first("QMAKE_LIBDIR"))) {
       
  1182                 QString dllName = *it;
       
  1183 
       
  1184                 if (dllName.contains(QLatin1String("QAxContainer"))
       
  1185                     || dllName.contains(QLatin1String("qtmain"))
       
  1186                     || dllName.contains(QLatin1String("QtUiTools")))
       
  1187                     continue;
       
  1188                 dllName.replace(QLatin1String(".lib") , QLatin1String(".dll"));
       
  1189                 QFileInfo info(dllName);
       
  1190                 conf.deployment.AdditionalFiles += info.fileName()
       
  1191                                                 + "|" + QDir::toNativeSeparators(info.absolutePath())
       
  1192                                                 + "|" + targetPath
       
  1193                                                 + "|0;";
       
  1194             }
       
  1195         }
       
  1196     }
       
  1197 
       
  1198     // C-runtime deployment
       
  1199     QString runtime = project->values("QT_CE_C_RUNTIME").join(QLatin1String(" "));
       
  1200     if (!runtime.isEmpty() && (runtime != QLatin1String("no"))) {
       
  1201         QString runtimeVersion = QLatin1String("msvcr");
       
  1202         QString mkspec = project->first("QMAKESPEC");
       
  1203         // If no .qmake.cache has been found, we fallback to the original mkspec
       
  1204         if (mkspec.isEmpty())
       
  1205             mkspec = project->first("QMAKESPEC_ORIGINAL");
       
  1206 
       
  1207         if (!mkspec.isEmpty()) {
       
  1208             if (mkspec.endsWith("2008"))
       
  1209                 runtimeVersion.append("90");
       
  1210             else
       
  1211                 runtimeVersion.append("80");
       
  1212             if (project->isActiveConfig("debug"))
       
  1213                 runtimeVersion.append("d");
       
  1214             runtimeVersion.append(".dll");
       
  1215 
       
  1216             if (runtime == "yes") {
       
  1217                 // Auto-find C-runtime
       
  1218                 QString vcInstallDir = qgetenv("VCINSTALLDIR");
       
  1219                 if (!vcInstallDir.isEmpty()) {
       
  1220                     vcInstallDir += "\\ce\\dll\\";
       
  1221                     vcInstallDir += project->values("CE_ARCH").join(QLatin1String(" "));
       
  1222                     if (!QFileInfo(vcInstallDir + QDir::separator() + runtimeVersion).exists())
       
  1223                         runtime.clear();
       
  1224                     else
       
  1225                         runtime = vcInstallDir;
       
  1226                 }
       
  1227             }
       
  1228         }
       
  1229 
       
  1230         if (!runtime.isEmpty() && runtime != QLatin1String("yes")) {
       
  1231             conf.deployment.AdditionalFiles += runtimeVersion
       
  1232                                             + "|" + QDir::toNativeSeparators(runtime)
       
  1233                                             + "|" + targetPath
       
  1234                                             + "|0;";
       
  1235         }
       
  1236     }
       
  1237 
       
  1238     // foreach item in DEPLOYMENT
       
  1239     foreach(QString item, project->values("DEPLOYMENT")) {
       
  1240         // get item.path
       
  1241         QString devicePath = project->first(item + ".path");
       
  1242         if (devicePath.isEmpty())
       
  1243             devicePath = targetPath;
       
  1244         // check if item.path is relative (! either /,\ or %)
       
  1245         if (!(devicePath.at(0) == QLatin1Char('/')
       
  1246             || devicePath.at(0) == QLatin1Char('\\')
       
  1247             || devicePath.at(0) == QLatin1Char('%'))) {
       
  1248             // create output path
       
  1249             devicePath = Option::fixPathToLocalOS(QDir::cleanPath(targetPath + QLatin1Char('\\') + devicePath));
       
  1250         }
       
  1251         // foreach d in item.sources
       
  1252         foreach(QString source, project->values(item + ".sources")) {
       
  1253             QString itemDevicePath = devicePath;
       
  1254             source = Option::fixPathToLocalOS(source);
       
  1255             QString nameFilter;
       
  1256             QFileInfo info(source);
       
  1257             QString searchPath;
       
  1258             if (info.isDir()) {
       
  1259                 nameFilter = QLatin1String("*");
       
  1260                 itemDevicePath += "\\" + info.fileName();
       
  1261                 searchPath = info.absoluteFilePath();
       
  1262             } else {
       
  1263                 nameFilter = source.split('\\').last();
       
  1264                 searchPath = info.absolutePath();
       
  1265             }
       
  1266 
       
  1267             int pathSize = searchPath.size();
       
  1268             QDirIterator iterator(searchPath, QStringList() << nameFilter
       
  1269                                   , QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks
       
  1270                                   , QDirIterator::Subdirectories);
       
  1271             // foreach dirIterator-entry in d
       
  1272             while(iterator.hasNext()) {
       
  1273                 iterator.next();
       
  1274                 QString absoluteItemPath = Option::fixPathToLocalOS(QFileInfo(iterator.filePath()).absolutePath());
       
  1275                 // Identify if it is just another subdir
       
  1276                 int diffSize = absoluteItemPath.size() - pathSize;
       
  1277                 // write out rules
       
  1278                 conf.deployment.AdditionalFiles += iterator.fileName()
       
  1279                     + "|" + absoluteItemPath
       
  1280                     + "|" + itemDevicePath + (diffSize ? (absoluteItemPath.right(diffSize)) : QLatin1String(""))
       
  1281                     + "|0;";
       
  1282             }
       
  1283         }
       
  1284     }
       
  1285 }
       
  1286 
       
  1287 void VcprojGenerator::initPreLinkEventTools()
       
  1288 {
       
  1289     VCConfiguration &conf = vcProject.Configuration;
       
  1290     if(!project->values("QMAKE_PRE_LINK").isEmpty()) {
       
  1291         QString cmdline = fixCommandLine(conf.CompilerVersion, var("QMAKE_PRE_LINK"));
       
  1292         conf.preLink.Description = cmdline;
       
  1293         conf.preLink.CommandLine = cmdline;
       
  1294     }
       
  1295 }
       
  1296 
       
  1297 void VcprojGenerator::initRootFiles()
       
  1298 {
       
  1299     // Note: Root files do _not_ have any filter name, filter nor GUID!
       
  1300     vcProject.RootFiles.addFiles(project->values("RC_FILE"));
       
  1301 
       
  1302     vcProject.RootFiles.Project = this;
       
  1303     vcProject.RootFiles.Config = &(vcProject.Configuration);
       
  1304     vcProject.RootFiles.CustomBuild = none;
       
  1305 }
       
  1306 
       
  1307 void VcprojGenerator::initSourceFiles()
       
  1308 {
       
  1309     vcProject.SourceFiles.Name = "Source Files";
       
  1310     vcProject.SourceFiles.Filter = "cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx";
       
  1311     vcProject.SourceFiles.Guid = _GUIDSourceFiles;
       
  1312 
       
  1313     vcProject.SourceFiles.addFiles(project->values("SOURCES"));
       
  1314 
       
  1315     vcProject.SourceFiles.Project = this;
       
  1316     vcProject.SourceFiles.Config = &(vcProject.Configuration);
       
  1317     vcProject.SourceFiles.CustomBuild = none;
       
  1318 }
       
  1319 
       
  1320 void VcprojGenerator::initHeaderFiles()
       
  1321 {
       
  1322     vcProject.HeaderFiles.Name = "Header Files";
       
  1323     vcProject.HeaderFiles.Filter = "h;hpp;hxx;hm;inl;inc;xsd";
       
  1324     vcProject.HeaderFiles.Guid = _GUIDHeaderFiles;
       
  1325 
       
  1326     vcProject.HeaderFiles.addFiles(project->values("HEADERS"));
       
  1327     if (usePCH) // Generated PCH cpp file
       
  1328         vcProject.HeaderFiles.addFile(precompH);
       
  1329 
       
  1330     vcProject.HeaderFiles.Project = this;
       
  1331     vcProject.HeaderFiles.Config = &(vcProject.Configuration);
       
  1332 //    vcProject.HeaderFiles.CustomBuild = mocHdr;
       
  1333 //    addMocArguments(vcProject.HeaderFiles);
       
  1334 }
       
  1335 
       
  1336 void VcprojGenerator::initGeneratedFiles()
       
  1337 {
       
  1338     vcProject.GeneratedFiles.Name = "Generated Files";
       
  1339     vcProject.GeneratedFiles.Filter = "cpp;c;cxx;moc;h;def;odl;idl;res;";
       
  1340     vcProject.GeneratedFiles.Guid = _GUIDGeneratedFiles;
       
  1341 
       
  1342     // ### These cannot have CustomBuild (mocSrc)!!
       
  1343     vcProject.GeneratedFiles.addFiles(project->values("GENERATED_SOURCES"));
       
  1344     vcProject.GeneratedFiles.addFiles(project->values("GENERATED_FILES"));
       
  1345     vcProject.GeneratedFiles.addFiles(project->values("IDLSOURCES"));
       
  1346     vcProject.GeneratedFiles.addFiles(project->values("RES_FILE"));
       
  1347     vcProject.GeneratedFiles.addFiles(project->values("QMAKE_IMAGE_COLLECTION"));   // compat
       
  1348     if(!extraCompilerOutputs.isEmpty())
       
  1349         vcProject.GeneratedFiles.addFiles(extraCompilerOutputs.keys());
       
  1350 
       
  1351     vcProject.GeneratedFiles.Project = this;
       
  1352     vcProject.GeneratedFiles.Config = &(vcProject.Configuration);
       
  1353 //    vcProject.GeneratedFiles.CustomBuild = mocSrc;
       
  1354 }
       
  1355 
       
  1356 void VcprojGenerator::initLexYaccFiles()
       
  1357 {
       
  1358     vcProject.LexYaccFiles.Name = "Lex / Yacc Files";
       
  1359     vcProject.LexYaccFiles.ParseFiles = _False;
       
  1360     vcProject.LexYaccFiles.Filter = "l;y";
       
  1361     vcProject.LexYaccFiles.Guid = _GUIDLexYaccFiles;
       
  1362 
       
  1363     vcProject.LexYaccFiles.addFiles(project->values("LEXSOURCES"));
       
  1364     vcProject.LexYaccFiles.addFiles(project->values("YACCSOURCES"));
       
  1365 
       
  1366     vcProject.LexYaccFiles.Project = this;
       
  1367     vcProject.LexYaccFiles.Config = &(vcProject.Configuration);
       
  1368     vcProject.LexYaccFiles.CustomBuild = lexyacc;
       
  1369 }
       
  1370 
       
  1371 void VcprojGenerator::initTranslationFiles()
       
  1372 {
       
  1373     vcProject.TranslationFiles.Name = "Translation Files";
       
  1374     vcProject.TranslationFiles.ParseFiles = _False;
       
  1375     vcProject.TranslationFiles.Filter = "ts;xlf";
       
  1376     vcProject.TranslationFiles.Guid = _GUIDTranslationFiles;
       
  1377 
       
  1378     vcProject.TranslationFiles.addFiles(project->values("TRANSLATIONS"));
       
  1379 
       
  1380     vcProject.TranslationFiles.Project = this;
       
  1381     vcProject.TranslationFiles.Config = &(vcProject.Configuration);
       
  1382     vcProject.TranslationFiles.CustomBuild = none;
       
  1383 }
       
  1384 
       
  1385 
       
  1386 void VcprojGenerator::initFormFiles()
       
  1387 {
       
  1388     vcProject.FormFiles.Name = "Form Files";
       
  1389     vcProject.FormFiles.ParseFiles = _False;
       
  1390     vcProject.FormFiles.Filter = "ui";
       
  1391     vcProject.FormFiles.Guid = _GUIDFormFiles;
       
  1392 
       
  1393     vcProject.FormFiles.addFiles(project->values("FORMS"));
       
  1394     vcProject.FormFiles.addFiles(project->values("FORMS3"));
       
  1395 
       
  1396     vcProject.FormFiles.Project = this;
       
  1397     vcProject.FormFiles.Config = &(vcProject.Configuration);
       
  1398     vcProject.FormFiles.CustomBuild = none;
       
  1399 }
       
  1400 
       
  1401 
       
  1402 void VcprojGenerator::initResourceFiles()
       
  1403 {
       
  1404     vcProject.ResourceFiles.Name = "Resource Files";
       
  1405     vcProject.ResourceFiles.ParseFiles = _False;
       
  1406     vcProject.ResourceFiles.Filter = "qrc;*"; //"rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;ts;xlf;qrc";
       
  1407     vcProject.ResourceFiles.Guid = _GUIDResourceFiles;
       
  1408 
       
  1409     // Bad hack, please look away -------------------------------------
       
  1410     QString rcc_dep_cmd = project->values("rcc.depend_command").join(" ");
       
  1411     if(!rcc_dep_cmd.isEmpty()) {
       
  1412         QStringList qrc_files = project->values("RESOURCES");
       
  1413         QStringList deps;
       
  1414         if(!qrc_files.isEmpty()) {
       
  1415             for (int i = 0; i < qrc_files.count(); ++i) {
       
  1416                 char buff[256];
       
  1417                 QString dep_cmd = replaceExtraCompilerVariables(rcc_dep_cmd, qrc_files.at(i),"");
       
  1418 
       
  1419                 dep_cmd = Option::fixPathToLocalOS(dep_cmd, true, false);
       
  1420                 if(canExecute(dep_cmd)) {
       
  1421                     if(FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), "r")) {
       
  1422                         QString indeps;
       
  1423                         while(!feof(proc)) {
       
  1424                             int read_in = (int)fread(buff, 1, 255, proc);
       
  1425                             if(!read_in)
       
  1426                                 break;
       
  1427                             indeps += QByteArray(buff, read_in);
       
  1428                         }
       
  1429                         QT_PCLOSE(proc);
       
  1430                         if(!indeps.isEmpty())
       
  1431                             deps += fileFixify(indeps.replace('\n', ' ').simplified().split(' '));
       
  1432                     }
       
  1433                 }
       
  1434             }
       
  1435             vcProject.ResourceFiles.addFiles(deps);
       
  1436         }
       
  1437     }
       
  1438     // You may look again --------------------------------------------
       
  1439 
       
  1440     vcProject.ResourceFiles.addFiles(project->values("RESOURCES"));
       
  1441     vcProject.ResourceFiles.addFiles(project->values("IMAGES"));
       
  1442 
       
  1443     vcProject.ResourceFiles.Project = this;
       
  1444     vcProject.ResourceFiles.Config = &(vcProject.Configuration);
       
  1445     vcProject.ResourceFiles.CustomBuild = none;
       
  1446 }
       
  1447 
       
  1448 void VcprojGenerator::initExtraCompilerOutputs()
       
  1449 {
       
  1450     QStringList otherFilters;
       
  1451     otherFilters << "FORMS"
       
  1452                  << "FORMS3"
       
  1453                  << "GENERATED_FILES"
       
  1454                  << "GENERATED_SOURCES"
       
  1455                  << "HEADERS"
       
  1456                  << "IDLSOURCES"
       
  1457                  << "IMAGES"
       
  1458                  << "LEXSOURCES"
       
  1459                  << "QMAKE_IMAGE_COLLECTION"
       
  1460                  << "RC_FILE"
       
  1461                  << "RESOURCES"
       
  1462                  << "RES_FILE"
       
  1463                  << "SOURCES"
       
  1464                  << "TRANSLATIONS"
       
  1465                  << "YACCSOURCES";
       
  1466     const QStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
       
  1467     for(QStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
       
  1468         QString extracompilerName = project->first((*it) + ".name");
       
  1469         if (extracompilerName.isEmpty())
       
  1470             extracompilerName = (*it);
       
  1471 
       
  1472         // Create an extra compiler filter and add the files
       
  1473         VCFilter extraCompile;
       
  1474         extraCompile.Name = extracompilerName;
       
  1475         extraCompile.ParseFiles = _False;
       
  1476         extraCompile.Filter = "";
       
  1477         extraCompile.Guid = QString(_GUIDExtraCompilerFiles) + "-" + (*it);
       
  1478 
       
  1479 
       
  1480         // If the extra compiler has a variable_out set the output file
       
  1481         // is added to an other file list, and does not need its own..
       
  1482         bool addOnInput = hasBuiltinCompiler(project->first((*it) + ".output"));
       
  1483         QString tmp_other_out = project->first((*it) + ".variable_out");
       
  1484         if (!tmp_other_out.isEmpty() && !addOnInput)
       
  1485             continue;
       
  1486 
       
  1487         if (!addOnInput) {
       
  1488             QString tmp_out = project->first((*it) + ".output");
       
  1489             if (project->values((*it) + ".CONFIG").indexOf("combine") != -1) {
       
  1490                 // Combined output, only one file result
       
  1491                 extraCompile.addFile(
       
  1492                     Option::fixPathToTargetOS(replaceExtraCompilerVariables(tmp_out, QString(), QString()), false));
       
  1493             } else {
       
  1494                 // One output file per input
       
  1495                 QStringList tmp_in = project->values(project->first((*it) + ".input"));
       
  1496                 for (int i = 0; i < tmp_in.count(); ++i) {
       
  1497                     const QString &filename = tmp_in.at(i);
       
  1498                     if (extraCompilerSources.contains(filename))
       
  1499                         extraCompile.addFile(
       
  1500                             Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, tmp_out, QString()), false));
       
  1501                 }
       
  1502             }
       
  1503         } else {
       
  1504             // In this case we the outputs have a built-in compiler, so we cannot add the custom
       
  1505             // build steps there. So, we turn it around and add it to the input files instead,
       
  1506             // provided that the input file variable is not handled already (those in otherFilters
       
  1507             // are handled, so we avoid them).
       
  1508             QStringList inputVars = project->values((*it) + ".input");
       
  1509             foreach(QString inputVar, inputVars) {
       
  1510                 if (!otherFilters.contains(inputVar)) {
       
  1511                     QStringList tmp_in = project->values(inputVar);
       
  1512                     for (int i = 0; i < tmp_in.count(); ++i) {
       
  1513                         const QString &filename = tmp_in.at(i);
       
  1514                         if (extraCompilerSources.contains(filename))
       
  1515                             extraCompile.addFile(
       
  1516                                 Option::fixPathToTargetOS(replaceExtraCompilerVariables(filename, QString(), QString()), false));
       
  1517                     }
       
  1518                 }
       
  1519             }
       
  1520         }
       
  1521         extraCompile.Project = this;
       
  1522         extraCompile.Config = &(vcProject.Configuration);
       
  1523         extraCompile.CustomBuild = none;
       
  1524 
       
  1525         vcProject.ExtraCompilersFiles.append(extraCompile);
       
  1526     }
       
  1527 }
       
  1528 
       
  1529 /* \internal
       
  1530     Sets up all needed variables from the environment and all the different caches and .conf files
       
  1531 */
       
  1532 
       
  1533 void VcprojGenerator::initOld()
       
  1534 {
       
  1535     if(init_flag)
       
  1536         return;
       
  1537 
       
  1538     init_flag = true;
       
  1539     QStringList::Iterator it;
       
  1540 
       
  1541     // Decode version, and add it to $$MSVCPROJ_VERSION --------------
       
  1542     if(!project->values("VERSION").isEmpty()) {
       
  1543         QString version = project->values("VERSION")[0];
       
  1544         int firstDot = version.indexOf(".");
       
  1545         QString major = version.left(firstDot);
       
  1546         QString minor = version.right(version.length() - firstDot - 1);
       
  1547         minor.replace(QRegExp("\\."), "");
       
  1548         project->values("MSVCPROJ_VERSION").append("/VERSION:" + major + "." + minor);
       
  1549         project->values("QMAKE_LFLAGS").append("/VERSION:" + major + "." + minor);
       
  1550     }
       
  1551 
       
  1552     project->values("QMAKE_LIBS") += escapeFilePaths(project->values("LIBS"));
       
  1553     project->values("QMAKE_LIBS_PRIVATE") += escapeFilePaths(project->values("LIBS_PRIVATE"));
       
  1554 
       
  1555      // Get filename w/o extension -----------------------------------
       
  1556     QString msvcproj_project = "";
       
  1557     QString targetfilename = "";
       
  1558     if(!project->isEmpty("TARGET")) {
       
  1559         project->values("TARGET") = unescapeFilePaths(project->values("TARGET"));
       
  1560         targetfilename = msvcproj_project = project->first("TARGET");
       
  1561     }
       
  1562 
       
  1563     // Init base class too -------------------------------------------
       
  1564     MakefileGenerator::init();
       
  1565 
       
  1566     if(msvcproj_project.isEmpty())
       
  1567         msvcproj_project = Option::output.fileName();
       
  1568 
       
  1569     msvcproj_project = msvcproj_project.right(msvcproj_project.length() - msvcproj_project.lastIndexOf("\\") - 1);
       
  1570     msvcproj_project = msvcproj_project.left(msvcproj_project.lastIndexOf("."));
       
  1571     msvcproj_project.replace(QRegExp("-"), "");
       
  1572 
       
  1573     project->values("MSVCPROJ_PROJECT").append(msvcproj_project);
       
  1574     QStringList &proj = project->values("MSVCPROJ_PROJECT");
       
  1575 
       
  1576     for(it = proj.begin(); it != proj.end(); ++it)
       
  1577         (*it).replace(QRegExp("\\.[a-zA-Z0-9_]*$"), "");
       
  1578 
       
  1579     // SUBSYSTEM -----------------------------------------------------
       
  1580     if(!project->values("QMAKE_APP_FLAG").isEmpty()) {
       
  1581             project->values("MSVCPROJ_TEMPLATE").append("win32app" + project->first("VCPROJ_EXTENSION"));
       
  1582             if(project->isActiveConfig("console")) {
       
  1583                 project->values("MSVCPROJ_CONSOLE").append("CONSOLE");
       
  1584                 project->values("MSVCPROJ_WINCONDEF").append("_CONSOLE");
       
  1585                 project->values("MSVCPROJ_VCPROJTYPE").append("0x0103");
       
  1586                 project->values("MSVCPROJ_SUBSYSTEM").append("CONSOLE");
       
  1587             } else {
       
  1588                 project->values("MSVCPROJ_CONSOLE").clear();
       
  1589                 project->values("MSVCPROJ_WINCONDEF").append("_WINDOWS");
       
  1590                 project->values("MSVCPROJ_VCPROJTYPE").append("0x0101");
       
  1591                 project->values("MSVCPROJ_SUBSYSTEM").append("WINDOWS");
       
  1592             }
       
  1593     }
       
  1594 
       
  1595     // $$QMAKE.. -> $$MSVCPROJ.. -------------------------------------
       
  1596     project->values("MSVCPROJ_LIBS") += project->values("QMAKE_LIBS");
       
  1597     project->values("MSVCPROJ_LIBS") += project->values("QMAKE_LIBS_PRIVATE");
       
  1598     project->values("MSVCPROJ_LFLAGS") += project->values("QMAKE_LFLAGS");
       
  1599     if(!project->values("QMAKE_LIBDIR").isEmpty()) {
       
  1600         QStringList strl = project->values("QMAKE_LIBDIR");
       
  1601         QStringList::iterator stri;
       
  1602         for(stri = strl.begin(); stri != strl.end(); ++stri) {
       
  1603             if(!(*stri).startsWith("/LIBPATH:"))
       
  1604                 (*stri).prepend("/LIBPATH:");
       
  1605         }
       
  1606         project->values("MSVCPROJ_LFLAGS") += strl;
       
  1607     }
       
  1608     project->values("MSVCPROJ_CXXFLAGS") += project->values("QMAKE_CXXFLAGS");
       
  1609     QStringList &incs = project->values("INCLUDEPATH");
       
  1610     for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
       
  1611         QString inc = (*incit);
       
  1612         if (!inc.startsWith('"') && !inc.endsWith('"'))
       
  1613             inc = QString("\"%1\"").arg(inc); // Quote all paths if not quoted already
       
  1614         project->values("MSVCPROJ_INCPATH").append("-I" + inc);
       
  1615     }
       
  1616     project->values("MSVCPROJ_INCPATH").append("-I" + specdir());
       
  1617 
       
  1618     QString dest;
       
  1619     project->values("MSVCPROJ_TARGET") = QStringList(project->first("TARGET"));
       
  1620     Option::fixPathToTargetOS(project->first("TARGET"));
       
  1621     dest = project->first("TARGET") + project->first("TARGET_EXT");
       
  1622     project->values("MSVCPROJ_TARGET") = QStringList(dest);
       
  1623 
       
  1624     // DLL COPY ------------------------------------------------------
       
  1625     if(project->isActiveConfig("dll") && !project->values("DLLDESTDIR").isEmpty()) {
       
  1626         QStringList dlldirs = project->values("DLLDESTDIR");
       
  1627         QString copydll("");
       
  1628         QStringList::Iterator dlldir;
       
  1629         for(dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir) {
       
  1630             if(!copydll.isEmpty())
       
  1631                 copydll += " && ";
       
  1632             copydll += "copy  \"$(TargetPath)\" \"" + *dlldir + "\"";
       
  1633         }
       
  1634 
       
  1635         QString deststr("Copy " + dest + " to ");
       
  1636         for(dlldir = dlldirs.begin(); dlldir != dlldirs.end();) {
       
  1637             deststr += *dlldir;
       
  1638             ++dlldir;
       
  1639             if(dlldir != dlldirs.end())
       
  1640                 deststr += ", ";
       
  1641         }
       
  1642 
       
  1643         project->values("MSVCPROJ_COPY_DLL").append(copydll);
       
  1644         project->values("MSVCPROJ_COPY_DLL_DESC").append(deststr);
       
  1645     }
       
  1646 
       
  1647     if (!project->values("DEF_FILE").isEmpty())
       
  1648         project->values("MSVCPROJ_LFLAGS").append("/DEF:"+project->first("DEF_FILE"));
       
  1649 
       
  1650     project->values("QMAKE_INTERNAL_PRL_LIBS") << "MSVCPROJ_LIBS";
       
  1651 
       
  1652     // Verbose output if "-d -d"...
       
  1653     outputVariables();
       
  1654 }
       
  1655 
       
  1656 // ------------------------------------------------------------------------------------------------
       
  1657 // ------------------------------------------------------------------------------------------------
       
  1658 
       
  1659 QString VcprojGenerator::replaceExtraCompilerVariables(const QString &var, const QStringList &in, const QStringList &out)
       
  1660 {
       
  1661     QString ret = MakefileGenerator::replaceExtraCompilerVariables(var, in, out);
       
  1662 
       
  1663     QStringList &defines = project->values("VCPROJ_MAKEFILE_DEFINES");
       
  1664     if(defines.isEmpty())
       
  1665         defines.append(varGlue("PRL_EXPORT_DEFINES"," -D"," -D","") +
       
  1666                        varGlue("DEFINES"," -D"," -D",""));
       
  1667     ret.replace("$(DEFINES)", defines.first());
       
  1668 
       
  1669     QStringList &incpath = project->values("VCPROJ_MAKEFILE_INCPATH");
       
  1670     if(incpath.isEmpty() && !this->var("MSVCPROJ_INCPATH").isEmpty())
       
  1671         incpath.append(this->var("MSVCPROJ_INCPATH"));
       
  1672     ret.replace("$(INCPATH)", incpath.join(" "));
       
  1673 
       
  1674     return ret;
       
  1675 }
       
  1676 
       
  1677 
       
  1678 
       
  1679 bool VcprojGenerator::openOutput(QFile &file, const QString &/*build*/) const
       
  1680 {
       
  1681     QString outdir;
       
  1682     if(!file.fileName().isEmpty()) {
       
  1683         QFileInfo fi(fileInfo(file.fileName()));
       
  1684         if(fi.isDir())
       
  1685             outdir = file.fileName() + QDir::separator();
       
  1686     }
       
  1687     if(!outdir.isEmpty() || file.fileName().isEmpty()) {
       
  1688         QString ext = project->first("VCPROJ_EXTENSION");
       
  1689         if(project->first("TEMPLATE") == "vcsubdirs")
       
  1690             ext = project->first("VCSOLUTION_EXTENSION");
       
  1691         QString outputName = unescapeFilePath(project->first("TARGET"));
       
  1692         if (!project->first("MAKEFILE").isEmpty())
       
  1693             outputName = project->first("MAKEFILE");
       
  1694         file.setFileName(outdir + outputName + ext);
       
  1695     }
       
  1696     return Win32MakefileGenerator::openOutput(file, QString());
       
  1697 }
       
  1698 
       
  1699 QString VcprojGenerator::fixFilename(QString ofile) const
       
  1700 {
       
  1701     ofile = Option::fixPathToLocalOS(ofile);
       
  1702     int slashfind = ofile.lastIndexOf(Option::dir_sep);
       
  1703     if(slashfind == -1) {
       
  1704         ofile = ofile.replace('-', '_');
       
  1705     } else {
       
  1706         int hypenfind = ofile.indexOf('-', slashfind);
       
  1707         while (hypenfind != -1 && slashfind < hypenfind) {
       
  1708             ofile = ofile.replace(hypenfind, 1, '_');
       
  1709             hypenfind = ofile.indexOf('-', hypenfind + 1);
       
  1710         }
       
  1711     }
       
  1712     return ofile;
       
  1713 }
       
  1714 
       
  1715 QString VcprojGenerator::findTemplate(QString file)
       
  1716 {
       
  1717     QString ret;
       
  1718     if(!exists((ret = file)) &&
       
  1719        !exists((ret = QString(Option::mkfile::qmakespec + "/" + file))) &&
       
  1720        !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc.net/" + file))) &&
       
  1721        !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc2002/" + file))) &&
       
  1722        !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc2003/" + file))) &&
       
  1723        !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc2005/" + file))) &&
       
  1724        !exists((ret = QString(QLibraryInfo::location(QLibraryInfo::DataPath) + "/win32-msvc2008/" + file))) &&
       
  1725        !exists((ret = (QString(qgetenv("HOME")) + "/.tmake/" + file))))
       
  1726         return "";
       
  1727     debug_msg(1, "Generator: MSVC.NET: Found template \'%s\'", ret.toLatin1().constData());
       
  1728     return ret;
       
  1729 }
       
  1730 
       
  1731 
       
  1732 void VcprojGenerator::processPrlVariable(const QString &var, const QStringList &l)
       
  1733 {
       
  1734     if(var == "QMAKE_PRL_DEFINES") {
       
  1735         QStringList &out = project->values("MSVCPROJ_DEFINES");
       
  1736         for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
       
  1737             if(out.indexOf((*it)) == -1)
       
  1738                 out.append((" /D " + *it));
       
  1739         }
       
  1740     } else {
       
  1741         MakefileGenerator::processPrlVariable(var, l);
       
  1742     }
       
  1743 }
       
  1744 
       
  1745 void VcprojGenerator::outputVariables()
       
  1746 {
       
  1747 #if 0
       
  1748     qDebug("Generator: MSVC.NET: List of current variables:");
       
  1749     for(QMap<QString, QStringList>::ConstIterator it = project->variables().begin(); it != project->variables().end(); ++it)
       
  1750         qDebug("Generator: MSVC.NET: %s => %s", it.key().toLatin1().constData(), it.data().join(" | ").toLatin1().constData());
       
  1751 #endif
       
  1752 }
       
  1753 
       
  1754 QT_END_NAMESPACE
       
  1755