3

Here are the lines I added in my .pro to set a custom build dir.

BASEPATH = ../some/path/
CONFIG(debug, debug|release) {
    BUILDDIR = $${BASEPATH}/debug
} else {
    BUILDDIR = $${BASEPATH}/release
}
OBJECTS_DIR = $${BUILDDIR}/obj
MOC_DIR = $${BUILDDIR}/moc
RCC_DIR = $${BUILDDIR}/rcc
UI_DIR = $${BUILDDIR}/ui
MAKEFILE = $${BUILDDIR}/Makefile

However, it fails with the error :

error : No rule to make target `../project/project.pro', needed by `Makefile'.  Stop.

It works well if I remove the MAKEFILE=... line but I don't want the Makefile to be output in the same dir than the source files.

So am I looking for some impossible thing or is MAKEFILE the wrong variable to edit ? Thanks.

Jean-Michaël Celerier
  • 7,412
  • 3
  • 54
  • 75

3 Answers3

0

You can separate them by adding source files to a separate src folder. This Question may help you too:-

How to specify different Debug/Release output directories in QMake .pro file

Community
  • 1
  • 1
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
0

Have you heard of shadow build?

Shadow building means building a project in a separate directory, the build directory. The build directory is different from the source directory. One of the benefits of shadow building is that it keeps your source directory clean, which makes it faster to switch between build configurations. Therefore, shadow building is the best practice if you need many build configurations for a single set of source files.

If you are building your projects with Qt Creator then see its manual: Editing Build Configurations. However if you are building it on the command line then see this question and answer on SO: Manually configuring shadow build in qmake

Community
  • 1
  • 1
Bill
  • 11,595
  • 6
  • 44
  • 52
  • Yes, usually I shadow build, but I explicitely wanted to specify it in the .pro, and not in the .pro.user, so that for everybody the build directory will be the same, regardless of configuration, etc... – Jean-Michaël Celerier Jul 30 '13 at 06:40
  • In this case I'm afraid I can not help you. I've read the documentation of the MAKEFILE variable and tried your .pro file in various ways and found that what you are trying to do does not seem to be supported: MAKEFILE specifies the **name** of the Makefile, that is, only the name and not its path: `MAKEFILE: This variable specifies the name of the Makefile which qmake should use when outputting the dependency information for building a project. The value of this variable is typically handled by qmake or qmake.conf and rarely needs to be modified.` – Bill Jul 30 '13 at 06:48
  • Eek ok, I had read it but I hadn't understood it like that. Anyway, I'll accept your answer because shadow build is an answer to my question in the way I formulated it. – Jean-Michaël Celerier Jul 30 '13 at 06:54
0

Works fine for me. That is .pro file:

linux-g++-64: {
BPATH_ = ../BUILD_DIR
OBJECTS_DIR = $${BPATH_}
MOC_DIR = $${BPATH_}
RCC_DIR = $${BPATH_}
UI_DIR = $${BPATH_}
MAKEFILE = $${BPATH_}/Makefile
TARGET =  $${BPATH_}/$${TARGET}
message(Code only for Linux! TARGET = $${TARGET})
}

Run the following command from the source folder:

make -f ../BUILD_DIR/Makefile