如何通过 Qt 项目文件将命令的输出作为编译器标志传递?
我正在尝试将“git describe”的输出添加到我的应用程序的“关于”窗口中,以便更轻松地找出人们使用的应用程序版本。
我可以通过添加以下编译器标志来做到这一点: -DAPP_VERSION="$(git describe HEAD)"
但由于该项目是基于qmake的,我想找到一种方法将其放入Qt项目文件中。 这可能吗? 如果是这样,怎么办?
编辑: 我尝试添加以下内容:
QMAKE_CXXFLAGS += -DAPP_VERSION="$(git describe HEAD)"
但它只是给了我“-DAPP_VERSION=”,所以我想我必须使用一些转义字符,但我不知道哪些字符以及在哪里。 :/
I'm trying to add the output of "git describe" to the about window of my application, so it's easier to find out what version of the application people use.
I can do it by adding the following compiler flag:
-DAPP_VERSION="$(git describe HEAD)"
But since the project is based on qmake, I would like to find a way to put this into the Qt project file.
Is this possible? And if so, how?
edit:
I tried adding the following:
QMAKE_CXXFLAGS += -DAPP_VERSION="$(git describe HEAD)"
But it just gave me "-DAPP_VERSION=", so I suppose I have to use some escape characters, but I don't know which ones and where. :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以使用
这将在 qmake 运行期间仅执行一次 git 命令,这可能会加快大型项目的编译速度。 但是,您必须确保从存储库拉取后运行
qmake
和make clean
。You can also use
This will execute the git command only once during the qmake run which might speed up compilation for large projects. However, you must make sure to run
qmake
andmake clean
after pulling from the repository.感谢此链接解决了问题: http://robertcarlsen.net/ blog/2009/01/06/qmake-xcode-bug-258
这是我用来测试它的示例 qt 项目:
qt.pro:
qt.cpp:
Problem solved thanks to this link: http://robertcarlsen.net/blog/2009/01/06/qmake-xcode-bug-258
Here's a sample qt project I used to test it:
qt.pro:
qt.cpp: