开发者

How to invoke make install for one subdirectory of Qt project

I'm working on custom library and I wish users could just use it by adding:

CONFIG += mylib

to their pro files. This can be done by installing mylib.prf file to %QTDIR%/mkspec/features. I've checked out in Qt Mobility project how to create and install such file, but there is one thing I'd like to do differently.

If I correctly understood the pro/pri files of Qt Mobility, inside the example projects they don't really use CONFIG += mobility, instead they add QtMobility sources to include path and share the *.obj directory with main library project. For my library I'd like to have examples that are as independent projects as possible, i开发者_如何学运维.e. projects that can be compiled from anywhere once MyLib is compiled and installed.

I have following directory structure:

mylib
  |
  |- examples
  |- src
  |- tests
  \- mylib.pro

It seems that the easiest way to achieve what I described above is creating mylib.pro like this:

TEMPLATE = subdirs
SUBDIRS += src
SUBDIRS += examples
tests:SUBDIRS += tests

And somehow enforce invoking "cd src && make install" after building src. What is the best way to do this?

Of course any other suggestions for automatic library deployment before examples compilation are welcome.


You could make another target and add it to the SUBDIRS variable, which works well if you realize that plain .pro files can also be a target. I would suggest something like this

TEMPLATE = subdirs
CONFIG += ordered

SUBDIRS += src
tests:SUBDIRS += tests
SUBDIRS += src/install.pro
SUBDIRS += examples

In this case, I made sure the subdir targets would be executed in order, via the config variable addition. I moved the tests compile to before the install, which makes sense to me -- you'd want to test that the code is working before going ahead and installing it. The important addition is the direct link to an install.pro file inside your source directory. (You could place this in the local directory also, if you want to keep src cleaner.) In that, you should have your commands to install the components you want installed.

In situations like this, I find it often helps to have the list of sources and headers separated out in a file that could be included in multiple .pro files, as such:

src/sources.pri:

HEADERS += foo.h
SOURCES += foo.c

src/src.pro

include(sources.pri)
#...

src/install.pro

include(sources.pri)
#...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜