[Interest] Fwd: Defining a string in qmake command line
Thiago Macieira
thiago.macieira at intel.com
Fri Jan 24 03:39:29 CET 2014
On quinta-feira, 23 de janeiro de 2014 23:05:26, Soroush Rabiei wrote:
> The problem is that bash (or qmake) eats the double quotation. Definition
> needs to be wrapped in quotations. So it should pass to compiler something
> like:
>
> -DSERIAL\"6b6ab0\"
You have to work back from what you want. You want a compiler argument
containing the string:
-DSERIAL="6b6ab0"
Since Make runs commands using the shell, you need to add one level of
escaping so the shell will do what you want:
-DSERIAL=\"6b6ab0\"
Testing:
$ make -f /dev/stdin <<<'all:
/bin/echo -DSERIAL=\"6b6ab0\"
'
/bin/echo -DSERIAL=\"6b6ab0\"
-DSERIAL="6b6ab0"
Now, qmake also processes backslashes, so you need to escape one more level:
to get one backslash in the Makefile, you need to write two. And you need one
more for the quote.
DEFINES += SERIAL=\\\"6b6ab0\\\"
Testing:
$ qmake /dev/stdin -o /dev/stdout <<<'DEFINES += SERIAL=\\\"6b6ab0\\\"' | grep
SERIAL
DEFINES = -DSERIAL=\"6b6ab0\" -DQT_GUI_LIB -DQT_CORE_LIB
Now, you wanted to pass that to qmake on the command-line, so you need to add
yet another level of escaping, by doubling each slash and adding one more:
DEFINES+=SERIAL=\\\\\\\"6b6ab0\\\\\\\"
Testing:
$ qmake /dev/null -o /dev/stdout DEFINES+=SERIAL=\\\\\\\"6b6ab0\\\\\\\" | grep
SERIAL
# Command: /home/thiago/obj/qt/qt5/qtbase/bin/qmake
DEFINES+=SERIAL=\\\6b6ab0\\\ -o . /dev/null
DEFINES = -DSERIAL=\"6b6ab0\" -DQT_GUI_LIB -DQT_CORE_LIB
$(QMAKE) DEFINES+=SERIAL=\\\6b6ab0\\\ /dev/null
@$(QMAKE) DEFINES+=SERIAL=\\\6b6ab0\\\ /dev/null
Note that the DEFINES variable is correct in the Makefile, but the command for
qmake to rerun itself is not. That's an apparent qmake bug.
PS: don't try this with spaces. You need $$quote for that.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140123/67b2b5cb/attachment.sig>
More information about the Interest
mailing list