How to refer to the source directory in qmake?

后端 未结 5 1890
长发绾君心
长发绾君心 2020-12-30 10:57

I added

version.target = version.h
version.commands = bash generate-version.sh

QMAKE_EXTRA_TARGETS += version

PRE_TARGETDEPS += version.h
<
5条回答
  •  温柔的废话
    2020-12-30 11:18

    My first thought is to try to rewrite

    version.commands = bash generate-version.sh
    

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

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

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

    PWD

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

    OUT_PWD

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

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

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

    version.commands = bash $$PWD/generate-version.sh
    

提交回复
热议问题