2013-01-15 70 views
0

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

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

谢谢!

+0

您正在使用哪些版本的Qt和Visual Studio? –

+0

我们使用的是Qt5和Visual Studio 2010.我们以前使用过Qt4.8和VS2008。使用该设置,我们通过运行一个脚本来设置依赖关系,该脚本在qmake创建它之后直接更改了.sln文件。 VS2010中新的.sln格式打破了这个脚本,我们希望有一个更直接的解决方案。 – Joey

回答

0

我在回答我自己的问题,因为似乎还没有人找到解决方案。据我所知,仍然无法使用QT .pro文件设置Visual Studio项目依赖项。我们正在使用我们开发的可执行文件(也使用Qt)在项目构建完成后手动执行此操作。用于构建可执行文件的代码适用于Visual Studio 2010解决方案,并显示在下面。它非常简单,并且可以更新您的解决方案,以便所有包含的项目都将取决于命令行中输入的所有项目。即。 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; 
} 
相关问题