如何在 qmake 生成的 Makefile 中添加自定义目标?

发布于 2024-09-24 18:10:48 字数 536 浏览 5 评论 0原文

我使用 qmake 生成 Makefile,效果很好。但是,有时我想向生成的 Makefile 添加更多内容,而不必编辑生成的 Makefile。

假设我们在源代码旁边有一个 Doxygen 目录,我需要在那里运行一些 doxygen 命令来生成文档。因此,最好将其作为主 Makefile 中的目标。但默认情况下,qmake 不理解这种类型的额外内容。

那么我可以添加一些东西来告诉 qmake 在“doxygen”目录中包含辅助 Makefile,或者直接在 qmake 配置中添加“额外目标”吗?


也许类似于:

I use qmake to generate the Makefile, and that works well. However, sometimes I want to add more stuff to the generated Makefile without having to edit the generated Makefile.

Let's say that we beside the source code have a Doxygen directory, and there I need to run some doxygen commands to generate the documentation. So it would be nice to have this as a target in the main Makefile. But as default qmake do not understand this type of extra stuff.

So can I add something to tell qmake to include a secondary Makefile in the "doxygen" dir, or maybe add "extra targets" directly in the qmake config?


Maybe something like:

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

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

发布评论

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

评论(4

掐死时间 2024-10-01 18:10:48

我正在处理同样的问题,到目前为止,我使用 QMAKE_EXTRA_TARGETS 变量来构建文档目标的成功有限,如下所示:

docs.depends = $(SOURCES)
docs.commands = (cat Doxyfile; echo "INPUT = $?") | doxygen -
QMAKE_EXTRA_TARGETS += docs

其中 Doxyfile 具有基本的 doxygen 配置设置减去我通过“echo”附加的 INPUT 符号,以仅包含$(SOURCES) 中的 Makefile 依赖关系不满足。

这种方法似乎有效,因为它只为已更改的源文件重新创建文档,这很好,但我遇到了另一个问题,因为我的 qmake 项目文件是使用 debug_and_release CONFIG 选项构建的,因此它生成 Makefile、Makefile.Debug 和Makefile.Release 但 SOURCES 仅在调试和发布 Makefile 中定义,迫使我显式执行 make -f Makefile.Debug docs 而不是更简单直观的 make docs构建文档。

以前有人从 QMAKE_EXTRA_TARGETS 角度解决过这个问题吗?

I am working this same issue and so far I have had limited success using the QMAKE_EXTRA_TARGETS variable to build the docs target like so:

docs.depends = $(SOURCES)
docs.commands = (cat Doxyfile; echo "INPUT = $?") | doxygen -
QMAKE_EXTRA_TARGETS += docs

where Doxyfile has the basic doxygen config settings minus the INPUT symbol which I am appending via 'echo' to include only the unsatisfied Makefile dependencies in $(SOURCES).

This approach seems to work in that it only recreates documentation for source files that have changed which is good but I have encountered another problem in that my qmake project file is built with the debug_and_release CONFIG option so that it generates Makefile, Makefile.Debug, and Makefile.Release but SOURCES are only defined in the debug and release Makefiles forcing me to explicitly do a make -f Makefile.Debug docs instead of the more simple and intuitive make docs to build the docs.

Anybody ever tackled the problem from this QMAKE_EXTRA_TARGETS perspective before?

左秋 2024-10-01 18:10:48

这是一个老问题,但无论如何我都会添加一个答案。

虽然 qmake 中似乎没有对自定义规则的一般支持,但有一个简单的方法可以做到这一点,假设是 GNU make。只需创建一个名为 makefile(全部小写)的文件:

include Makefile

re: clean
        $(MAKE) all

其中最后两行是我的自定义规则。

如果两者都存在,GNU make 将使用 makefile,而不是 Makefile。

顺便说一句,re 规则通过“make -j8 clean all”解决了问题。该命令将在完成清理之前开始执行所有操作。 re 规则保证顺序性。

This is an old question, but I'll add an answer anyway.

While there seems to be no general support for custom rules in qmake, there is a simple way to do it, assuming GNU make. Just create a file called makefile (all lower case):

include Makefile

re: clean
        $(MAKE) all

where the last two lines are my custom rule.

GNU make will use makefile, not Makefile, if both exist.

BTW, the re rule solves the problem with "make -j8 clean all". This command will start doing all before it has finished doing clean. The re rules guarantees sequentiality.

浅唱々樱花落 2024-10-01 18:10:48

这里提到的未记录选项怎么样 http://paulf.free.fr/undocumented_qmake.html
添加 doxygen 目标下可以找到以下内容:

# custom target 'doc' in *.pro file
dox.target = doc
dox.commands = doxygen Doxyfile; \
    test -d doxydoc/html/images || mkdir doxydoc/html/images; \
    cp documentation/images/* doxydoc/html/images
dox.depends =

...
# somewhere else in the *.pro file
QMAKE_EXTRA_UNIX_TARGETS += dox

这可以是解决方案吗?

What about the undocumented options mentioned here http://paulf.free.fr/undocumented_qmake.html
Under Adding a doxygen target the following can be found:

# custom target 'doc' in *.pro file
dox.target = doc
dox.commands = doxygen Doxyfile; \
    test -d doxydoc/html/images || mkdir doxydoc/html/images; \
    cp documentation/images/* doxydoc/html/images
dox.depends =

...
# somewhere else in the *.pro file
QMAKE_EXTRA_UNIX_TARGETS += dox

Could this be a solution ?

乙白 2024-10-01 18:10:48

这篇 Qt 博客文章回答了QMAKE_EXTRA_COMPILERS 和 QMAKE_EXTRA_TARGETS 的问题非常明确。

很快我们就会了解 QBS.. 来自 Digia 和 Qt 的新 Qt 构建套件社区..希望它经过深思熟虑(并且就此而言,有充分的记录)。

This Qt blog post answers the question of QMAKE_EXTRA_COMPILERS and QMAKE_EXTRA_TARGETS quite definitively.

Very soon we will be introduced to QBS.. the new Qt Build Suite coming from Digia and the Qt community.. hopefully it is being really well thought out (and well documented, for that matter).

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