Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,27 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(app LANGUAGES C)

target_sources(app PRIVATE src/main.c)

# The code below locates the git index file for this repository and adds it as a dependency for
# the application VERSION file so that if the repo has a new commit added, even if no files in
# the build have changed, the application version file will be regenerated with the new git commit
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --absolute-git-dir
WORKING_DIRECTORY .
OUTPUT_VARIABLE application_git_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE stderr
RESULT_VARIABLE return_code)
# If there is an error e.g. it is not a git repo, we just silently ignore it and continue
# without a dependency, this will be the case with freestanding applications.
if(NOT return_code)
if(NOT "${stderr}" STREQUAL "")
message(WARNING "APPLICATION_BUILD_VERSION: git rev-parse warned: ${stderr}")
endif()

set_property(TARGET app_version_h PROPERTY APP_VERSION_DEPENDS ${application_git_dir}/index)
endif()
endif()
Loading