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

编程入门 行业动态 更新时间:2024-10-15 16:21:27
本文介绍了如何获取qmake来生成“项目依赖”在Visual Studio .sln项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 qmake 构建的几个库和一个依赖于他们的应用程序。使用subdirs模板我能够得到qmake输出一个.sln文件,几乎是我喜欢在VC2008。虽然我已经以我所见过的每种方式指定了目标之间的依赖关系,但我最终在.sln文件中没有项目依赖,我必须手动添加这些依赖。

到目前为止,我尝试了

CONFIG + = ordered

正确的顺序无效。

client.depends = core common

这也不工作。 c> $ CONFIG + =

解决方案 qmake的MSVC后端(解决方案生成器)不支持c $ c>和 target.depends = 。回到2010年的Qt 4.7周围,文档没有提到,但在Qt 4.8开发人员更新了文档(见目标部分备注):

  • .depends 此子项目取决于指定的子项目。仅适用于使用makefile的平台
  • Visual Studio不支持订购选项。

但他们提供了一个解决方法(在加密帖),它仍然有效,甚至记录在同一个 target 部分。太糟糕了,我不得不重建qmake和使用调试器来验证:

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

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

  • 不要使用TARGET变量中的路径(使用DESTDIR / DLLDESTDIR),例如TARGET = $(SOME_VARIABLE)/ myLib,将无法工作。
  • 位置,您指定-Lmy / library / path和LIBS + = mylib,而不是只使用LIBS + = my / library / path / mylib
  • 创建叶项目之前生成解决方案文件。 (您可以使用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 )= postSolution {E634D0EB-B004-3246-AADA-E383A376158F} .0 = {1BD6E999-63E6-36F5-99EE-1A650332198C} EndGlobalSection

    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.

    解决方案

    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:

  • 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.

  • You don't use paths in the TARGET variable (use DESTDIR/DLLDESTDIR for that), e.g, TARGET=$(SOME_VARIABLE)/myLib, won't work.
  • 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
  • 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

    更多推荐

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

    本文发布于:2023-11-09 04:35:27,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1571419.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:项目   qmake   Visual   sln   Studio

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!