Skip to content

Commit 06b1792

Browse files
nashifcfriedt
authored andcommitted
kernel: use cmake macro for adding kernel files
simplify cmake file and use macros for adding files that are part of the kernel based on the configuration. Signed-off-by: Anas Nashif <[email protected]>
1 parent e39de0e commit 06b1792

File tree

1 file changed

+24
-45
lines changed

1 file changed

+24
-45
lines changed

kernel/CMakeLists.txt

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ zephyr_syscall_header(
1010
${ZEPHYR_BASE}/include/zephyr/sys/time_units.h
1111
)
1212

13+
# Helper macro to append files to the kernel_files list
14+
macro(kernel_sources_ifdef feature_toggle)
15+
if(${${feature_toggle}})
16+
list(APPEND kernel_files ${ARGN})
17+
endif()
18+
endmacro()
19+
20+
macro(kernel_sources)
21+
list(APPEND kernel_files ${ARGN})
22+
endmacro()
23+
1324
if(NOT CONFIG_ERRNO_IN_TLS AND NOT CONFIG_LIBC_ERRNO)
1425
zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/sys/errno_private.h)
1526
endif()
@@ -47,7 +58,7 @@ else()
4758
# FIXME: SHADOW_VARS: Remove this once we have enabled -Wshadow globally.
4859
add_compile_options($<TARGET_PROPERTY:compiler,warning_shadow_variables>)
4960

50-
list(APPEND kernel_files
61+
kernel_sources(
5162
main_weak.c
5263
banner.c
5364
busy_wait.c
@@ -61,14 +72,11 @@ list(APPEND kernel_files
6172
version.c
6273
)
6374

64-
if(CONFIG_SCHED_CPU_MASK)
65-
list(APPEND kernel_files
75+
kernel_sources_ifdef(CONFIG_SCHED_CPU_MASK
6676
cpu_mask.c
6777
)
68-
endif()
6978

70-
if(CONFIG_MULTITHREADING)
71-
list(APPEND kernel_files
79+
kernel_sources_ifdef(CONFIG_MULTITHREADING
7280
idle.c
7381
mailbox.c
7482
msg_q.c
@@ -84,53 +92,24 @@ list(APPEND kernel_files
8492
pipe.c
8593
)
8694

95+
if(CONFIG_MULTITHREADING)
8796
if (CONFIG_SCHED_SCALABLE OR CONFIG_WAITQ_SCALABLE)
88-
list(APPEND kernel_files priority_queues.c)
97+
kernel_sources(priority_queues.c)
8998
endif()
9099

91-
if(CONFIG_SMP)
92-
list(APPEND kernel_files
100+
kernel_sources_ifdef(CONFIG_SMP
93101
smp.c
94102
ipi.c)
95-
endif()
96103
else() # CONFIG_MULTITHREADING
97-
list(APPEND kernel_files
98-
nothread.c
99-
)
104+
kernel_sources(nothread.c)
100105
endif() # CONFIG_MULTITHREADING
101106

102-
if(CONFIG_TIMESLICING)
103-
list(APPEND kernel_files
104-
timeslicing.c)
105-
endif()
106-
107-
if(CONFIG_SPIN_VALIDATE)
108-
list(APPEND kernel_files
109-
spinlock_validate.c)
110-
endif()
111-
112-
if(CONFIG_IRQ_OFFLOAD)
113-
list(APPEND kernel_files
114-
irq_offload.c
115-
)
116-
endif()
117-
118-
119-
if (CONFIG_BOOTARGS)
120-
list(APPEND kernel_files
121-
boot_args.c
122-
)
123-
endif()
124-
125-
if(CONFIG_THREAD_MONITOR)
126-
list(APPEND kernel_files
127-
thread_monitor.c)
128-
endif()
129-
130-
if(CONFIG_DEMAND_PAGING_STATS)
131-
list(APPEND kernel_files
132-
paging/statistics.c)
133-
endif()
107+
kernel_sources_ifdef(CONFIG_TIMESLICING timeslicing.c)
108+
kernel_sources_ifdef(CONFIG_SPIN_VALIDATE spinlock_validate.c)
109+
kernel_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
110+
kernel_sources_ifdef(CONFIG_BOOTARGS boot_args.c)
111+
kernel_sources_ifdef(CONFIG_THREAD_MONITOR thread_monitor.c)
112+
kernel_sources_ifdef(CONFIG_DEMAND_PAGING_STATS paging/statistics.c)
134113

135114
add_library(kernel ${kernel_files})
136115

0 commit comments

Comments
 (0)