Qt项目包括在qmake中构建的子项目 [英] Qt project include subprojects build in qmake

查看:93
本文介绍了Qt项目包括在qmake中构建的子项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Qt/C ++编写的跨平台项目,该项目使用以Go编写的静态库作为依赖项.Go项目使用GNU Make生成了两个文件( .a .h ).

I have a cross-platform project written in Qt/C++, this project uses a static library that is written in Go as a dependency. Go project generates two files (.a and .h as expected) using GNU Make.

我正在尝试使我正在使用 qmake 生成 Makefile 的构建自动化,然后将该Makefile的默认目标作为简单的 $ make .

I am trying to automate builds for which I am using qmake to generate Makefile and then calling default target of this Makefile as simple $ make.

现在,我的构建首先明确执行 git clone go-subproject&&cd go-subproject&&make ,然后将其复制到生成的库和头文件中,然后再调用 git clone qt-project&&qmake&&make (请注意,这些命令不是确切的命令,它们只是我现在正在做的简化说明).

Right now my build first explicitly does git clone go-subproject && cd go-subproject && make, then it copies over resulting library and headers file and only then calls git clone qt-project && qmake && make (note that those are not exact commands, these are just simplified explanation of what I am doing right now).

我可以将子项目作为 git模块包含在内,以便在执行 git clone qt-project 时它会自动获取子项目的最新代码.

I can include subproject as git module, so that it will automatically get latest code of subproject when doing git clone qt-project.

要使其正常工作,如何指示 .pro 文件生成将首先构建子项目的Makefile?

For that to work How do I instruct .pro file to generate Makefile that will first build subproject?

更新:

问题的结构似乎不清楚.以下是结构外观的一些可视化:

Seems the structure is not clear from the question. Here is some visualization of how structure would look like:

/
|
+- .git/
|
+- qt-project.pro
|
+- go-project/
|            |
|            +- .git/
|            |
|            +- Makefile

因此,采用上述结构,我想仅用 $ qmake&&制作

So with the above structure I would like to build entire project with just $ qmake && make

我需要在我的 qt-project.pro 中包含什么代码?

What code would I need to have in my qt-project.pro that would do that?

推荐答案

在寻找正确答案后,我自己找到了解决方案.这可以通过 QMAKE_EXTRA_TARGETS PRE_TARGETDEPS 变量并定义自定义目标来完成.例如上述项目:

After searching for a correct answer I found the solution myself. This can be done with QMAKE_EXTRA_TARGETS and PRE_TARGETDEPS variables and defining custom targets. Such as for the project described above:

在我的 .pro 文件中:

# Build sub project
subproject.target = subproject
subproject.commands = cd $$PWD/go-project/ && \
                      make

QMAKE_EXTRA_TARGETS += subproject
PRE_TARGETDEPS += subproject

QMAKE_EXTRA_TARGETS 将带有指定命令的附加目标添加到生成的Makefile中,而 PRE_TARGETDEPS 将此目标添加为整个项目的依赖项.

The QMAKE_EXTRA_TARGETS will add the additional target with specified commands to the produced Makefile and PRE_TARGETDEPS will add this target as a dependency to the whole project.

这篇关于Qt项目包括在qmake中构建的子项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆