Qt project include subprojects build in qmake

微笑、不失礼 提交于 2021-02-19 08:18:13

问题


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.

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.

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).

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

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

UPDATE:

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

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

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


回答1:


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:

In my .pro file:

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

QMAKE_EXTRA_TARGETS += subproject
PRE_TARGETDEPS += subproject

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.




回答2:


If the subproject was normal C/C++ project which Qmake could build it, you can create a pri file for subproject and include it in your main project, but your subproject written in Go and i'am not sure it could be built via Qmake or not.

But you can use QMake variables like QMAKE_PRE_LINK. you have to create a bash script which goes to subproject source directory, configures it and making it. now you can use QMAKE_PRE_LINK to instruct qmake run commands pointed by this variable before starting linking.

Put it in your pro file

QMAKE_PRE_LINK=$$PWD/buildSubproject.sh



来源:https://stackoverflow.com/questions/41244808/qt-project-include-subprojects-build-in-qmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!