Installing Library Header Files with QMake

The problem

Since most of my projects are platform independent I like to organise them like Unix libraries. Unix libraries typically have the following directory structure:

./        Makefile(s)
./src     Source files and private header files
./include Public header files (that are to be installed)
./lib     Library build directory

The header files of the library should be installed into their own subdirectory of the common include directory. The code that uses the library can include the headers this way:

#include <mylibrary/myheader.h>

Copying the header files can be achieved in Visual Studio by adding a custom build step. The custom build steps allow the developer to customize the build process. But what about QT?

The solution

QMake supports an install set. This variable contains a list of resources that will be installed when make install is executed.
In order to install the header files you need to do the following:

  1. Edit your qmake project file:
    headers.path    = commondir/yourlib
    headers.files   += $$HEADERS
    INSTALLS       += headers
    

    This will copy all the header files to the folder, specified in headers.path. If you want to copy some of the files, you can specify them in the headers.files section.

  2. If you use QT Creator, you should add a build step that invokes make install as shown on the picture:
You can leave a response, or trackback from your own site.

Leave a Reply