qmake CONFIG constains release and debug variable at the same time - qt

I want to change some DEFINES and LIBS paths depending on Debug or Release build configuration, but my CONFIG variable constains release and debug variables at the same time.
Simple test in pro file:
CONFIG(debug, debug|release) {
message(DEBUG build)
}
CONFIG(release, debug|release) {
message(RELEASE build)
}
This test outputs:
Project MESSAGE: DEBUG build
Project MESSAGE: RELEASE build
How should I set up my project?

You should use this:
debug_and_release_target {
CONFIG(debug, debug|release) {
message("debug")
} else {
message("release")
}
}
This is what we use inside Qt as well, including QtSerialPort. Although we use this as well for Mac, just in case:
if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
LIBS += -lQtSerialPort$${QT_LIBINFIX}_debug
} else {
LIBS += -lQtSerialPort$${QT_LIBINFIX}
}

Related

QMake: Get full path of output executable

In my .pro file for QMake I would like to run install_name_tool to replace some library paths. For this I need to determine path to my output executable. Particularly on macx the path to executable looks like this
<build_directory>/<configuration_name>/<target_name>.app/Contents/MacOS/<target_name>
I figured out that
message("build_directory=$${OUT_PWD}")
message("target_name=$${TARGET}")
Is there a QMake variable to populate configuration_name?
By default it is supposed to return "release" for release configurations and "debug" for debug configurations. From what I saw online people just explicitly define $${DESTDIR}
debug { DESTDIR = debug }
release { DESTDIR = release }
debug_and_release { DESTDIR = bin }
if not defined message("DESTDIR=$$DESTDIR") returns empty value for DESTDIR.
This works:
CONFIG(debug, debug|release) {
DEBUG_OR_RELEASE = debug
} else {
DEBUG_OR_RELEASE = release
}
So then the full output path is:
$${OUT_PWD}/$${DEBUG_OR_RELEASE}

how do I create a Qt project option for linux only

I know I can insert this to .pro file
win32 {
LIBS += libbreakpad_client.lib
}
so that the option is only used when building under windows.
How do I do same for linux? I tried both
linux-g++ {
LIBS += libbreakpad_client.a
}
linux {
LIBS += libbreakpad_client.a
}
but it works only in qt5-qmake on qt4 it doesn't work at all...
You can use unix:
unix {
message("Creating Makefile for UNIX ...")
LIBS += libbreakpad_client.a
}

Qt 4.8.4 Creating release

I'm trying to build a release version of a project I'm working on. When building in Qt creator in Debug it works great. When I try building as release I get "cannot find -lQtSerialPort". Qt 4.8.4 does not include QtSerialPort. I had to add that manually. I'm assuming there is something I'm forgetting to include here. Possibly in the .pro file?
Also, I noticed in my Qt/4.8.4/lib directory I have many .prl files. There is one for QtSerialPortd.prl. This is the only one in here that seems to have a .dll version. Not sure if this is significant or not.
Makefile includes this:
Makefile: ???.pro
c:/Qt/4.8.4/mkspecs/features/serialport.prf \
$(QMAKE) -config release -o Makefile ???.pro
c:/Qt/4.8.4/mkspecs/features/serialport.prf:
serialport.prf looks like this:
qtAddLibrary(QtSerialPort)
!isEmpty(QTSERIALPORT_BUILD_ROOT) {
INCLUDEPATH -= $$QMAKE_INCDIR_QT/QtSerialPort
QMAKE_INCDIR += $$QTSERIALPORT_BUILD_ROOT/include $$QTSERIALPORT_BUILD_ROOT/include/QtSerialPort
QTSERIALPORT_BUILD_SUBDIR = src/serialport
debug_and_release_target {
CONFIG(debug, debug|release) {
QTSERIALPORT_BUILD_SUBDIR = $$QTSERIALPORT_BUILD_SUBDIR/debug
} else {
QTSERIALPORT_BUILD_SUBDIR = $$QTSERIALPORT_BUILD_SUBDIR/release
}
}
QMAKE_LIBDIR += $$QTSERIALPORT_BUILD_ROOT/$$QTSERIALPORT_BUILD_SUBDIR
}
mac {
LIBS -= -framework QtSerialPort$${QT_LIBINFIX}
if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
LIBS += -lQtSerialPort$${QT_LIBINFIX}_debug
} else {
LIBS += -lQtSerialPort$${QT_LIBINFIX}
}
}
Edit:
After figuring out I can change the name of the file by removing the d at the end, I realized that all the libraries included on the exe that is built include files that do not end in 'd.dll' with the exception of the QtSerialPortd.dll file.
I.E ldd on the debug .exe:
QtCored4.dll => /cygdrive/c/Qt/4.8.4/bin/QtCored4.dll (0x69cc0000)
QtGuid4.dll => /cygdrive/c/Qt/4.8.4/bin/QtGuid4.dll (0xf30000)
QtNetworkd4.dll => /cygdrive/c/Qt/4.8.4/bin/QtNetworkd4.dll (0x6cb40000)
QtSerialPortd.dll => /cygdrive/c/Qt/4.8.4/bin/QtSerialPortd.dll (0x63680000)
ldd on the release .exe:
QtCore4.dll => /cygdrive/c/Qt/4.8.4/bin/QtCore4.dll (0x6e0c0000)
QtGui4.dll => /cygdrive/c/Qt/4.8.4/bin/QtGui4.dll (0x67700000)
QtNetwork4.dll => /cygdrive/c/Qt/4.8.4/bin/QtNetwork4.dll (0x65c80000)
QtSerialPortd.dll => /cygdrive/c/Qt/4.8.4/bin/QtSerialPortd.dll (0x63680000)
Release vs Debug, it looks like the QtSerialPortd.dll remained the same. I'm guessing this is going to be problematic when I try this application on different machines.
I changed the name of Qt/4.8.4/lib/libQtSerialPortd.a to Qt/4.8.4/lib/libQtSerialPort.a. It builds now. Not sure if this is going to have adverse effects.

Qmake in release and debug mode

I have a library and I would like it to copy itself to a directory depending upon what configuration i'm in (debug or release). Here is my project file.
#-------------------------------------------------
#
# Project created by QtCreator 2011-08-13T12:48:33
#
#-------------------------------------------------
TARGET = JECLibrary
TEMPLATE = lib
DEFINES += JECLIBRARY_LIBRARY
SOURCES += \
JECMessageText.cpp \
JECMessageCombo.cpp \
JECButton.cpp
HEADERS +=\
JECLibrary_global.h \
JECMessageText.h \
JECMessageCombo.h \
JECButton.h
CONFIG(debug, debug|release)
{
DLLDESTDIR += $$quote(../../../Jane/Jane/Build/debug)
message("Copying to Jane Debug Directory.")
}
CONFIG(release, debug|release)
{
DLLDESTDIR += $$quote(../../../Jane/Jane/Build/release)
message("Copying to Jane Release Directory.")
}
FORMS += \
JECMessageText.ui \
JECMessageCombo.ui
For some reason, the debug or release DLL are copied to both directories instead of just one. So if I run in release mode, I get the release DLL in both the Debug directory and release directory.
I'm totally confused. Could someone shed some light on this? Thanks
The opening brace should be on the same line as the condition:
CONFIG(debug, debug|release) {
DLLDESTDIR += $$quote(../../../Jane/Jane/Build/debug)
message("Copying to Jane Debug Directory.")
}
CONFIG(release, debug|release) {
DLLDESTDIR += $$quote(../../../Jane/Jane/Build/release)
message("Copying to Jane Release Directory.")
}
or
CONFIG(debug, debug|release) {
DLLDESTDIR += $$quote(../../../Jane/Jane/Build/debug)
message("Copying to Jane Debug Directory.")
} else {
DLLDESTDIR += $$quote(../../../Jane/Jane/Build/release)
message("Copying to Jane Release Directory.")
}
But both messages will be displayed, because the files Makefile.Debug and Makefile.Release are both created when you run qmake (on Windows, or if you add debug_and_release to the CONFIG variable on other OSes).

How can i add custom build steps in Qt-Creator?

After build my app, i want copy it to specific directory (on Windows 7).
Custom build step
cmd.exe \c \k copy MyPlugin.dll ..\..\..\HostApp\Debug\plugins
But I have error:
Can't run process "cmd.exe \c \k copy MyPlugin.dll ..\..\..\HostApp\Debug\plugins"
That's wrong?
One way to do it would be to change the build output directory in the .pro file.
Something like
CONFIG(debug, debug|release) {
DESTDIR = C:/myApp/debug
} else {
DESTDIR = C:/myApp/release
}
Or in your particular case
CONFIG(debug, debug|release) {
DESTDIR = ..\..\..\HostApp\Debug\plugins
} else {
DESTDIR = ..\..\..\HostApp\Release\plugins
}
Edit:
This question has some good alternatives to my answer.

Resources