Search code examples
qtqmakenmake

configure qmake for install headers to different subfolders


I have project where header files are in different subfolders (/config/.h; /thread/.h etc) in qt project file they are included like:

HEADERS += $$PWD/src/*.h
HEADERS += $$PWD/src/config/*.h

then install is described as simple:

headers.files = $$HEADERS
headers.path  = $$INSTALL_INC_DIR/proj

some other projects that use this lib will include files from that install dir and there problem occurs - all .h files are copied to same folder, without subfolders and in code they are included with subfolders (#include <proj/config/config.h>).

Is it possible to tell qmake (or actually nmake) that when copying files keep original folder stucture?


Solution

  • This works for me:

    headerinstall.pri:

    for(header, INSTALL_HEADERS) {
      path = $${INSTALL_PREFIX}/$${dirname(header)}
      eval(headers_$${path}.files += $$header)
      eval(headers_$${path}.path = $$path)
      eval(INSTALLS *= headers_$${path})
    }
    

    at the end of your .pro file:

    INSTALL_PREFIX = /tmp/installprefix
    INSTALL_HEADERS = $$HEADERS
    include(headerinstall.pri)