从Qt5 .pro文件设置Visual Studio 2010解决方案项目依赖项



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

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

谢谢!

我在回答我自己的问题,因为似乎还没有人找到解决方案。据我所知,仍然没有办法使用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) = postProjectn";
                for(unsigned int i = 0; i < currentDependencies.size(); i++)
                {
                    writer << "tt" << currentDependencies[i] << " = " << currentDependencies[i] << "n";                  
                }
                writer << "tEndProjectSectionn";
            }
        }       
    }
    writer.flush();
    outFile.close();
    return 0;
}

相关内容

  • 没有找到相关文章

最新更新