File tree Expand file tree Collapse file tree 2 files changed +40
-17
lines changed Expand file tree Collapse file tree 2 files changed +40
-17
lines changed Original file line number Diff line number Diff line change 2
2
3
3
cmake_minimum_required (VERSION 3.20.0 )
4
4
5
+ set (ZEPHYR_BASE $ENV{ZEPHYR_BASE} CACHE PATH "Zephyr base" )
6
+ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ZEPHYR_BASE} /cmake/modules )
7
+
8
+ include (git )
9
+
5
10
if (VERSION_TYPE STREQUAL KERNEL )
6
11
set (BUILD_VERSION_NAME BUILD_VERSION )
7
12
else ()
@@ -10,23 +15,7 @@ endif()
10
15
11
16
if (NOT DEFINED ${BUILD_VERSION_NAME} )
12
17
cmake_path (GET VERSION_FILE PARENT_PATH work_dir )
13
- find_package (Git QUIET )
14
- if (GIT_FOUND )
15
- execute_process (
16
- COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 --always
17
- WORKING_DIRECTORY ${work_dir}
18
- OUTPUT_VARIABLE ${BUILD_VERSION_NAME}
19
- OUTPUT_STRIP_TRAILING_WHITESPACE
20
- ERROR_STRIP_TRAILING_WHITESPACE
21
- ERROR_VARIABLE stderr
22
- RESULT_VARIABLE return_code
23
- )
24
- if (return_code )
25
- message (STATUS "git describe failed: ${stderr} " )
26
- elseif (NOT "${stderr} " STREQUAL "" )
27
- message (STATUS "git describe warned: ${stderr} " )
28
- endif ()
29
- endif ()
18
+ git_describe (${work_dir} ${BUILD_VERSION_NAME} )
30
19
endif ()
31
20
32
21
include (${ZEPHYR_BASE} /cmake/modules/version.cmake )
Original file line number Diff line number Diff line change
1
+ # SPDX-License-Identifier: Apache-2.0
2
+
3
+ include_guard (GLOBAL )
4
+
5
+ find_package (Git QUIET )
6
+
7
+ # Usage:
8
+ # git_describe(<dir> <output>)
9
+ #
10
+ # Helper function to get a short GIT desciption associated with a directory.
11
+ # OUTPUT is set to the output of `git describe --abbrev=12 --always` as run
12
+ # from DIR.
13
+ #
14
+ function (git_describe DIR OUTPUT )
15
+ if (GIT_FOUND )
16
+ execute_process (
17
+ COMMAND ${GIT_EXECUTABLE} describe --abbrev=12 --always
18
+ WORKING_DIRECTORY ${DIR}
19
+ OUTPUT_VARIABLE DESCRIPTION
20
+ OUTPUT_STRIP_TRAILING_WHITESPACE
21
+ ERROR_STRIP_TRAILING_WHITESPACE
22
+ ERROR_VARIABLE stderr
23
+ RESULT_VARIABLE return_code
24
+ )
25
+ if (return_code )
26
+ message (STATUS "git describe failed: ${stderr} " )
27
+ elseif (NOT "${stderr} " STREQUAL "" )
28
+ message (STATUS "git describe warned: ${stderr} " )
29
+ else ()
30
+ # Save output
31
+ set (${OUTPUT} ${DESCRIPTION} PARENT_SCOPE )
32
+ endif ()
33
+ endif ()
34
+ endfunction ()
You can’t perform that action at this time.
0 commit comments