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

查看:143
本文介绍了从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.

我尝试过的一件事是在我的pro文件中使用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并没有使make_file中的其他依赖项成为batch_runner.commands的动作.

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天全站免登陆