Best way to make QMake switch INCLUDEPATH on debug/release - qt

I have a Qt project (.pro) which has some dependencies that put the include directory in a "release" or "debug" directory when built. What is the best practice method of "switching" which directories are in the include in debug and release? At the moment I have this in my .pro:
CONFIG(debug, debug|release) {
CONFIGURATION = debug
DESTDIR = $${PWD}/../../Interface/Debug
} else {
CONFIGURATION = release
DESTDIR = $${PWD}/../../Interface/Release
}
GENDIR = $${DESTDIR}/Generated
OBJECTS_DIR = $${GENDIR}/obj
MOC_DIR = $${GENDIR}/moc
RCC_DIR = $${GENDIR}/rcc
UI_DIR = $${GENDIR}/ui
INCLUDEPATH += $(LIBOPC_DIR)/$${CONFIGURATION}/include
However if I import this into VS2012 via the Qt VisualStudio plugin it puts $(LIBOPC_DIR)/debug/include into both the debug and release configurations... am I doing something wrong or is this a limitation of the VS plugin and/or qmake?

Related

QMake subdir Template outputs into the build directory instead of the main directory

I am trying to use qmake's subdirs template. The problem is that the output directory specified in the sub projects is created in the build directory instead of the directory that is being referenced in the projects. other then that everything works normally. I was wondering if there is a way to fix this.
Dir Structure
build-project_dir/
-Apps/ --this gets created
-Other things
project_dir/
-main.pro
-Apps/ -- I want it to use this instead
-Server/
----Server.pro
----some logic files
-Parser/
----Parser.pro
----Parser files
-muparser/
-build/
----muparser.pro
----main.cpp
Main.pro
TEMPLATE = subdirs
# where to find the sub projects - give the folders
Server.subdir = Server
Parser.subdir = Parser
muparser.file = muparser-2.2.5\build\muparser.pro
# what subproject depends on others
Server.depends = Parser
Parser.depends = muparser
SUBDIRS = muparser Parser Server
Server.pro
TEMPLATE = app
QT += core sql websockets xml
QT -= gui
TARGET = Server
CONFIG += console
CONFIG -= app_bundle
CONFIG += thread
SOURCES += $$files(src/*.cpp, true) $$files(src/*.c, true)
HEADERS += $$files(src/*.h, true)
INCLUDEPATH += src src/things/include
LIBS += -L../lib -lParser
DESTDIR = ../Apps
Parser.pro
TEMPLATE = lib
QT -= gui
TARGET = Parser
DEFINES += PARSER_LIBRARY
SOURCES += parser.cpp
HEADERS += parser.h
INCLUDEPATH += ./include
DEPENDPATH += $$PWD/./
LIBS += -L../lib -lmuparser
DESTDIR += ../lib
DLLDESTDIR += ../Apps
The reason for this is because there are DLL that are needed there.
Thank to Bill I was able to find a solution to the problem
I simply had to change the DESTDIR location for my apps to DESTDIR = $$_PRO_FILE_PWD_/../Apps_Win

Deploy Custom Qt Widgets

I try to deploy my custom widget with this doc but when I compile only .h and dll are copied, .lib and .pdb are not:
This is my .pro when i configurer the copy directive
message(Building...)
QT += widgets designer
PLUGIN_CLASS_NAME = QKWidgets
QTDIR_build {
message(Qt Build)
# This is only for the Qt build. Do not use externally. We mean it.
PLUGIN_TYPE = designer
load(qt_plugin)
CONFIG += install_ok
} else {
message(Public Build)
# Public example:
TARGET = $$qtLibraryTarget($$TARGET)
CONFIG += plugin debug_and_release
TEMPLATE = lib
target.path = $$[QT_INSTALL_PLUGINS]/designer
#INSTALLS += target
headersDataFiles.path = $$[QT_INSTALL_HEADERS]/$$PLUGIN_CLASS_NAME/
headersDataFiles.files = $$PWD/*.h
#INSTALLS += headersDataFiles
libraryFiles.path = $$[QT_INSTALL_LIBS]
CONFIG(debug, debug|release): libraryFiles.files = $$OUT_PWD/debug/*.lib $$OUT_PWD/release/*.pdb
CONFIG(release, debug|release): libraryFiles.files = $$OUT_PWD/release/*.lib
INSTALLS += target headersDataFiles libraryFiles
message(Lib dest: $$[QT_INSTALL_LIBS])
message(Lib src: $$libraryFiles.files)
}
message(General Build)
Edit:
install_libraryFiles doesn't appear in Makefile
Edit2:
Output :
Project MESSAGE: Building...
Project MESSAGE: Public Build
Project MESSAGE: Lib dest: C:/Qt/Qt5.9.0/5.9.1/msvc2017_64/lib
Project MESSAGE: Lib src: C:/Users/SD/Documents/Studio/MyProject/Widgets/Build/Release/release/*.lib
Project MESSAGE: General Build
Project MESSAGE: Building...
Project MESSAGE: Public Build
Project MESSAGE: Lib dest: C:/Qt/Qt5.9.0/5.9.1/msvc2017_64/lib
Project MESSAGE: Lib src: C:/Users/SD/Documents/Studio/MyProject/Widgets/Build/Release/release/*.lib
Project MESSAGE: General Build
Project MESSAGE: Building...
Project MESSAGE: Public Build
Project MESSAGE: Lib dest: C:/Qt/Qt5.9.0/5.9.1/msvc2017_64/lib
Project MESSAGE: Lib src: C:/Users/SD/Documents/Studio/MyProject/Widgets/Build/Release/debug/*.lib C:/Users/SD/Documents/Studio/MyProject/Widgets/Build/Release/release/*.pdb
Project MESSAGE: General Build
Use QMAKE_POST_LINK solved my problem :
message(Building...)
QT += widgets designer
PLUGIN_CLASS_NAME = QKWidgets
QTDIR_build {
message(Qt Build)
# This is only for the Qt build. Do not use externally. We mean it.
PLUGIN_TYPE = designer
load(qt_plugin)
CONFIG += install_ok
} else {
message(Public Build)
# Public example:
TARGET = $$qtLibraryTarget($$TARGET)
CONFIG += plugin debug_and_release
TEMPLATE = lib
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target # headersDataFiles libraryFiles
headersDataFiles.path = $$[QT_INSTALL_HEADERS]/$$PLUGIN_CLASS_NAME/
headersDataFiles.files = $$PWD/*.h
libraryFiles.path = $$[QT_INSTALL_LIBS]
CONFIG(debug, debug|release): libraryFiles.files = $$OUT_PWD/debug/*.lib $$OUT_PWD/debug/*.pdb
CONFIG(release, debug|release): libraryFiles.files = $$OUT_PWD/release/*.lib
win32 {
# Copy *.lib
DESTDIR_WIN = $$libraryFiles.path
DESTDIR_WIN ~= s,/,\\,g
FILES = $$libraryFiles.files
FILES ~= s,/,\\,g
for(FILE, FILES){
QMAKE_POST_LINK += $$quote(cmd /c copy /y $${FILE} $${DESTDIR_WIN}$$escape_expand(\\n\\t))
}
# Copy *.h
DESTDIR_WIN = $$headersDataFiles.path
DESTDIR_WIN ~= s,/,\\,g
FILES = $$headersDataFiles.files
FILES ~= s,/,\\,g
for(FILE, FILES){
QMAKE_POST_LINK += $$quote(cmd /c copy /y $${FILE} $${DESTDIR_WIN}$$escape_expand(\\n\\t))
}
}
}

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}

qmake copy files created while building

I've got a library qmake project:
QT += gui
TARGET = qturtle
TEMPLATE = lib
DEFINES += QTURTLE_LIBRARY
SOURCES += qturtle.cpp
HEADERS += qturtle.h\
qturtle_global.h
docMake.commands = doxygen;
QMAKE_EXTRA_TARGETS += docMake
PRE_TARGETDEPS += docMake
QMAKE_DISTCLEAN += $$PWD/html/ -r
QMAKE_DISTCLEAN += doxygen_sqlite3.db
unix {
docInstall.path = /usr/share/doc/qturtle
docInstall.files = $$PWD/html/
headerInstall.files = $$HEADERS
headerInstall.path = /usr/include/qturtle
target.path = /usr/lib
INSTALLS += docInstall
INSTALLS += target
INSTALLS += headerInstall
}
docMake runs doxygen in the project directory, and creates the 'html' directory and its contents ( during build!)
'html' and its contents now should be copied to /usr/share/doc/qturtle, using the INSTALL variable.
BUT: qmake doesn't generate any code for docInstall install, because $$PWD/html and its contents do not exist during makefile generation. Could anybody tell me how to avoid this problem, or do I have to use cp?
Thanks in advance,
Marius
There are two approaches to address this problem.
Not to check againt the initially empty directory
docInstall.CONFIG += no_check_exist directory
Since this directory will be created on the fly, I would personally opt for this.
Create the directory explicitly
createDirs.commands = $$QMAKE_MKDIR $$PWD/html
This could be done either in a target or even in a system("$$QMAKE_MKDIR $$PWD/html") call, depending on your needs.

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