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?