0

I am creating large project in Qt. I created sub projects there. My problem is build destination. I will simplify my problem like this:
I have to build library and binary file. My library has following Qt project settings:

TARGET = MyLib
CONFIG(debug, debug|release) {
    TARGET.path = $$OUT_PWD/MyProject/debug
} else {
    TARGET.path = $$OUT_PWD/MyProject/release
}
INSTALLS += TARGET
#DESTDIR += TARGET
TEMPLATE = lib

My executable binary has following Qt project settings:

TARGET = MyExecutable
CONFIG(debug, debug|release) {
    TARGET.path = $$OUT_PWD/MyProject/debug
} else {
    TARGET.path = $$OUT_PWD/MyProject/release
}
INSTALLS += TARGET
#DESTDIR += TARGET
TEMPLATE = app
LIBS += -L$$OUT_PWD/MyProject/... -lMyLib (row is different, but it is not important now)

Compiler VS2017 with these settings creates output in:

$$OUT_PWD/MyLib/debug/MyLib.dll
$$OUT_PWD/MyLib/release/MyLib.dll
$$OUT_PWD/MyExecutable/debug/MyExecutable.exe
$$OUT_PWD/MyExecutable/release/MyExecutable.exe

I want to have output like:

$$OUT_PWD/MyProject/debug/MyLib.dll
$$OUT_PWD/MyProject/release/MyLib.dll
$$OUT_PWD/MyProject/debug/MyExecutable.exe
$$OUT_PWD/MyProject/release/MyExecutable.exe

The reason why I want to have output like that, I want to debug library jumping from executable file. MyExecutable.exe cannot be executed now, because it does not have MyLib.dll in proper path. If I will put to both projects:

DESTDIR += TARGET

Folders named "TARGET" will be created like:

$$OUT_PWD/MyExecutable/TARGET/MyExecutable.exe
$$OUT_PWD/MyLib/TARGET/MyLib.dll

I am doing testing solution for Windows now, but in the future the project supposed to be multi platform. I think I am too old for computer programming...

  • Define the destination path environment variable at the root and use it: https://stackoverflow.com/questions/7754218/qmake-how-to-add-and-use-a-variable-into-the-pro-file Mind the scope depending on syntax. I guess you should better choose one that is available during QMake phase but then every nested .pro file should assign it to local variable. It feels more compatible with VS which uses qmake product. – Alexander V Apr 22 '18 at 05:55
  • What you've specified is not the build destination, but install destination. After the default build, you have to build the `install` target as well. – Kuba hasn't forgotten Monica Apr 22 '18 at 05:56

1 Answers1

1

Thanks Guys, this is my final (Windows) solution of the problem for all sub projects:

CONFIG(debug, debug|release) {
    DESTDIR += $$OUT_PWD/../MyProject/debug
    TARGET.path = $$OUT_PWD/../MyProject/debug
    LIBS += -L$$OUT_PWD/../MyProject/debug
} else {
    DESTDIR += $$OUT_PWD/../MyProject/release
    TARGET.path = $$OUT_PWD/../MyProject/release
    LIBS += -L$$OUT_PWD/../MyProject/release
}
INSTALLS += TARGET
#LIBS += -lMyLib
message(The $$TEMPLATE $$TARGET will be installed in $$DESTDIR)