是否可以設置TEMPLATE = subdirs
.pro文件,以便qmake -tp vc
將在生成的Visual Studio解決方案中設置項目依賴關係?從Qt5 .pro文件設置Visual Studio 2010解決方案項目依賴關係
我嘗試過使用CONFIG += ordered
後跟SUBDIRS += <libdir>
條目的順序正確,但這似乎對解決方案屬性對話框中的「項目依賴性」設置沒有影響。
謝謝!
是否可以設置TEMPLATE = subdirs
.pro文件,以便qmake -tp vc
將在生成的Visual Studio解決方案中設置項目依賴關係?從Qt5 .pro文件設置Visual Studio 2010解決方案項目依賴關係
我嘗試過使用CONFIG += ordered
後跟SUBDIRS += <libdir>
條目的順序正確,但這似乎對解決方案屬性對話框中的「項目依賴性」設置沒有影響。
謝謝!
我在回答我自己的問題,因爲似乎還沒有人找到解決方案。據我所知,仍然無法使用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;
}
您正在使用哪些版本的Qt和Visual Studio? –
我們使用的是Qt5和Visual Studio 2010.我們以前使用過Qt4.8和VS2008。使用該設置,我們通過運行一個腳本來設置依賴關係,該腳本在qmake創建它之後直接更改了.sln文件。 VS2010中新的.sln格式打破了這個腳本,我們希望有一個更直接的解決方案。 – Joey