0

I've a project built with QtCreator. A myapp and a staticlib mylib. Both are handled within a SUBDIRS template project.

TEMPLATE  = subdirs
SUBDIRS = \
        mylib \
        myapp

CONFIG += ordered
CONFIG += qt

 myapp.depends = mylib

myapp is also linked against mylib2, a static-lib built separately outsideof Qt framework.

So, somewhere in myapp.pro I've:

# Paths to PGA libs and contrib
INCLUDEPATH += ./include
INCLUDEPATH += $$PWD/../mylib2/include
...
unix {
    LIBS += "-L$$PWD/../mylib2/lib/" -lmylib2$${DBG}  # DBG=d if debug mode
...
}

That way, everything works fine. I'm happy. But to get it working, I need top ensure myself that mylib2 is already built when I build myapp.

What I wish to achieve, is to make a call to the makefile oy mylib2 when it needs to built. i.e. make -C /path/to/mylib2 -f mylib2.mak

What should I need to add in my .pro file ? Is it related with custom targets ? But how to make a custom target automatically built with the qmake target ?

Z.

Zyend
  • 572
  • 1
  • 4
  • 24
  • Create qmake file for mylib2 add mylib2 as subdir project as well. Provide dependency of mylib from mylib2. Create custom target in lib2: http://stackoverflow.com/questions/3776476/how-to-add-custom-targets-in-a-qmake-generated-makefile – Alexander V Feb 16 '17 at 05:37
  • Alexander, unfortunately I cannot migrate the regular makefiles to qmake project files...for technical reasons. – Zyend Feb 16 '17 at 08:03
  • No. I meant that you will create .pro file that calls GNU make processing makefile. – Alexander V Feb 16 '17 at 15:27

1 Answers1

2

Maybe I misunderstand it, but myapp is dependent on mylib, but you are building myapp first. You forced Qt to build it ordered, but you have myapp at first place.

Try to build mylib first.

CONFIG += ordered
SUBDIRS = \
    mylib \  # must be first
    myapp

Edit: I am compiling libraw in my project like this

This can be in separate file like libraw.pri and you can add it to app project.

Comment: This solution expecting library you are not working on. It wont rebuild upon changes of any file in mylib2 folder. It will be build upon qmake run. Not when building your app project or mylib.

# Build libraw
!exists( $$librawdir/bin/libraw.dll ) {
    system( cd $$librawdir && vcvarsall.bat amd64 && nmake Makefile.msvc )
}

So you version can look like: File name mylib2.pri

!exist ( /path/to/mylib2/bin/mylib2.dll ) { 
    system ( make -C /path/to/mylib2 -f mylib2.mak )
}

Then in your application pro file you should add this file like

include(mylib2.pri)

Or you can add QMAKE_POST_TARGET like this in mylib project which is run before myapp project.

        QMAKE_POST_LINK += make -C /path/to/mylib2 -f mylib2.mak &

This should run make every time mylib target is build.

fbucek
  • 1,647
  • 13
  • 22
  • 1
    I got mine to work with `QMAKE_PRE_LINK` ... also note that the trailing `&` is to indicate an additional command to run. If there is only one command in your QMAKE_PXXX_LINK then you don't need the ampersand. – phyatt May 10 '17 at 20:31