Domanda

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?

È stato utile?

Soluzione

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)

Altri suggerimenti

I am sure, that the currently accepted answer from 2013 was valid for the time being. However, it did not work well for me with all the slashes and dots and colons in the $${path}. Also we have to put $$list() around a list of files nowadays to use it in a for loop.

Here is the approach I came up with. I wrote that in a *.pri file and added it to my directory structure. No need for the extra INSTALL_HEADERS variable:

for(header, $$list($$HEADERS)) {
  path = $$OUT_PWD/../include/$$dirname(header)
  pathname = $$replace(path,/,)
  pathname = $$replace(pathname,\.,)
  pathname = $$replace(pathname,:,)
  file = headers_$${pathname}
  eval($${file}.files += $$header)
  eval($${file}.path = $$path)
  INSTALLS *= $${file}
}

Note that the replacement characters may vary for you. For example, my first approach above had still problems with whitespaces in the path, so I added:

pathname = $$replace(pathname," ",)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top