从 QMake 运行程序/脚本 [英] Running a program/script from QMake

查看:49
本文介绍了从 QMake 运行程序/脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个相当大的代码库.绝大多数代码使用 qmake 编译以生成 makefile.但是,有些子项目是通过运行批处理文件或运行其他程序生成的.

We have a fairly large code-base. The vast majority of the code is compiled using qmake to produce the makefiles. However, there are some sub-projects that get produced by running batch files or running other programs.

我希望能够使用 qmake 编译所有内容,但我不知道如何让 qmake 简单地运行脚本.

I'd like to be able to have everything compiled using qmake, but I can't figure out how to get qmake to simply run a script.

我尝试过的一件事是在我的专业文件中使用 QMAKE_EXTRA_TARGETS,如下所示:

One thing that I've tried is using QMAKE_EXTRA_TARGETS in my pro file, like so:

TEMPLATE = lib
SOURCES = placeholder.cpp
CONFIG += no_link staticlib
batch_runner.target   = placeholder.cpp
batch_runner.commands = my_batch_file.bat
QMAKE_EXTRA_TARGETS   = batch_runner

然后我必须让批处理文件像这样生成 placeholder.cpp:

I then have to have the batch file produce placeholder.cpp like so:

# do the real work here
# ...
# create placeholder.cpp so qmake and nmake are happy
echo // dummy >> placeholder.cpp

这似乎工作正常.问题是它有点虚伪.如果我不指定 batch_runner.target (即我将其留空)或不将 placeholder.cpp 放在 SOURCES 中,则批处理文件永远不会运行.这是因为 qmake 没有使 batch_runner.commands 成为 Makefile 中任何其他依赖项的操作.

This seems to work fine. The trouble is that it is somewhat hokey. If I don't specify batch_runner.target (i.e. I leave it blank) or don't put placeholder.cpp in SOURCES then the batch file never gets run. This is because qmake isn't making batch_runner.commands the action for any other dependency in the Makefile.

有没有更好的方法让 QMake 构建一个 Makefile,以便在 Makefile 执行时运行脚本?

Is there any better way to get QMake to construct a Makefile such that a script is run when the Makefile executes?

推荐答案

看起来 QMAKE_POST_LINK 很适合这类事情.

It looks like QMAKE_POST_LINK works well for this sort of thing.

这似乎完成了工作.my_batch_file.bat 在 nmake 运行时运行(而不是在 qmake 运行时运行),我不需要对占位符目标或文件做任何有趣的事情.

This seems to get the job done. my_batch_file.bat runs when nmake runs (rather than when qmake runs) and I don't need to do anything funny with placeholder targets or files.

很可能我不需要CONFIG"中列出的所有项目.

It's quite likely that I don't need all of the items listed in 'CONFIG'.

TEMPLATE = lib
TARGET   = 
CONFIG  += no_link target_predeps staticlib

QMAKE_POST_LINK  = my_batch_file.bat
QMAKE_CLEAN     += batch_output.obj

这篇关于从 QMake 运行程序/脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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