4

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)

Community
  • 1
  • 1
McLan
  • 2,552
  • 9
  • 51
  • 85

2 Answers2

8

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.

loentar
  • 5,111
  • 1
  • 24
  • 25
  • thank you very much for your reply. I tried your way and the output in the cmd console is:(Could not find absolute location of file ""), note that I am getting the correct output of the svn version in my qt #defines. besides, I am confused about the use of the dollar sign!!. since we already indicating the command by using the `system()` function why do we need to reference it again using the `$$` sign . – McLan Apr 08 '13 at 09:24
  • think, something is wrong with your .pro file. Simple .pro file declaring TEMPLATE, SOURCES and that DEFINES compiles just fine without any warnings. `$$system()` is a qmake function, all qmake functions have `$$` prefix. See qmake function reference: http://qt-project.org/doc/qt-4.8/qmake-function-reference.html – loentar Apr 08 '13 at 09:51
  • my .pro file is fine. however, I think it is just a matter of specifying the working copy of my svn. for now, l only need what qt gives me ... but I am enable to pass the value of my "SVN_V" as string (because I am getting the value but with a letter like this "1.23M". it gives me an error that: invalid sufix "M" on integer constant. that means it read my SVN_V as integer but the M string is making problems, so, how do I fix this issue – McLan Apr 08 '13 at 11:06
  • `DEFINES += "SVN_V=\"$$system(svnversion -n)\""` -- should be fine – loentar Apr 08 '13 at 11:19
  • sorry for this mistake but the returned value is actually written like this "1:23M" (notice the colon ":", sorry it wasn't the dot) .. but again it is not working, the previous error still exists. in addition, in my call function `asd = (SVN_V)` it return this error: ("Expected ")" before ":" token) – McLan Apr 08 '13 at 11:32
0

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

alexbour
  • 11
  • 1