gpt4 book ai didi

qmake - 如何在qmake中引用源目录?

转载 作者:行者123 更新时间:2023-12-04 03:34:28 26 4
gpt4 key购买 nike

我加了

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

QMAKE_EXTRA_TARGETS += version

PRE_TARGETDEPS += version.h

到项目,但它尝试在目标目录中运行“generate-version.sh”:
make: Leaving directory `.../qqq-build-desktop'
make: Entering directory `.../qqq-build-desktop'
Makefile:236: warning: overriding commands for target `version.h'
Makefile:233: warning: ignoring old commands for target `version.h'
bash generate-version.sh
bash: generate-version.sh: No such file or directory
make: Leaving directory `.../qqq-build-desktop'

有$$ DESTDIR,但我看不到$$ SRCDIR。如何在qmake中引用项目目录(或如何重写它)?

最佳答案

我的第一个想法是尝试重写

version.commands = bash generate-version.sh
从而不必调用shell脚本。也许您可以将所有语句合并为一行:
version.commands = echo \'char VERSION[]=\"1.0\";\' > version.h && ls && echo Done
如果您一直想调用脚本,那么可能正在寻找PWD或OUT_PWD。从 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.


文档中未提及的一个警告是,如果您正在执行递归qmake,则PWD指的是从中读取顶级.pro文件的位置。因此,如果您从{proj-root}运行qmake -r,则当最终读入sub/sub/sub/dir-proj.pro时,PWD仍将指向{proj-root}。
假设generate-version.sh与顶级.pro文件位于同一目录中,则可以尝试:
version.commands = bash $$PWD/generate-version.sh

关于qmake - 如何在qmake中引用源目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5192714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com