3
votes

I have a qtcreator project with subfolder template. The folders looks like this:

mainProject/
   mainProject.pro
   staticLib/
      (bunch of .cpp and .h files)
      staticLib.pro
   testApp/
      main.cpp
      testApp.pro

And the mainProject.pro file:

TEMPLATE = subdirs
CONFIG += ordered

SUBDIRS = staticLib \
          testApp

testApp.depends = staticLib

I would like to install the static library so I added the install option in the staticLib.pro file:

headersDataFiles.path = $$LIBPATH/include
headersDataFiles.files = $$PWD/*.h
INSTALLS += headersDataFiles

libraryFiles.path = $$LIBPATH/lib
Debug:libraryFiles.files = $$OUT_PWD/debug/*.a
Release:libraryFiles.files = $$OUT_PWD/release/*.a
INSTALLS += libraryFiles

The problem is when I build the project in Qtcreator, it builds the static lib and then the application without running make install first, so the build for the app fails. And Qtcreator only lets me add build steps after qmake_all (which build both projects without installing the lib first).

So the question is, is there any way I could build staticLib project, install it and then build testApp?

EDIT: The testApp project can always be linked to the library from the output directory of the first project. But I would like to move the .a and headers files to other folder to keep the project organized. The testApp building failure it's not the problem. Sorry for the misunderstood.

2
Install is not reqired afaik to compile something with static libs in dependency. It looks like misconfiguration in you testApp.pro - could you please share it also? Did you tried to add static lib to testApp via Qt Creator? - Mikhail Churbanov
Yes you are right, install it's not requiered. Actually it's not an install in the system what i want to do, just move the generated .a and headers to other folders in the project to keep my project organized. Thank for your comment and sorry for the misunderstood, i edited the question. - Seba Arriagada

2 Answers

1
votes

I don't like the idea of adding steps in Qt creator (if it's no the only way, of course) as they are not persistent over different dev environments AFAIK. For example, you will need to add this step in Qt Creator each time you download/clone code from repository on another machine.

The way we've done it on Windows (however, it should work for other platforms also) is via the QMAKE_POST_LINK and $$QMAKE_COPY (pre-define qmake cross-platform copy command):

FILES_TO_COPY = $$DESTDIR/staticLib.a <path to your header1> <path to your header2>

or if you prefer:

FILES_TO_COPY = $$DESTDIR/staticLib.a
FILES_TO_COPY += <path to your header1>
FILES_TO_COPY += <path to your header2>

You can use vars like $$PWD, to not hardcode full path to headers, and then

DESTINATION_DIR = $$shell_quote($$shell_path("/put/it/here/"))
for (FILE, FILES_TO_COPY)
{
    FILE_PATH = $$shell_quote($$shell_path($$FILE))
    QMAKE_POST_LINK += $$QMAKE_COPY $$FILE_PATH $$DESTINATION_DIR $$escape_expand(\\n)
}

UPD: If you have all needed headers in one directory, you can use QMAKE_COPY_DIR instead of QMAKE_COPY.

Also, if you plan to build it on one specific platform, you could omit the $$shel_quote/$$shell_path and just write the correct paths.

1
votes

Or if install is what you want, you can just add

QMAKE_POST_LINK=$(MAKE) install

to your .pro file