2019-04-06 09:08:09 -04:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2017-10-27 15:43:34 +02:00
|
|
|
# kernel is a normal CMake library and not a zephyr_library because it
|
|
|
|
# should not be --whole-archive'd
|
2020-08-27 08:37:10 -04:00
|
|
|
|
2021-08-05 11:11:23 -07:00
|
|
|
# If a pre-built static library containing kernel code exists in
|
|
|
|
# this directory, libkernel.a, link it with the application code
|
|
|
|
# instead of building from source.
|
|
|
|
zephyr_library_get_current_dir_lib_name(${ZEPHYR_BASE} libkernel_stem)
|
|
|
|
set(libkernel ${CMAKE_CURRENT_SOURCE_DIR}/lib${libkernel_stem}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
|
|
|
unset(libkernel_stem)
|
|
|
|
|
|
|
|
if(EXISTS ${libkernel})
|
|
|
|
|
|
|
|
add_library(kernel INTERFACE)
|
|
|
|
target_link_libraries(kernel INTERFACE ${libkernel})
|
|
|
|
|
|
|
|
else()
|
|
|
|
|
2020-08-27 08:37:10 -04:00
|
|
|
list(APPEND kernel_files
|
2021-05-31 14:59:23 +02:00
|
|
|
main_weak.c
|
2021-04-14 13:40:25 +02:00
|
|
|
banner.c
|
2017-10-27 15:43:34 +02:00
|
|
|
device.c
|
|
|
|
errno.c
|
2019-07-11 14:18:28 -07:00
|
|
|
fatal.c
|
2017-10-27 15:43:34 +02:00
|
|
|
init.c
|
2020-04-03 10:01:03 -07:00
|
|
|
kheap.c
|
2017-10-27 15:43:34 +02:00
|
|
|
mem_slab.c
|
2021-04-14 13:40:25 +02:00
|
|
|
thread.c
|
|
|
|
version.c
|
|
|
|
)
|
|
|
|
|
|
|
|
if(CONFIG_MULTITHREADING)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
idle.c
|
|
|
|
mailbox.c
|
2017-10-27 15:43:34 +02:00
|
|
|
msg_q.c
|
|
|
|
mutex.c
|
|
|
|
pipes.c
|
|
|
|
queue.c
|
|
|
|
sem.c
|
|
|
|
stack.c
|
|
|
|
system_work_q.c
|
2020-11-24 16:47:47 -06:00
|
|
|
work.c
|
2021-04-14 13:40:25 +02:00
|
|
|
sched.c
|
|
|
|
condvar.c
|
2018-03-28 15:16:48 +05:30
|
|
|
)
|
2021-04-06 12:32:55 +02:00
|
|
|
|
|
|
|
if(CONFIG_SMP)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
smp.c)
|
|
|
|
endif()
|
|
|
|
|
2021-04-14 13:40:25 +02:00
|
|
|
endif()
|
2018-03-28 15:16:48 +05:30
|
|
|
|
2020-08-27 08:37:10 -04:00
|
|
|
if(CONFIG_XIP)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
xip.c)
|
|
|
|
endif()
|
|
|
|
|
2021-03-26 12:03:42 -07:00
|
|
|
if(CONFIG_DEMAND_PAGING_STATS)
|
|
|
|
list(APPEND kernel_files
|
|
|
|
paging/statistics.c)
|
|
|
|
endif()
|
|
|
|
|
2020-08-27 08:37:10 -04:00
|
|
|
add_library(kernel ${kernel_files})
|
|
|
|
|
2018-03-28 15:16:48 +05:30
|
|
|
# Kernel files has the macro __ZEPHYR_SUPERVISOR__ set so that it
|
|
|
|
# optimizes the code when userspace is enabled.
|
2020-11-21 06:58:58 -06:00
|
|
|
|
2018-03-28 15:16:48 +05:30
|
|
|
set_target_properties(
|
|
|
|
kernel
|
|
|
|
PROPERTIES
|
|
|
|
COMPILE_DEFINITIONS
|
|
|
|
__ZEPHYR_SUPERVISOR__
|
|
|
|
)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
|
|
|
target_sources_ifdef(CONFIG_STACK_CANARIES kernel PRIVATE compiler_stack_protect.c)
|
2018-09-27 16:50:00 -07:00
|
|
|
target_sources_ifdef(CONFIG_SYS_CLOCK_EXISTS kernel PRIVATE timeout.c timer.c)
|
2017-10-27 15:43:34 +02:00
|
|
|
target_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_C kernel PRIVATE atomic_c.c)
|
2020-07-31 13:52:40 +02:00
|
|
|
target_sources_ifdef(CONFIG_MMU kernel PRIVATE mmu.c)
|
|
|
|
target_sources_ifdef(CONFIG_POLL kernel PRIVATE poll.c)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2020-09-18 14:12:51 -07:00
|
|
|
if(${CONFIG_KERNEL_MEM_POOL})
|
|
|
|
target_sources(kernel PRIVATE mempool.c)
|
2020-04-03 15:39:25 -07:00
|
|
|
endif()
|
|
|
|
|
2017-12-14 14:37:00 +05:30
|
|
|
# The last 2 files inside the target_sources_ifdef should be
|
|
|
|
# userspace_handler.c and userspace.c. If not the linker would complain.
|
|
|
|
# This order has to be maintained. Any new file should be placed
|
|
|
|
# above these 2 files.
|
2017-10-27 15:43:34 +02:00
|
|
|
target_sources_ifdef(
|
|
|
|
CONFIG_USERSPACE
|
|
|
|
kernel PRIVATE
|
2019-06-20 23:51:27 +08:00
|
|
|
futex.c
|
2017-10-27 15:43:34 +02:00
|
|
|
mem_domain.c
|
2017-12-14 14:37:00 +05:30
|
|
|
userspace_handler.c
|
|
|
|
userspace.c
|
2017-10-27 15:43:34 +02:00
|
|
|
)
|
|
|
|
|
2021-04-28 10:38:27 +02:00
|
|
|
if(CONFIG_CACHE_MANAGEMENT AND CONFIG_USERSPACE)
|
|
|
|
target_sources(kernel PRIVATE cache_handlers.c)
|
|
|
|
endif()
|
|
|
|
|
2019-10-25 00:08:21 +09:00
|
|
|
target_include_directories(kernel PRIVATE
|
|
|
|
${ZEPHYR_BASE}/kernel/include
|
2020-07-07 08:06:27 +02:00
|
|
|
${ARCH_DIR}/${ARCH}/include
|
2019-10-25 00:08:21 +09:00
|
|
|
)
|
2018-03-28 15:16:48 +05:30
|
|
|
|
2021-08-05 11:11:23 -07:00
|
|
|
target_link_libraries(kernel zephyr_interface)
|
|
|
|
|
|
|
|
endif()
|
|
|
|
|
2020-01-23 15:39:17 +01:00
|
|
|
add_dependencies(kernel zephyr_generated_headers)
|
2017-10-27 15:43:34 +02:00
|
|
|
|
2021-08-05 11:11:23 -07:00
|
|
|
unset(libkernel)
|