在当前目录之外获取GIT构建哈希 [英] Getting GIT build hash outside the current directory

查看:67
本文介绍了在当前目录之外获取GIT构建哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CMake对项目进行内核外/源外构建,并希望将 git describe --tags --dirty的结果作为版本号包含在该项目(仅供bug参考)。但是,任何试图告诉git代码回购的位置的尝试都会导致类似致命:不是git存储库(或任何父目录):. git的错误。

I'm using CMake to do an out-of-core/out-of-source build of my project, and want to include the result of a "git describe --tags --dirty" as a version number in the project (just for reference on bugs). However, any attempt to try and tell git where the code repo is results in an error like "fatal: Not a git repository (or any of the parent directories): .git".

除了当前工作目录外,是否有一种方法可以指定git在哪里寻找存储库?

Is there a way to specify where git should look for the repo, other than the current working directory?

推荐答案

或者,您可以使用 WORKING_DIRECTORY 参数从cmake中将 execute_process()用作参数。这就是我的工作:

Or you can use the WORKING_DIRECTORY-argument to execute_process() from cmake. This is what I do:

execute_process(COMMAND "${GIT_EXECUTABLE}" describe --tags --dirty
    WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
    RESULT_VARIABLE res
    OUTPUT_VARIABLE out
    ERROR_QUIET
    OUTPUT_STRIP_TRAILING_WHITESPACE)


$ b

然后在 $ {out} 中找到版本。

这篇关于在当前目录之外获取GIT构建哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆