-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDfetchModules.cmake
More file actions
78 lines (67 loc) · 2.46 KB
/
DfetchModules.cmake
File metadata and controls
78 lines (67 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# DfetchModules.cmake
#
# Provides:
# dfetch_discover_zephyr_modules(<yaml> <workspace>)
# Reads a dfetch.yaml and appends any project destination that contains a
# zephyr/module.yml to ZEPHYR_MODULES in the caller's scope.
#
# dfetch_set_zephyr_build_version(<zephyr_dir>)
# When Zephyr is fetched via dfetch it has no .git directory, so Zephyr's
# CMake cannot derive a build version from git describe. This function
# reads the VERSION file directly and sets BUILD_VERSION in the caller's
# scope (unless it is already defined), silencing the CMake warning.
#
# Requires: Python 3 with pyyaml (both are Zephyr prerequisites).
# Capture this directory at include-time so the function below can always
# locate dfetch_modules.py, regardless of where it is called from.
set(_DfetchModules_dir "${CMAKE_CURRENT_LIST_DIR}")
function(dfetch_discover_zephyr_modules yaml workspace)
if(NOT EXISTS "${yaml}")
return()
endif()
if(DEFINED WEST_PYTHON)
set(_python "${WEST_PYTHON}")
else()
find_package(Python3 REQUIRED COMPONENTS Interpreter)
set(_python "${Python3_EXECUTABLE}")
endif()
execute_process(
COMMAND "${_python}" "${_DfetchModules_dir}/dfetch_modules.py" "${yaml}"
OUTPUT_VARIABLE _dsts
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE _err
RESULT_VARIABLE _result
)
if(NOT _result EQUAL 0)
message(FATAL_ERROR "DfetchModules: dfetch_modules.py failed: ${_err}")
endif()
string(REPLACE "\n" ";" _dsts "${_dsts}")
foreach(_dst IN LISTS _dsts)
if(EXISTS "${workspace}/${_dst}/zephyr/module.yml")
list(APPEND ZEPHYR_MODULES "${workspace}/${_dst}")
message(STATUS "Found dfetch module: ${_dst}")
endif()
endforeach()
# Propagate the (potentially extended) list back to the caller.
set(ZEPHYR_MODULES "${ZEPHYR_MODULES}" PARENT_SCOPE)
endfunction()
function(dfetch_set_zephyr_build_version zephyr_dir)
if(DEFINED BUILD_VERSION)
return()
endif()
set(_version_file "${zephyr_dir}/VERSION")
if(NOT EXISTS "${_version_file}")
return()
endif()
file(STRINGS "${_version_file}" _lines)
foreach(_line IN LISTS _lines)
if(_line MATCHES "VERSION_MAJOR = ([0-9]+)")
set(_maj "${CMAKE_MATCH_1}")
elseif(_line MATCHES "VERSION_MINOR = ([0-9]+)")
set(_min "${CMAKE_MATCH_1}")
elseif(_line MATCHES "PATCHLEVEL = ([0-9]+)")
set(_patch "${CMAKE_MATCH_1}")
endif()
endforeach()
set(BUILD_VERSION "${_maj}.${_min}.${_patch}" PARENT_SCOPE)
endfunction()