14

Absolute paths are ridiculous. All we need - and all we are allowed, by the way - is to use a folder on the same level that the folder containing .pro file for shadow builds. There are bugs otherwise.

But you can't just specify ../mingw_debug for example. Yes, it is a relative path but relative to what? It turns out it is relative to current directory of Qt Creator, and this is completely meaningless.

%{sourceDir} is of no help either. %{sourceDir}/../mingw_debug dosen't work, at least on Windows. If there was a way to extract parent folder from sourceDir!

Does anybody know a way to solve the issue?

Sergey Skoblikov
  • 5,811
  • 6
  • 40
  • 49

4 Answers4

2

In Qt Creator 3.6.1 at least, this is fixed - relative paths work just fine. The resolved full path is shown in the tooltip. I don't know when in the past few years this was fixed.

James Turner
  • 2,425
  • 2
  • 19
  • 24
0

Not exactly shadow builds as qt-creator defines them but I am using the following to get a neat build structure.

Excerpt from a pro-file for a library that I build for multiple targets and also in test modes.

TARGET = ../lib/common
message("libcommon:")

contains(CONFIG,test){
  message("Building Test")
  DESTDIR = test
  TARGET = $$TARGET-test
}else{
  message("Building Program")
  DESTDIR = program
  TARGET = $$TARGET
}

contains(MEEGO_EDITION,harmattan){
  message("Maemo Harmattan")
  DESTDIR = $$DESTDIR-maemo6
  TARGET = $$TARGET-maemo6
  DEFINES += MAEMO MAEMO6
}
unix:!maemo5:!contains(MEEGO_EDITION,harmattan){#desktop
  message("Desktop")
  DESTDIR = $$DESTDIR-desktop
  TARGET = $$TARGET-desktop
}

contains(CONFIG,test){
  TEMPLATE = app
  SOURCES += $$files(src_test/main.cpp)
  HEADERS += $$files(src_test/*.h)
  INCLUDEPATH += src_test
}else{
  TEMPLATE = lib
  CONFIG += staticlib
}

CONFIG(debug, debug|release) {
  message("Debug")
  DESTDIR = $$DESTDIR-debug
  CONFIG += debug
  DEFINES += DEBUG
  TARGET = $$TARGET-debug
}else{
  message("Release")  
  //DEFINES += QT_NO_DEBUG_OUTPUT
  DESTDIR = $$DESTDIR-release
  TARGET = $$TARGET-release
}
MOC_DIR = build/$${DESTDIR}/moc
OBJECTS_DIR = build/$${DESTDIR}/obj
UI_DIR = build/$${DESTDIR}/ui

So you get all your object,moc,gui files in separate directories (e.g libcommon/build/program-desktop-debug/moc) and your binaries in the same with different names. To trigger one build or another you simply set a CONFIG+= in the build target. And the best about it this structure only depends on the pro file and you can put parts of it in a common.pri and use it for all your projects. No need for shadow-build configuration anymore. By the way the pro file resides in libcommon/libcommon.pro as it should.

Martin
  • 4,738
  • 4
  • 28
  • 57
  • It's nice, but the answer is a complete off-topic. It's not about shadow builds or Qt Creator either. – Sergey Skoblikov Aug 11 '12 at 09:49
  • I don't think so. What do you need shadow builds for ? You want to build for several architectures in a managed way without deleting built files when compiling another target. Qt fails here due to the build directory restriction but you can use the code above to get exactly the desired functionality with relative paths. Thus this is a working replacement for Qts shadow builds. – Martin Aug 12 '12 at 12:24
  • It is not. Makefile and some others will be always created in current dir which is often project dir. So this is just partially working shadow builds replacement. And, Qt doesn't have shadow builds at all. Qt Creator has. And qusestion was about Qt Creator settings. – Sergey Skoblikov Aug 23 '12 at 20:52
  • The fact that sources are in subfolders doesn't change the fact. The project file IS part of sources, and there will be garbage right beside it. And sources in subfolders in such way that you propose will be displayed ugly in Qt Creator interface - with src_test/ prefix. – Sergey Skoblikov Aug 23 '12 at 20:56
  • True enough about the source display. I used the simplified view most of the times. For the make files you are right as well, they remain in the same directory as the project file, but honestly I spent a lot of time wondering how to get an alomst clean build environment with an alomst clean directory structure and this is the best solution I found. If you find something better that works wit qt-creator please tell me – Martin Aug 23 '12 at 21:02
  • Qt Creator shadow builds works and get you clean sources. But there is a small glitch my question is about - you have to use absloute paths for shadow builds to work. – Sergey Skoblikov Sep 09 '12 at 13:34
0

I'm using this code in *.pro file, it seems working fine.

CONFIG(debug, debug|release){
    DESTDIR=$$shadowed($$ROOT_PWD)/debug
}else{
    DESTDIR=$$shadowed($$ROOT_PWD)/release
}
Zac
  • 1
  • 1
-1

There are several things that can be used to make this manageable:

$$_PRO_FILE_PWD_ (version >=4.5) variable contains the directory of the current pro file being read.

Use the .qmake.cache file in the root directory of the project, and define a variable for the directory:

PROJECT_DIR = $$PWD

Then use that to navigate around beginning from the root.

Tatu Lahtela
  • 4,514
  • 30
  • 29
  • 1
    How is it realted to Qt Creator? Do you propose to drop Qt creator shadow build feature and emulate it? If so, from your answer it is completely unclear how to do it. – Sergey Skoblikov Sep 22 '12 at 17:50
  • Qt creator or shadow building specifically - not much. But these issues with relative paths are common for all projects that use qmake, and I pointed out the common ways to work around these things. – Tatu Lahtela Sep 24 '12 at 06:34
  • 1
    Does not answer the question. So annoying! – Mr. Developerdude Mar 13 '16 at 12:57