How to pass a cmd-command output to a #DEFINE MACRO in QMake

家住魔仙堡 提交于 2019-12-01 04:30:45

问题


I added a new #DEFINE to my ".pro" file like this:

#DEFINE += SVN_V

now I would like to pass the output of the command "svnversion -n" to this SVN_V, and here is what I did:

#DEFINE += "SVN_V = svnversion -n"

but the result is

error: no such file or directory

error: svnversion: no such file or directory

so, what am I missing here exactly? (Be aware I am working with Linux Ubuntu)


回答1:


It could be something like that:

DEFINES += "SVN_V=\"\\\"$$system(svnversion -n)\\\"\""

$$system() is a qmake function to execute system command and obtain output from it.

external quotes around SVN_V... - is for qmake - it must understand that this is a single define. If $$system() returns space delimited string "Unknown version" you will get in result: -DSVN="Unknown -Dversion".

Next quotes \" - to pass $$system() result to compiler. Without it you will get two arguments instead of one "Unknown and version".

Double quoted quotes \\\" is to pass value to preprocessor. Without it value will be without quotes and recognized as int. \\\" will be resolved by qmake as \" and passed to compiler.




回答2:


My cent on table: svn info --show-item revision



来源:https://stackoverflow.com/questions/15837185/how-to-pass-a-cmd-command-output-to-a-define-macro-in-qmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!