How to call make install for one subdirectory of a Qt project

I am working on a custom library, and I want users to just be able to use it by adding:

CONFIG += mylib 

to their pro files. This can be done by setting the file mylib.prf to% QTDIR% / mkspec / features. I checked Qt Mobility on how to create and install such a file, but there is one thing I would like to do differently.

If I correctly understood the pro / pri Qt Mobility files, in the sample projects they really do not use CONFIG + = mobility, instead they add QtMobility sources to include the path and share the * .obj directory with the main library project. For my library, I would like have examples that are as independent projects as possible, i.e. Projects that can be compiled from anywhere after compiling and installing MyLib.

I have the following directory structure:

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

It seems that the easiest way to achieve what I described above is to create mylib.pro as follows:

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

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

Of course, any other suggestions for automatically deploying libraries before compiling the examples are welcome.

+4
source share
1 answer

You can make another target and add it to the SUBDIRS variable, which works well if you understand that simple .pro files can also be targeted. 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 that the subdir’s goals will be executed in order by adding the configuration configuration. I moved the tests to compile to installation, which makes sense to me - you want to check if the code works before you go ahead and install it. An important addition is a direct link to the install.pro file inside the source directory. (You can also put this in a local directory if you want to save the src cleaner.) In this case, you should have your commands to install the components that you want to install.

In such situations, I often find that a list of sources and headers is highlighted in a file that can be included in several .pro files, as such:

SIC / sources.pri:

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

SIC / src.pro

 include(sources.pri) #... 

CSI / install.pro

 include(sources.pri) #... 
+1
source

Source: https://habr.com/ru/post/1309697/


All Articles