[Interest] Fwd: Defining a string in qmake command line

Francisco Ares frares at gmail.com
Fri Jan 24 17:18:59 CET 2014


2014/1/24 Soroush Rabiei <soroush.rabiei at gmail.com>:
> On Fri, Jan 24, 2014 at 6:09 AM, Thiago Macieira <thiago.macieira at intel.com>
> wrote:
>>
>>
>> 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.
>
>
> I wasted a day on this issue. I was looking to Makefile all the time and I
> thought that this is not going to work because there is no " in `cat
> ./Makefile | grep SERIAL`. All definitions looks like this:
>     DEFINES+=SERIAL=\\\6b6ab0\\\
>
> Though make,  passes right argument to the compiler (how this happens?):
>     g++ -c -m64 -pipe -std=c++0x -O2 -Wall -W -D_REENTRANT -fPIC -DQT_WEBKIT
> -SERIAL=\"6b6ab0\"
>
> I'm going to force Windows users to use a shell (MSYS) if this way is not
> cross-platform enough.
>
> Thanks
>


Is it really needed to enclose the string?

What will it happens if you just do

DEFINES += SERIAL=6b6ab0


Francisco



More information about the Interest mailing list