如何让 qmake 生成“项目依赖项”在 Visual Studio .sln 项目中

发布于 2024-08-23 07:32:14 字数 381 浏览 6 评论 0原文

我有一个由几个库和一个依赖于它们的应用程序组成的 qmake 版本。使用 subdirs 模板,我可以让 qmake 输出一个 .sln 文件,该文件在 VC2008 中几乎符合我的喜好。尽管我已经以我见过的各种方式指定了目标之间的依赖关系,但最终在 .sln 文件中没有“项目依赖关系”,我必须手动添加这些依赖关系。

到目前为止,我已经尝试过

CONFIG += ordered

正确的排序,但没有成功。

类似地,更神秘的语法:

client.depends = core common

这也不起作用。当我加载 sln 时,没有任何依赖项出现。

I have a qmake build of a few libraries and an app which depends on them. Using the subdirs template I'm able to get qmake to output a .sln file which works almost to my liking in VC2008. Though I've specified the dependencies between the targets in every way I've seen described, I end up with no "project dependencies" in the .sln file, and I have to add these in manually.

So far I've tried

CONFIG += ordered

with correct ordering to no avail.

And similarly the more arcane syntax:

client.depends = core common

Which also doesn't work. No dependencies whatsoever show up when I load the sln.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丑疤怪 2024-08-30 07:32:14

qmake 的 MSVC 后端(解决方案生成器)不支持 CONFIG +=orderedtarget.depends =。早在 2010 年 Qt 4.7 左右,文档就没有提到这一点,但在 Qt 4.8 中,开发人员更新了文档 相应(参见目标部分备注):

  • .depends 该子项目依赖于指定的子项目。仅在使用 makefile 的平台上可用。
  • Visual Studio 不支持 ordered 选项。

但他们提供了一种解决方法(在神秘帖子中讨论< /a>),它仍然有效,甚至记录在同一个

  1. a) 有一个 Lib/DLL 项目,其 TARGET(使用 .lib,而不是 .dll)在您的解决方案中另一个项目的链接行上使用(您可以使用以下命令修改链接行) LIBS)。

    b) 有一个 Exe 项目,其 TARGET 用于解决方案中另一个项目的自定义构建步骤。

  2. 您不使用 TARGET 变量中的路径(为此使用 DESTDIR/DLLDESTDIR),例如 TARGET=$(SOME_VARIABLE)/myLib 将不起作用。
  3. 如果您的库有特殊位置,请指定 -Lmy/library/path 和 LIBS += mylib,而不是仅使用 LIBS += my/library/path/mylib
  4. 叶项目是在生成解决方案文件之前创建的。 (您可以使用 qmake 的递归标志来执行此操作,例如“qmake -tp vc -r [yourproject.pro]”

基本上,当您的 lib 的目标名称(yourlib.lib)时,qmake 将生成依赖项等于最终应用程序的导入库之一(具有LIBS += yourlib.lib)。
(请参阅 qmake 的源代码,其中导入库作为依赖项添加,并且 稍微进一步,它们与项目目标名称进行比较)

这是在解决方案中生成依赖项的最小设置:

solution.pro
  TEMPLATE = vcsubdirs
  SUBDIRS = main app

app/app.pro
  LIBS += main.lib

main/main.pro
  TARGET = main
  TEMPLATE = vclib

有了这些,如果您运行qmake -r -tp vc,您将在生成的 .sln 中获得显式依赖项:

GlobalSection(ProjectDependencies) = postSolution
    {E634D0EB-B004-3246-AADA-E383A376158F}.0 = {1BD6E999-63E6-36F5-99EE-1A650332198C}
EndGlobalSection

Both CONFIG += ordered and target.depends = are not supported by the qmake's MSVC backend (solution generator). Back in 2010 with Qt 4.7 around, the docs didn't mention that, but in Qt 4.8 the developers have updated the docs accordingly (see the Target section remarks):

  • .depends This subproject depends on specified subproject. Available only on platforms that use makefiles.
  • The ordered option is not supported for Visual Studio.

But they had provided a workaround (which is discussed in that cryptic post), and it's still valid and even documented in the same target section. Too bad I had to rebuild qmake and use a debugger to verify that:

  1. a) There is a Lib/DLL project of which TARGET (the .lib is used and not the .dll) is used on the link line of another project in your solution (you can modify the link line with LIBS).

    b) There is an Exe project of which TARGET is used in a custom build-step of another project in your solution.

  2. You don't use paths in the TARGET variable (use DESTDIR/DLLDESTDIR for that), e.g, TARGET=$(SOME_VARIABLE)/myLib, won't work.
  3. If you have a special location for your libs, you specify the -Lmy/library/path and LIBS += mylib, instead of just using LIBS += my/library/path/mylib
  4. The leaf projects are created before you generate the solution file. (You can use the recursive flag for qmake to do this, like "qmake -tp vc -r [yourproject.pro]"

Basically, qmake will generate dependency when your lib's target name (yourlib.lib) is equal to the one of the import libraries of the final app (that has LIBS += yourlib.lib).
(See qmake's source where the import libraries are added as dependencies, and a little further where they're compared with the project target names)

Here is the minimal setup that generates dependencies in the solution:

solution.pro
  TEMPLATE = vcsubdirs
  SUBDIRS = main app

app/app.pro
  LIBS += main.lib

main/main.pro
  TARGET = main
  TEMPLATE = vclib

With those, if you run qmake -r -tp vc, you'll get the explicit dependency in the generated .sln:

GlobalSection(ProjectDependencies) = postSolution
    {E634D0EB-B004-3246-AADA-E383A376158F}.0 = {1BD6E999-63E6-36F5-99EE-1A650332198C}
EndGlobalSection
偏爱自由 2024-08-30 07:32:14

来自旧邮件列表条目:
http://lists.trolltech.com/qt-interest/ 2006-07/thread00238-0.html

看来它试图找出哪些事情依赖于你。您是否能够从 sln 进行构建,而无需手动输入项目依赖项?

From an old mailing list entry:
http://lists.trolltech.com/qt-interest/2006-07/thread00238-0.html

It appears that it tries to figure out which things are dependent for you. Are you able to build from the sln without entering the project dependencies manually?

请止步禁区 2024-08-30 07:32:14

我不是 makefile 专家,但如果我是你,我会尝试通过编辑 .pro 文件、运行 qmake 然后查看 MAKLEFILE 中自动生成的结果,在 QtCreator 中重新创建该依赖关系。如果您想了解 qmake 的工作原理,请查看 qt 文档。

I am not a wiz in makefiles but if I were you, I would try to recreate that dependency in with QtCreator by editing the .pro file, running qmake then looking at the auto-generated result in the MAKLEFILE. If you want to know how qmake works then look at the qt documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文