[ACCEPTED]-How to refer to the source directory in qmake?-qmake

Accepted answer
Score: 14

My first thought is to try to rewrite

version.commands = bash generate-version.sh

so 20 as not to have to invoke a shell script. Perhaps 19 you can combine all of the statements into 18 one line:

version.commands = echo \'char VERSION[]=\"1.0\";\' > version.h && ls && echo Done

If you are stuck with invoking 17 the script, probably PWD or OUT_PWD are 16 what you are looking for. From the qmake Variable Reference

PWD

This 15 variable contains the full path leading 14 to the directory where the qmake project 13 file (project.pro) is located.

OUT_PWD

This variable 12 contains the full path leading to the directory 11 where qmake places the generated Makefile.

The 10 one caveat that is not mentioned in the 9 documentation is that if you are doing a 8 recursive qmake, PWD refers to where the 7 top level .pro file was read from. Thus 6 if you run qmake -r from {proj-root}, when 5 sub/sub/sub/dir-proj.pro is finally read 4 in, PWD will still point to {proj-root}.

Assuming 3 that generate-version.sh is in the same 2 directory as your top level .pro file, you 1 might try:

version.commands = bash $$PWD/generate-version.sh
Score: 1

I found a better and cleaner solution

version.target = version.h
version.commands = bash ${QMAKE_VAR__PRO_FILE_PWD_}/generate-version.sh
QMAKE_EXTRA_TARGETS += version

The 5 variable _PRO_FILE_PWD_ is documented since qt 4.5 and 4 contains the path to the directory containing 3 the project file in use (Contains the .pro 2 file)

But to access this variable for QMAKE_EXTRA_TARGETS, QMAKE_VAR_ must 1 be appended.

Score: 1

PWD

Specifies the full path leading to the 4 directory containing the current file 3 being parsed. This can be useful to refer 2 to files within the source tree when writing 1 project files to support shadow builds.

Score: 0

I use (Linux and g++)

DEFINES += SVN_VERSION=\\\"\""`svnversion $$PWD`\""\\\"
DEFINES += COMPILE_DATE=\\\"\""`date`\""\\\"
DEFINES += SW_VERSION=\\\"\"0.5\"\\\"

which defines the macro 5 SVNVERSON to be the svn version. To access 4 it from C++:

QString svnVersion = SVN_VERSION;
QString swVersion  = SW_VERSION;

Explanation: On the shell I 3 want to see this call:

-DSVN_VERSION=\""`svnversion /path/to/my/source`"\"

As you see some escapes 2 are necessary on shell level. In the .pro-file 1 it then has to be escaped twice.

Score: 0

This works and is easy to understand.

version.commands = ( cd $${PWD}; generate-version.sh )

0

More Related questions