In Qt Creator, when I create a new Unit Test project it will not build successfully if the full path to the project contains a space.
I've tracked the bug down to the makefile produced by qmake. The makefile contains a line near the top like:
DEFINES = -DUNICODE -DWIN32 -DSRCDIR=\"C:/Users/Smith/Qt Projects/Unit_Tests/\" -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_TESTLIB_LIB -DQT_CORE_LIB -DQT_TESTCASE_BUILDDIR=\"C:/Users/Smith/Qt Projects/Debug_Unit_Tests\"
The quotes in the values for SRCDIR and QT_TESTCASE_BUILDDIR are escaped with backslashes. If I delete the backslashes from Makefile.Debug, then the project will build successfully.
Obviously, I don't want to have manually delete the backslashes every time. I'd also like to avoid a custom build step that removes the backslashes. Because qmake has so many options, I was hoping there was something I could just put in the .pro file that will fix this.
I tried something like DEFINES -= QT_TESTCASE_BUILDDIR. That doesn't work however because QT_TESTCASE_BUILDDIR is not yet defined. testlib apparently adds its own definitions later.
I am using:
Visual Studio 2010 SP 1
Qt 5.0.2
Qt Creator 2.7.0
Windows 7
What's the simplest way to get rid of the backslashes?
Edit: This also happens OSX.
The definitions added by testlib are in testlib_defines.prf which is in:
C:\Qt\Qt5.0.2\5.0.2\msvc2010\mkspecs\features
Change...
DEFINES += QT_TESTCASE_BUILDDIR=\\\"$$OUT_PWD\\\"
...to...
DEFINES += QT_TESTCASE_BUILDDIR=\"$$OUT_PWD\"
The other part is easy. The extra backslashes for SRCDIR come from the .pro file itself. Change...
DEFINES += SRCDIR=\\\"$$PWD/\\\"
...to...
DEFINES += SRCDIR=\"$$PWD/\"
Every time you install a new version of Qt, you'll have to edit the .prf file but that's better than having to edit the makefile every time qmake runs.
Related
I can easily edit Makefile to add custom step. For example, I have a line:
first: release
If I change it to
first: pre-build release
Then I'll be able to place some operations after "pre-build:" label.
The question is how to write corresponding instruction to .pro file, to force qmake tool generate required lines in Makefile?
You can add a custom target to your resulting Makefile using QMAKE_EXTRA_TARGETS variable, kind of that:
QMAKE_EXTRA_TARGETS += beforebuild
beforebuild.commands = echo Hello world!
beforebuild.CONFIG = phony
However, you cannot put this target onto first: all line, unless you've patched qmake's source code (consider the following snippet from makefile.cpp: t << "first: " << targets.first()->target << endl).
In principle, it's possible to induce some dependency between all (or release / debug) and your beforebuild target, so beforebuild would still get executed by make automatically, as described in this article (Russian language). Yet the resulting solution seems to me too ugly and error-prone.
I think that simply executing make beforebuild first (probably, using a shell script) is much easier. Unless you're using Qt Creator, in this case you should try the recipe from the link above.
I have a Qmake subdirs project and in the top level .pro file, I specify an extra target like so:
gruntbuild.target = gruntbuild
gruntbuild.commands = grunt --gruntfile $$PWD/Gruntfile.js
gui.depends = lib gruntbuild
QMAKE_EXTRA_TARGETS += gruntbuild
I can see in the resulting Makefile that a gruntbuild target is correctly added, however the all target does not reference it, so gruntbuild is not being run when jom.exe is called by QtCreator.
Do I need to add an extra command to ensure the target is run?
I think this is as easy as adding guito QMAKE_EXTRA_TARGETS. In other words, use
QMAKE_EXTRA_TARGETS += gui gruntbuild
The reason is that you have to "export" the modified gui-target to the Makefile too. This will append another depend for the target, but that is apparently legal.
I have setted an environment variable like this:
XXX_ENV H:\xxx
I can see
H:\xxx
when I run command
echo %XXX_ENV%
in cmd.
Then I have a Qt .pro file like this:
> INCLUDEPATH += ($$(XXX_ENV))/include
but unfortunately the INCLUDEPATH don't work, I can't use those .h file in H:\xxx\include
How can I use the environment varibale in qmake file ?
---------------------update---------------------------------
May be my description is not detaild enough.
This is the case. I have introduced a third party component into my project. The relevant files are in H:\XXX and i can use head files in H:\XXX\include. So my qmake can be writed like this:
INCLUDEPATH += H:/XXX/include
Then I can use head file "aaa.h" which is under directory H:\XXX\include just like this:
#include <aaa.h>
But I don't want to write the absolute path in the qmake file. So I seted a Windows environment variable(not qmake file's variable) XXX_ENV and it's value is "H:\XXX"(or "H:/XXX").
I just want to know can I write INCLUDEPATH += $${XXX_ENV}/include instead of INCLUDEPATH += H:/XXX/include
I tried it but it didn't work.
See the documentation for details:
Variables can be used to store the contents of environment variables. These can be evaluated at the time that qmake is run, or included in the generated Makefile for evaluation when the project is built.
To obtain the contents of an environment value when qmake is run, use the $$(...) operator:
DESTDIR = $$(PWD)
message(The project will be installed in $$DESTDIR)
Your question seems to be imprecise as to what exactly "does not work" means, but you ought to use the quote function should you have spaces in the path, etc.
quote(string)
Converts a whole string into a single entity and returns the result. This is just a fancy way of enclosing the string into double quotes.
Is there a way to tell qmake to add to Makefile an include directive to include other Makefile.
I need at the beginning of generated Makefile added one line:
include custom.inc
Maybe there is just a way to output text to Makfiles from qmake but I could not find.
You can use the undocumented QMAKE_EXTRA_INCLUDES variable, like
QMAKE_EXTRA_INCLUDES += /path/to/your/file.mk
you can define a new target into make file and then tell what that target does:
mytarget.target = .buildfile
mytarget.commands = make -f AnotherMakeFile
QMAKE_EXTRA_TARGETS += mytarget
PRE_TARGETDEPS += .buildfile
last 2 statements add your target .buildfile to Makefile and mytarget to Qt compiling process
here you can get further info: http://qt-project.org/doc/qt-4.8/qmake-environment-reference.html
I haven't found a way to include a Makefile, but I have had a similar problem where I wanted one file to contain a common set of build variables. The solution I came up with was to use the QMake command include(filename.pro) (see QMake reference page). This causes QMake to include another project file. In my case, that contained all of the common settings.
Before compile my program ,I need to compile a 3rd party library,but it is not writen in QT ,it has a Makefile to build itself . so if I write a pro file like this:
TEMPLATE = subdirs
SUBDIRS += image myapp
(image directory is the 3rd party library)
then qmake,make
it always report "Cannot find file: image.pro"
if I write a pro file inside image, it will create a Makefile which will overwrite the original Makefile.
any suggestions?
Thanks in advance
You could try several things, depending on what you want:
Use QMAKE_MAKEFILE to rename the qmake-generated makefile so that is won't overwrite the other one.
do some fancy stuff to create something like a QMAKE_PRE_BUILD sort of thing (this variable does not exist in qmake):
makefile.target = Makefile
makefile.depends += prebuild
prebuild.target = prebuild
prebuild.depends = FORCE
prebuild.commands = #echo before build (to replace)
QMAKE_EXTRA_TARGETS += makefile
QMAKE_EXTRA_TARGETS += prebuild
Source: http://forum.qtfr.org/viewtopic.php?id=10686 (read post two and three (google translate) and keep in mind that "défaut" wich means defect gets translated as default :) )
These should be able to solve the problem you're having.