Search code examples
qtcross-platformqmake

How to change Debug/Release output dir using qmake .pro file. Cross-plataform


I've read all post about it and none of solutions works in windows and linux. My current solution works pretty well in Windows, creating, if doesn't exist, the respective directory for debug or release.

I want to create all my object files (*.o) inside one of these folders. In windows I achieved this in linux my DESTDIR variable is empty. =|

TEMPLATE = app
TARGET = 
DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += Config.h \
           keyboard.h \
           keyboardgui.h \
           keyboardkey.h \
           Log.h \
           main.h \
           mainwindow.h \
           Settings.h
FORMS += mainwindow.ui
SOURCES += Config.cpp \
           keyboard.cpp \
           keyboardgui.cpp \
           keyboardkey.cpp \
           Log.cpp \
           main.cpp \
           mainwindow.cpp
RESOURCES += Resources.qrc

OTHER_FILES += \
    default_layout.kl


# se for Windows
win32 {
# inclui a lib para acessar o DMI
LIBS += -lqaxcontainer
}

# Habilita a opcao de copia de diretorios
CONFIG += copy_dir_files

Debug:DESTDIR = debug
Release:DESTDIR = release

# copia a pasta configuracao para o diretorio de saida
win32 {
 QMAKE_POST_LINK +=  copy /Y default_layout.kl $$DESTDIR
}
else {
 QMAKE_POST_LINK +=  cp -a default_layout.kl $$DESTDIR 
}

I tried to use the INSTALL var but without success. The debug directory is created and all object files is put there but when I changed the compilation mode to RELEASE the objects files continue to be moved to the debug directory and the RELEASE directory isn't created (I've tried to run qmake again). In both configurations my files (default_layout and layout) aren't copied to the output directory.

# Habilita a opcao de copia de diretorios
CONFIG += copy_dir_files

release:DESTDIR = release
release:OBJECTS_DIR = release/
release:MOC_DIR = release/
release:RCC_DIR = release/
release:UI_DIR = release/

debug:DESTDIR = debug
debug:OBJECTS_DIR = debug/
debug:MOC_DIR = debug/
debug:RCC_DIR = debug/
debug:UI_DIR = debug/

INSTALLS += config_files
config_files.path = $$DESTDIR
config_files.filename = default_layout.kl
config_files.filename += layout.kl

thx!


Solution

  • I think the reason it works on Windows and not on Linux is because you capitalized "Debug" and "Release". The examples I have found all have them as lower case (see second example in this section on the qmake document page.)

    The other thing I question is the use of DESTDIRS. DESTDIRS tells qmake where you want to put the TARGET. If you want to directly control where only the object files are put, you should use OBJECT_DIRS.

    Personally, I use qmake's INSTALLS keyword to do copy extra files where they need to go. It does mean executing both a make and a make install, but it does produce a more platform dependent code.

    If I assume you want the TARGET and the objects in 'debug' or 'release', I would do it like this:

    # Habilita a opcao de copia de diretorios
    debug {
        DESTDIR = debug
        OBJ_DIR = debug
    }
    release
    {
        DESTDIR = release
        OBJ_DIR = release
    }
    
    # copia a pasta configuracao para o diretorio de saida
    config_files.path = $$DESTDIR
    config_files.files = default_layout.kl
    INSTALLS += config_files
    

    If you are running QtCreator, you can add the make install step to the building settings by selecting the "Projects" icon in the left hand tool bar. Next, select "Add Build Step", "Make", and set the "Make arguments" to install. You will have to do this for each build configuration.