如何在制作过程中每次检查git标签?
我目前正在将CMAKE用于一个项目。 我想在制作项目时检查git标签,如果git标签不满足某种格式,则制作过程将失败。
这是我在cmakelist.txt中所做的事情。
execute_process(
COMMAND git describe --always --tags
OUTPUT_VARIABLE git_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)
string(REPLACE "-" ";" git_tag_list ${git_tag})
list(GET git_tag_list 0 git_tag_short)
string(REPLACE "." ";" ver_list ${git_tag_short})
set(ver_check_fail_msg "The git tag must be in the format of X.X.XX (6 characters), where X are digits. The current is ${git_tag_short}.")
list(LENGTH ver_list ver_len)
if (NOT "${ver_len}" STREQUAL "3")
message(FATAL_ERROR "${ver_check_fail_msg}")
endif()
问题是每次致电Cmake时才执行支票,但是我希望每次致电时执行检查。
有什么建议吗?
I am currently using the CMake for a project.
I would like to check the git tag when making the project, if the git tag does not satisfy a certain format, the making process shall fail.
Here is what I am doing in the CMakeList.txt
execute_process(
COMMAND git describe --always --tags
OUTPUT_VARIABLE git_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${PX4_SOURCE_DIR}
)
string(REPLACE "-" ";" git_tag_list ${git_tag})
list(GET git_tag_list 0 git_tag_short)
string(REPLACE "." ";" ver_list ${git_tag_short})
set(ver_check_fail_msg "The git tag must be in the format of X.X.XX (6 characters), where X are digits. The current is ${git_tag_short}.")
list(LENGTH ver_list ver_len)
if (NOT "${ver_len}" STREQUAL "3")
message(FATAL_ERROR "${ver_check_fail_msg}")
endif()
The problem is that the check is only executed every time I call cmake, but I would like the check to be executed every time I call make.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案最初来自:如何始终运行构建时命令不管有任何依赖性吗?
可以使用以下代码:
对于某些说明,此处的关键是文件
$ {cmake_current_binary_dir}/__header.h
永远不应该存在。由于它不存在,并且自定义目标取决于它,因此它将在
some_script
中触发add_custom_command
尝试生成缺失的文件。使该
some_script
从未真正生成$ {cmake_current_binary_dir}/__ Header.h
。只要文件不存在,add_custom_target
将始终触发some_script
。The answer is originally from: How to always run command when building regardless of any dependency?
One can use the following code:
For some explanation, the key here is the file
${CMAKE_CURRENT_BINARY_DIR}/__header.h
which should never exist.Since it does not exist and the custom target depends on it, it will trigger the
some_script
in theadd_custom_command
to try generate the missing file.Makesure that
some_script
never really generate the${CMAKE_CURRENT_BINARY_DIR}/__header.h
. As long as the file does not exist, theadd_custom_target
will always trigger thesome_script
.