0

是否可以设置一个TEMPLATE = subdirs.pro 文件,以便qmake -tp vc在生成的 Visual Studio 解决方案中设置项目依赖项?

我尝试使用CONFIG += ordered后跟以SUBDIRS += <libdir>正确顺序输入的条目,但这似乎对解决方案属性对话框中的“项目依赖项”设置没有影响。

谢谢!

4

1 回答 1

0

我正在回答我自己的问题,因为似乎还没有人找到解决方案。据我所知,仍然无法使用 QT .pro 文件设置 Visual Studio 项目依赖项。我们正在使用我们开发的可执行文件(也使用 Qt)在项目构建完成后手动执行此操作。用于构建可执行文件的代码适用于 Visual Studio 2010 解决方案,如下所示。它相当简单,并且会更新您的解决方案,以便所有包含的项目都依赖于命令行中的所有项目输入。IE。vcSlnDependencies filename.sln dependency1 dependency2 dependency3将 filename.sln 中的所有项目设置为依赖于dependency1、dependency2 和dependency3。显然,一个项目永远不会依赖于它自己。这段代码应该很容易修改,以允许更复杂的依赖结构。

#include <QFile>
#include <QDir>
#include <QFileInfo>
#include <QStringList>
#include <QUuid>
#include <QTextStream>

#include <iostream>
#include <vector>
#include <map>

std::map<QString, QString> dependencyGuids;
std::vector<QString> dependencies;

int main(int argc, char *argv[])
{
    if(argc<3)
    {
        std::cout << "Usage:" << std::endl << std::endl << "vcSlnDependencies filename.sln dependency1 dependency2 dependency3 ..." << std::endl;

        return -1;
    }
    else
    {
        for(int i = 2; i < argc; i++)
        {
            dependencies.push_back(argv[i]);
        }
    }

    QFile file(argv[1]);
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        std::cout << "Could not open sln file: " << argv[1] << "." << std::endl;
        return -1;
    }

    QFileInfo fileInfo(file);

    std::cout << "Processing " << fileInfo.fileName().toStdString() << std::endl;

    QByteArray fileData;
    fileData = file.readAll();
    file.close();

    QFile outFile(argv[1]);
    if(!outFile.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        std::cout << "Could not open sln file: " << argv[1] << "." << std::endl;
        return -1;
    }

    QTextStream reader(fileData);
    QTextStream writer(&outFile);

    //first populate the dependency guids
    while(!reader.atEnd())
    {
        QString currentLine = reader.readLine();

        for(unsigned int i = 0; i < dependencies.size(); i++)
        {
            if(currentLine.contains(dependencies[i]) && currentLine.contains(".vcxproj") && currentLine.contains("Project(\"{"))
            {
                dependencyGuids[dependencies[i]] = currentLine.right(39).left(38);
                std::cout << "Setting dependency GUID for " << dependencies[i].toLatin1().data() << " to " << currentLine.right(39).left(38).toLatin1().data() << "\n";
            }
        }               
    }
    reader.seek(0);

    //now update other projects with those dependencies
    while(!reader.atEnd())
    {
        QString currentLine = reader.readLine();

        writer << currentLine << "\n";

        if(currentLine.contains(".vcxproj") && currentLine.contains("Project(\"{"))
        {
            QString currentGuid = currentLine.mid(9,38);

            std::vector<QString> currentDependencies;

            for(std::map<QString, QString>::const_iterator iter = dependencyGuids.begin(); iter != dependencyGuids.end(); ++iter)
            {
                if(iter->second != currentGuid)
                {
                    currentDependencies.push_back(iter->second);
                }
            }

            if(currentDependencies.size() > 0)
            {
                writer << "\tProjectSection(ProjectDependencies) = postProject\n";

                for(unsigned int i = 0; i < currentDependencies.size(); i++)
                {
                    writer << "\t\t" << currentDependencies[i] << " = " << currentDependencies[i] << "\n";                  
                }

                writer << "\tEndProjectSection\n";
            }
        }       
    }

    writer.flush();
    outFile.close();

    return 0;
}
于 2013-01-23T16:46:51.860 回答