Skip to content

Commit f445ed0

Browse files
arbraunsrlubos
authored andcommitted
[nrf fromtree] cmake: clean up gen_kobject_list.py invocations
cmake/kobj.cmake now provides nice wrappers around the script itself and common uses. Signed-off-by: Armin Brauns <[email protected]> (cherry picked from commit d6efbc8af47b8daa3957b5e7a1c1b5e71c7966a0)
1 parent ca1044b commit f445ed0

File tree

3 files changed

+85
-69
lines changed

3 files changed

+85
-69
lines changed

CMakeLists.txt

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -903,27 +903,17 @@ add_custom_command(
903903
DEPENDS ${PARSE_SYSCALLS_TARGET}
904904
)
905905

906-
# This is passed into all calls to the gen_kobject_list.py script.
907-
set(gen_kobject_list_include_args --include-subsystem-list ${struct_tags_json})
906+
include(${ZEPHYR_BASE}/cmake/kobj.cmake)
908907

909908
set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/zephyr/driver-validation.h)
910-
add_custom_command(
911-
OUTPUT ${DRV_VALIDATION}
912-
COMMAND
913-
${PYTHON_EXECUTABLE}
914-
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
915-
--validation-output ${DRV_VALIDATION}
916-
${gen_kobject_list_include_args}
917-
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
918-
DEPENDS
919-
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
920-
${PARSE_SYSCALLS_TARGET}
921-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
909+
gen_kobject_list(
910+
TARGET ${DRIVER_VALIDATION_H_TARGET}
911+
OUTPUTS ${DRV_VALIDATION}
912+
SCRIPT_ARGS --validation-output ${DRV_VALIDATION}
913+
INCLUDES ${struct_tags_json}
922914
)
923-
add_custom_target(${DRIVER_VALIDATION_H_TARGET} DEPENDS ${DRV_VALIDATION})
924915

925-
include(${ZEPHYR_BASE}/cmake/kobj.cmake)
926-
gen_kobj(KOBJ_INCLUDE_PATH)
916+
gen_kobject_list_headers(INCLUDES ${struct_tags_json})
927917

928918
# Generate sections for kernel device subsystems
929919
set(
@@ -1122,7 +1112,6 @@ if(CONFIG_USERSPACE)
11221112
NO_COVERAGE_FLAGS "${compiler_flags_priv}"
11231113
)
11241114

1125-
set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py)
11261115
set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/build/process_gperf.py)
11271116
endif()
11281117

@@ -1276,23 +1265,12 @@ if(CONFIG_USERSPACE)
12761265
set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE kobject_prebuilt_hash_preprocessed.c)
12771266
set(KOBJECT_PREBUILT_HASH_OUTPUT_SRC kobject_prebuilt_hash.c)
12781267

1279-
add_custom_command(
1268+
gen_kobject_list_gperf(
1269+
TARGET kobj_prebuilt_hash_list
12801270
OUTPUT ${KOBJECT_PREBUILT_HASH_LIST}
1281-
COMMAND
1282-
${PYTHON_EXECUTABLE}
1283-
${GEN_KOBJ_LIST}
1284-
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
1285-
--gperf-output ${KOBJECT_PREBUILT_HASH_LIST}
1286-
${gen_kobject_list_include_args}
1287-
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
1288-
DEPENDS
1289-
${ZEPHYR_LINK_STAGE_EXECUTABLE}
1290-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
1271+
KERNEL_TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE}
1272+
INCLUDES ${struct_tags_json}
12911273
)
1292-
add_custom_target(
1293-
kobj_prebuilt_hash_list
1294-
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_LIST}
1295-
)
12961274

12971275
add_custom_command(
12981276
OUTPUT ${KOBJECT_PREBUILT_HASH_OUTPUT_SRC_PRE}
@@ -1483,23 +1461,12 @@ if(CONFIG_USERSPACE)
14831461
# Use the script GEN_KOBJ_LIST to scan the kernel binary's
14841462
# (${ZEPHYR_LINK_STAGE_EXECUTABLE}) DWARF information to produce a table of kernel
14851463
# objects (KOBJECT_HASH_LIST) which we will then pass to gperf
1486-
add_custom_command(
1464+
gen_kobject_list_gperf(
1465+
TARGET kobj_hash_list
14871466
OUTPUT ${KOBJECT_HASH_LIST}
1488-
COMMAND
1489-
${PYTHON_EXECUTABLE}
1490-
${GEN_KOBJ_LIST}
1491-
--kernel $<TARGET_FILE:${ZEPHYR_LINK_STAGE_EXECUTABLE}>
1492-
--gperf-output ${KOBJECT_HASH_LIST}
1493-
${gen_kobject_list_include_args}
1494-
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
1495-
DEPENDS
1496-
${ZEPHYR_LINK_STAGE_EXECUTABLE}
1497-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
1467+
KERNEL_TARGET ${ZEPHYR_LINK_STAGE_EXECUTABLE}
1468+
INCLUDES ${struct_tags_json}
14981469
)
1499-
add_custom_target(
1500-
kobj_hash_list
1501-
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_LIST}
1502-
)
15031470

15041471
# Use gperf to generate C code (KOBJECT_HASH_OUTPUT_SRC_PRE) which implements a
15051472
# perfect hashtable based on KOBJECT_HASH_LIST

cmake/kobj.cmake

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,61 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
function(gen_kobj gen_dir_out)
3+
set(GEN_KOBJECT_LIST ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py)
4+
5+
# Invokes gen_kobject_list.py with the given SCRIPT_ARGS, creating a TARGET that depends on the
6+
# script's OUTPUTS
7+
function(gen_kobject_list)
8+
cmake_parse_arguments(PARSE_ARGV 0 arg
9+
""
10+
"TARGET"
11+
"OUTPUTS;SCRIPT_ARGS;INCLUDES;DEPENDS"
12+
)
13+
foreach(include ${arg_INCLUDES})
14+
list(APPEND arg_SCRIPT_ARGS --include-subsystem-list ${include})
15+
endforeach()
16+
add_custom_command(
17+
OUTPUT ${arg_OUTPUTS}
18+
COMMAND
19+
${PYTHON_EXECUTABLE}
20+
${GEN_KOBJECT_LIST}
21+
${arg_SCRIPT_ARGS}
22+
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
23+
DEPENDS
24+
${arg_DEPENDS}
25+
${GEN_KOBJECT_LIST}
26+
${PARSE_SYSCALLS_TARGET}
27+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
28+
)
29+
add_custom_target(${arg_TARGET} DEPENDS ${arg_OUTPUTS})
30+
endfunction()
31+
32+
# Generates a gperf header file named OUTPUT using the symbols found in the KERNEL_TARGET's output
33+
# binary. INCLUDES is a list of JSON files defining kernel subsystems and sockets.
34+
function(gen_kobject_list_gperf)
35+
cmake_parse_arguments(PARSE_ARGV 0 arg
36+
""
37+
"TARGET;OUTPUT;KERNEL_TARGET"
38+
"INCLUDES"
39+
)
40+
gen_kobject_list(
41+
TARGET ${arg_TARGET}
42+
OUTPUTS ${arg_OUTPUT}
43+
SCRIPT_ARGS
44+
--kernel $<TARGET_FILE:${arg_KERNEL_TARGET}>
45+
--gperf-output ${arg_OUTPUT}
46+
INCLUDES ${arg_INCLUDES}
47+
DEPENDS ${arg_KERNEL_TARGET}
48+
)
49+
endfunction()
50+
51+
# Generates header files describing the kernel subsystems defined by the JSON files in INCLUDES. The
52+
# variable named by GEN_DIR_OUT_VAR is set to the directory containing the header files.
53+
function(gen_kobject_list_headers)
54+
cmake_parse_arguments(PARSE_ARGV 0 arg
55+
""
56+
"GEN_DIR_OUT_VAR"
57+
"INCLUDES"
58+
)
459
if (PROJECT_BINARY_DIR)
560
set(gen_dir ${PROJECT_BINARY_DIR}/include/generated/zephyr)
661
else ()
@@ -13,24 +68,18 @@ function(gen_kobj gen_dir_out)
1368

1469
file(MAKE_DIRECTORY ${gen_dir})
1570

16-
add_custom_command(
17-
OUTPUT ${KOBJ_TYPES} ${KOBJ_OTYPE} ${KOBJ_SIZE}
18-
COMMAND
19-
${PYTHON_EXECUTABLE}
20-
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
21-
--kobj-types-output ${KOBJ_TYPES}
22-
--kobj-otype-output ${KOBJ_OTYPE}
23-
--kobj-size-output ${KOBJ_SIZE}
24-
${gen_kobject_list_include_args}
25-
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
26-
DEPENDS
27-
${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py
28-
${PARSE_SYSCALLS_TARGET}
29-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
30-
)
31-
add_custom_target(${KOBJ_TYPES_H_TARGET} DEPENDS ${KOBJ_TYPES} ${KOBJ_OTYPE})
32-
33-
cmake_path(GET gen_dir PARENT_PATH gen_dir)
34-
set(${gen_dir_out} ${gen_dir} PARENT_SCOPE)
71+
gen_kobject_list(
72+
TARGET ${KOBJ_TYPES_H_TARGET}
73+
OUTPUTS ${KOBJ_TYPES} ${KOBJ_OTYPE} ${KOBJ_SIZE}
74+
SCRIPT_ARGS
75+
--kobj-types-output ${KOBJ_TYPES}
76+
--kobj-otype-output ${KOBJ_OTYPE}
77+
--kobj-size-output ${KOBJ_SIZE}
78+
INCLUDES ${arg_INCLUDES}
79+
)
3580

81+
if(arg_GEN_DIR_OUT_VAR)
82+
cmake_path(GET gen_dir PARENT_PATH gen_dir)
83+
set(${arg_GEN_DIR_OUT_VAR} ${gen_dir} PARENT_SCOPE)
84+
endif()
3685
endfunction ()

cmake/modules/unittest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ target_link_libraries(testbinary PRIVATE test_interface)
5555
set(KOBJ_TYPES_H_TARGET kobj_types_h_target)
5656
include(${ZEPHYR_BASE}/cmake/kobj.cmake)
5757
add_dependencies(test_interface ${KOBJ_TYPES_H_TARGET})
58-
gen_kobj(KOBJ_GEN_DIR)
58+
gen_kobject_list_headers(GEN_DIR_OUT_VAR KOBJ_GEN_DIR)
5959

6060
# Generates empty header files to build
6161
set(INCL_GENERATED_DIR ${APPLICATION_BINARY_DIR}/zephyr/include/generated/zephyr)

0 commit comments

Comments
 (0)