Qmake in release and debug mode - qt

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).

Related

Why lupdate not include qml qstr string into .ts file?

I have this .pro file :
TEMPLATE = subdirs
SUBDIRS += internal app
app.depends = internal
app.subdir = src/app
internal.subdir = src/internal
TRANSLATIONS = \
$$PWD/translations/croatian.ts \
$$PWD/translations/danish.ts \
$$PWD/translations/english.ts \
$$PWD/translations/french.ts \
$$PWD/translations/german.ts \
$$PWD/translations/italian.ts \
$$PWD/translations/norwegian.ts \
$$PWD/translations/portuguese.ts \
$$PWD/translations/romanian.ts \
$$PWD/translations/spanish.ts
internal.pro is this:
TEMPLATE = lib
TARGET = internal
CONFIG += c++1z
QT += core core-private gui quick serialport sql multimedia
DEFINES += CURRENT_PATH=\\\"$$PWD\\\"
CONFIG(release, debug|release) {
CONFIG += qtquickcompiler
QMAKE_CXXFLAGS += -O3
}
CONFIG(debug, debug|release) {
QMAKE_CXXFLAGS += -O0
QMAKE_CXXFLAGS -= -O1
QMAKE_CXXFLAGS -= -O2
QMAKE_CXXFLAGS -= -O3
QMAKE_CXXFLAGS += --debug
}
#MS_SKELETON_MODULES = core utils network
#include($$PWD/../external/ms-skeleton/ms-skeleton.pri)
include($$PWD/aggiornamento/aggiornamento.pri)
include($$PWD/allarmi/allarmi.pri)
include($$PWD/comunicazione/comunicazione.pri)
include($$PWD/core/core.pri)
include($$PWD/jsoncpp/jsoncpp.pri)
include($$PWD/mqtt/mqtt.pri)
include($$PWD/other/other.pri)
include($$PWD/parametri/parametri.pri)
include($$PWD/programs/programs.pri)
include($$PWD/serializer/serializer.pri)
unix: target.path = /opt/Tagliavini/lib
!isEmpty(target.path): INSTALLS += target
and app.pro is this :
TEMPLATE = app
TARGET = UserInterface
CONFIG += c++1z
QT += core gui quick sql multimedia
DEFINES += CURRENT_PATH=\\\"$$PWD\\\"
CONFIG(release, debug|release) {
CONFIG += qtquickcompiler
QMAKE_CXXFLAGS += -O3
}
CONFIG(debug, debug|release) {
QMAKE_CXXFLAGS += -O0
QMAKE_CXXFLAGS -= -O1
QMAKE_CXXFLAGS -= -O2
QMAKE_CXXFLAGS -= -O3
QMAKE_CXXFLAGS += --debug
}
LIBS += -L$$shadowed($$PWD)/../internal/ -linternal
INCLUDEPATH += \
$$PWD/../internal \
$$PWD/../external/ms-skeleton
SOURCES += $$PWD/main.cpp
RESOURCES += \
$$PWD/../../font/fonts.qrc \
$$PWD/../../images/images.qrc \
$$PWD/qml/qml.qrc \
$$PWD/../../sounds/sounds.qrc
unix: target.path = /opt/Tagliavini/bin
!isEmpty(target.path): INSTALLS += target
when i try to create file .ts with lupdate , the files are generated correctly , but the file .ts not cointeins the qstr strings that are into qml files. ( the file qml are into app.pro ), instead the string that i want to translate into .cpp files are all recognized correctly and put into .ts file.(these are into internal.pro) Where is the problem??
It seems that you are including your .qml files in .qrc resources but not in the project SOURCES itself. lupdate will not pick/parse your .qrc files to list .qml files.
So, you will have to add your .qml files to SOURCES either one-by-one or per directory.
lupdate_only{
SOURCES+=example.qml
SOURCES+=app/FancyControls/*.qml
}
This will duplicate your QML file entries in Qt Creator project pane tree which is not very desirable. So, you can comment out those lines in your .pro file and uncomment it before any lupdate. It's also mandatory to fence those imports in lupdate_only{} conditional statement. Make sure that there is no space between lupdate_only and the curly bracket. Actually, your C/C++ compiler would not expect a qml file to be compiled.

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
}

qmake CONFIG constains release and debug variable at the same time

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}
}

Compiling qt project with use of ffmpeg on x64 system

I have a qt project that uses some ffmpeg functionality, that i have compiled previously on windows (x86) and ubuntu. However, its x86 binaries do not work correctly on x64 windows machine. I have tried compiling it but have run into a strange problem.
All ffmpeg functions i use are listed as unresolved exgternals; and the most pecicular thing is, their names all ahve a leading underscore attached to them (so, avformat_close_input -> _avformat_close_input etc). To be sure, i have downloaded latest ffmpeg libraries for x64 machines and run them through a dependency walker - no leading underscores anywhere.
How to fix this problem?
Here is my .pro file:
#-------------------------------------------------
#
# Project created by QtCreator 2013-05-17T10:55:01
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = LPR_Demo
TEMPLATE = app
# The application version
VERSION = 1.0
# Define the preprocessor macro to get the application version in our application.
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
SOURCES += main.cpp\
mainwindow.cpp \
imgProcessor.cpp \
qpicturelabel.cpp \
aboutdialog.cpp \
state.cpp \
qt_videoreader.cpp \
roidialog.cpp \
recognitionresult.cpp \
ffmpeg_reader.cpp \
label_videoplayer.cpp
HEADERS += mainwindow.h \
imgProcessor.h \
qpicturelabel.h \
aboutdialog.h \
state.h \
qt_videoreader.h \
roidialog.h \
recognitionresult.h \
global.h \
ffmpeg_reader.h \
label_videoplayer.h
FORMS += mainwindow.ui \
aboutdialog.ui \
roidialog.ui
LPRDIR = $$PWD/LPR
win32: LIBS += -L$$LPRDIR/bin/ -lliblpr
unix:LIBS += -L$$LPRDIR/bin -lLPR
INCLUDEPATH += $$LPRDIR/include
DEPENDPATH += $$LPRDIR/include
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
#OTHER_FILES += \
# ffmpeg.pri
include(ffmpeg.pri)
#LIBS += -lavformat -lavcodec -lavutil -lswscale
RESOURCES += \
lpr_Res.qrc
win32 {
dlls_to_move.path += $$OUT_PWD/bin
dlls_to_move.files += $$LPRDIR/bin/liblpr.dll
QTDIR=C:/Qt/4.8.4/
CONFIG (debug, debug|release) {
dlls_to_move.files += $$QTDIR/bin/QtCored4.dll \
$$QTDIR/bin/QtGuid4.dll
}
CONFIG (release, debug|release) {
dlls_to_move.files += $$QTDIR/bin/QtCore4.dll \
$$QTDIR/bin/QtGui4.dll
}
img_format.path += $$OUT_PWD/bin/imageformats
CONFIG (debug, debug|release) {
img_format.files += $$QTDIR/plugins/imageformats/qgifd4.dll \
$$QTDIR/plugins/imageformats/qicod4.dll \
$$QTDIR/plugins/imageformats/qjpegd4.dll \
$$QTDIR/plugins/imageformats/qmngd4.dll \
$$QTDIR/plugins/imageformats/qsvgd4.dll \
$$QTDIR/plugins/imageformats/qtgad4.dll \
$$QTDIR/plugins/imageformats/qtiffd4.dll
}
CONFIG (release, debug|release) {
img_format.files += $$QTDIR/plugins/imageformats/qgif4.dll \
$$QTDIR/plugins/imageformats/qico4.dll \
$$QTDIR/plugins/imageformats/qjpeg4.dll \
$$QTDIR/plugins/imageformats/qmng4.dll \
$$QTDIR/plugins/imageformats/qsvg4.dll \
$$QTDIR/plugins/imageformats/qtga4.dll \
$$QTDIR/plugins/imageformats/qtiff4.dll
}
ffmpeg_dll.path += $$OUT_PWD/bin
ffmpeg_dll.files += $$FFMPEG_LIBRARY_PATH/avutil-*.dll \
$$FFMPEG_LIBRARY_PATH/avcodec-*.dll \
$$FFMPEG_LIBRARY_PATH/avformat-*.dll \
$$FFMPEG_LIBRARY_PATH/swscale-*.dll
main_exe.path += $$OUT_PWD/bin
CONFIG (debug, debug|release) {
main_exe.files += $$OUT_PWD/debug/LPR_Demo.exe
}
CONFIG (release, debug|release) {
main_exe.files += $$OUT_PWD/release/LPR_Demo.exe
}
INSTALLS += dlls_to_move img_format ffmpeg_dll main_exe
}
unix {
CONFIG (release, debug|release) {
QMAKE_PRE_LINK += rm LPR_Demo_cmpr LPR_Demo$$escape_expand(\n\t)
QMAKE_POST_LINK += upx -9 -oLPR_Demo_cmpr LPR_Demo$$escape_expand(\n\t)
QMAKE_POST_LINK += cp -v -u LPR_Demo_cmpr $$OUT_PWD/../artifacts/examples/qt_demo/bin/unix
}
}
and here is pri file for ffmpeg:
# Include the configuration file below in the QT .pro file, and modify the path accordingly.
# ##############################################################################
# ##############################################################################
# FFMPEG: START OF CONFIGURATION BELOW ->
# Copy these lines into your own project
# Make sure to set the path variables for:
# 1) ffmpeg_reader,
# 2) FFMPEG include path (i.e. where the directories libavcodec, libavutil, etc. lie),
# 3) the binary FFMPEG libraries (that must be compiled separately).
# Under Linux path 2 and 3 may not need to be set as these are usually in the standard include and lib path.
# Under Windows, path 2 and 3 must be set to the location where you placed the FFMPEG includes and compiled binaries
# Note that the FFMPEG dynamic librairies (i.e. the .dll files) must be in the PATH
# ##############################################################################
# ##############################################################################
# ##############################################################################
# Modify here: set FFMPEG_LIBRARY_PATH and FFMPEG_INCLUDE_PATH
# ##############################################################################
# Set FFMPEG_LIBRARY_PATH to point to the directory containing the FFmpeg import libraries (if needed - typically for Windows), i.e. the dll.a files
win32:FFMPEG_LIBRARY_PATH = $$PWD/ffmpeg/lib
unix: FFMPEG_LIBRARY_PATH = /usr/local/lib
# Set FFMPEG_INCLUDE_PATH to point to the directory containing the FFMPEG includes (if needed - typically for Windows)
win32:FFMPEG_INCLUDE_PATH = $$PWD/ffmpeg/include
unix:FFMPEG_INCLUDE_PATH = /usr/local/include
# ##############################################################################
# Do not modify: FFMPEG default settings
# ##############################################################################
# Set list of required FFmpeg libraries
#unix:LIBS += -L$$FFMPEG_LIBRARY_PATH
unix:LIBS += -lavformat -lavcodec -lavutil -lswscale
# Add the path
win32:LIBS += -L$$FFMPEG_LIBRARY_PATH
win32:LIBS += -lavformat -lavcodec -lavutil -lswscale
INCLUDEPATH += $$FFMPEG_INCLUDE_PATH
# Requied for some C99 defines
DEFINES += __STDC_CONSTANT_MACROS
# ##############################################################################
# FFMPEG: END OF CONFIGURATION
# ##############################################################################

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!
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.

Resources