QMake“子目录” 模板 - 执行目标?
我正在使用使用“subdirs”模板的 qmake .pro 文件为我的 Qt 应用程序构建一个构建系统。 这工作得很好,并允许我指定每个目标的构建顺序,因此依赖关系工作得很好。 但是,我现在已经向项目添加了一个工具,该工具生成主应用程序使用的版本号(包含构建日期、SVN 修订版等) - 我可以先构建此版本工具,但构建后我想要在构建更多目标之前执行它(它生成一个包含主应用程序包含的版本号的头文件。)
例如,我的简单 qmake 文件看起来像这样:
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = version \
lib \
tests \
mainapp
当构建“版本”时,我想执行它(在构建“lib”之前在命令行上传递一些参数。
有谁知道这是否可能? 我看到 qmake 有一个可以执行应用程序的“系统”命令,但我不知道如何利用它。
一个相关的问题涉及我的单元测试。 它们位于“测试”项目中并使用 QTest 框架。 我想在构建“mainapp”之前执行测试 exe,如果测试失败(即测试 exe 不返回零),我想退出构建过程。
我意识到 qmake 是设计来生成 makefile 的,所以我可能在这里希望有点太多,但如果有人能给我一些指示,那将非常受欢迎。
I am putting together a build system for my Qt app using a qmake .pro file that uses the 'subdirs' template. This works fine, and allows me to specify the order that each target is built, so dependencies work nicely. However, I have now added a tool to the project that generates a version number (containing the build date, SVN revision, etc,) that is used by the main app - I can build this version tool first but when it is built I want to execute it before any more targets are built (it generates a header file containing the version number that the main app includes.)
For example, my simple qmake file looks like something this:
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = version \
lib \
tests \
mainapp
When 'version' is built I want to execute it (passing some arguments on the command-line) before 'lib' is built.
Does anyone know if this is possible? I see that qmake has a 'system' command that can execute apps, but I don't know how I could leverage this.
A related question concerns my unit tests. These live in the 'test' project and use the QTest framework. I want to execute the tests exe before building 'mainapp' and if the tests fail (i.e. the tests exe doesn't return zero) I want to quit the build process.
I realise that qmake is designed to generate makefiles, so I may be wishing for a little too much here but if anyone can give me some pointers it would be very welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我目前使用 qmake 自动执行我的单元测试两年了 - 而且效果很好。
看看这里 - 我为此制作了一个迷你指南:
Qt:使用 QMAKE 进行自动单元测试
简短摘要:
结构
使用 QMake 在构建上自动运行单元测试的
QMake 目标 QMAKE_POST_LINK 将在链接后运行用户定义的命令。
tests.pri(通用文件)
tests.pro(项目特定文件)
在单个 main() 中运行多个单元测试
main.cpp
这会在每个构建上运行测试,并在发现错误时中止。
注意:
如果出现诸如“LNK2005:xxx 已定义...”之类的链接器错误,请为每个测试类标头添加新的 .cpp 文件并移动一些测试方法实现。
您可以完全使用该机制在编译/构建后执行您的版本控制工具 - 所以您的问题应该得到解决:-)
如果您有任何其他问题,请随时问我。
PS:在这里您可以找到有关 QMake 的更多(未记录的)技巧: 未记录的 QMake
I currently use qmake to exec my unit tests automatically for two years - and it works fine.
Have a look here - I made a mini-howto for that:
Qt: Automated Unit Tests with QMAKE
Abridged summary:
Structure
Using QMake to automatically run unit tests on build
The QMake target QMAKE_POST_LINK will run a user defined command after linking.
tests.pri (common file)
tests.pro (project-specific file)
Running multiple unit tests in a single main()
main.cpp
This runs your tests on each build and aborts if an error is found.
Note
If you get linker errors such as "LNK2005: xxx already defined...", add a new .cpp file for each test class header and move some test method implementations.
You can use exactly that mechanism to exec your versioning tool after compile/building - so your questions should be solved :-)
If you have any further questions don't hesitate to ask me.
PS: Here you can find more (undocumented) tricks around QMake: Undocumented QMake
我在 Qt Interest 邮件列表上发布了一条关于“预构建”步骤的消息,它可以使用 PRE_TARGETDEPS 和 QMAKE_EXTRA_TARGETS 的组合来完成。 这是回应:
我现在使用与此类似的东西在每次构建时生成我的应用程序的版本号。
I posted a message on the Qt Interest mailing list about a 'pre build' step and it can be done using a combination of PRE_TARGETDEPS and QMAKE_EXTRA_TARGETS. Here is the response:
I am now using something similar to this to generate my app's version number each time it is built.
多年来我尝试使用 qmake 作为构建系统做很多事情。 最终我只是采取了 pre-qmake 步骤。 IE。 配置脚本。
您可以在其中构建版本工具,然后在调用 qmake 生成 Makefile 之前执行它。
我发现将数据放入 pro 文件的最简单方法(如果您也需要的话)是生成一个 .pro.inc 文件并从您的主 pro 中包含它。
I've tried to do a lot of stuff with qmake as a build system over the years. Eventually I just resorted to having a pre-qmake step. Ie. a configure script.
You can build your version tool in there and then execute it before calling qmake to generate the Makefiles.
I found the easiest way to get data into the pro files, if you need that too, is to generate a .pro.inc file and include it from your main pro.
正如3DH提到的,你想要一个
QMAKE_POST_LINK
中指定的选项。 pro 文件包含您想要执行的内容。 因此,对于您的示例,我将使用version.pro
文件执行类似的操作:类似的内容应该适用于您的测试目录。
As 3DH mentioned, you want a
QMAKE_POST_LINK
option specified in your .pro files that contain something you want executed. So for your example, I would do something like this with theversion.pro
file:Something similar should work with your test directory.