Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC][DNM] cmake: RFC for single libraries to use CMake dependencies and remove whole-archive #8451

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c01c577
cmake: Moving of TOOLCHAIN_LIBS and _ConfigAbsSyms settings
tejlmand Jun 18, 2018
8aa8726
cmake: Zephyr interface depends upon kernel
tejlmand Jun 18, 2018
a9b9487
cmake: Offset library linking flags
tejlmand Jun 18, 2018
86b6bec
cmake: Created a function which creates a list based on IFDEF / IFNDEF.
tejlmand May 17, 2018
0d8b50f
cmake: Kernel and app memory space update
tejlmand Jul 4, 2018
50b895d
cmake: cmake link libraries handling
tejlmand Aug 23, 2018
9268c4e
cmake: cmake library handling
tejlmand Sep 11, 2018
8a23d85
cmake: Example showing the use of fewer libraries.
tejlmand Jun 18, 2018
98d479e
cmake: Placing subsys_bluetooth and subsys_net in kernel memory space
tejlmand Sep 19, 2018
d55b171
cmake: Merged n times arch_arm_Y libs into soc_arm and arch_arm
tejlmand Jul 12, 2018
6b57a73
cmake: Merged n times arch_arc_Y libs into soc_arc and arch_arc
tejlmand Jul 12, 2018
294511f
cmake: Merged n times arch_nios2_Y libs into soc_nios2 and arch_nios2
tejlmand Jul 12, 2018
f6b241f
cmake: Merged n times arch_posix_Y libs into soc_posix and arch_posix
tejlmand Jul 12, 2018
340fa5e
cmake: Merged n times arch_riscv32_Y libs into soc_- / arch_riscv32
tejlmand Jul 12, 2018
8b8adf8
cmake: Merged n times arch_xtensa_Y libs into soc_xtensa and arch_xtensa
tejlmand Jul 12, 2018
c66dffa
arch: x86: exception: Weak symbol on default exception handlers.
tejlmand Aug 7, 2018
f1797ee
cmake: Merged n times arch_x86_Y libs into soc_x86 and arch_x86
tejlmand Jul 12, 2018
5833a2d
cmake: Placing arch_${ARCH} in kernel memory space
tejlmand Sep 19, 2018
389b689
cmake: include file based on KConfig configuration
tejlmand Aug 16, 2018
a2a061e
cmake: Example showing the use of fewer libraries.
tejlmand Aug 16, 2018
1cb0673
cmake: Placing drivers in kernel memory space
tejlmand Sep 19, 2018
aadbe33
cmake: creation of independent minimal libc library
tejlmand Aug 23, 2018
7760df9
cmake: Removed app and zephyr libs from whole-archive
tejlmand Aug 23, 2018
7fb5fb2
cmake: Creating a single board library
tejlmand Aug 29, 2018
a8e2a2a
cmake: Example showing the use of fewer libraries.
tejlmand Aug 31, 2018
478fb29
cmake: Example showing the use of fewer libraries.
tejlmand Aug 31, 2018
52ddad6
cmake: Creating a single openthread_platform library
tejlmand Aug 30, 2018
a06575c
cmake: mbedtls interface
tejlmand Oct 19, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
209 changes: 100 additions & 109 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ set_property( GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-little${ARCH})
# compiler options needed by all source files. All zephyr libraries,
# including the library named "zephyr" link with this library to
# obtain these flags.
# Linker flags will be propagated to executable targets which links
# to zephyr_interface, either directly or through other libraries which
# depends upon zephyr_interface, e.g. zephyr itself.
add_library(zephyr_interface INTERFACE)
zephyr_link_libraries(kernel ${TOOLCHAIN_LIBS})

# zephyr is a catchall CMake library for source files that can be
# built purely with the include paths, defines, and other compiler
# flags that come with zephyr_interface.
zephyr_library_named(zephyr)
add_library(zephyr STATIC "")
set(ZEPHYR_CURRENT_LIBRARY zephyr)
target_link_libraries(zephyr PRIVATE zephyr_interface)
target_link_libraries(zephyr INTERFACE -u_ConfigAbsSyms)
target_link_libraries(zephyr_app_linking INTERFACE zephyr)

zephyr_include_directories(
kernel/include
Expand Down Expand Up @@ -476,11 +484,7 @@ add_subdirectory(misc)
# property which is set implicitly for custom command outputs
include(misc/generated/CMakeLists.txt)

if(EXISTS ${SOC_DIR}/${ARCH}/CMakeLists.txt)
add_subdirectory(${SOC_DIR}/${ARCH} soc/${ARCH})
else()
add_subdirectory(${SOC_DIR}/${ARCH}/${SOC_PATH} soc/${ARCH}/${SOC_PATH})
endif()
add_subdirectory(${SOC_DIR} soc/${ARCH})

add_subdirectory(boards)
add_subdirectory(ext)
Expand Down Expand Up @@ -630,14 +634,23 @@ set(OFFSETS_O_PATH ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/offsets.dir/arch/${ARC
set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h)

add_library( offsets STATIC ${OFFSETS_C_PATH})
target_link_libraries(offsets zephyr_interface)
target_link_libraries(offsets INTERFACE -u_OffsetAbsSyms)
add_dependencies( offsets
syscall_list_h_target
syscall_macros_h_target
driver_validation_h_target
kobj_types_h_target
)

# Kernel is a Zephyr interface dependency, which means everyone using zephyr_interface has an
# indirect dependency, which for other libraries is fine.
# However offsets does not need to link to kernel as there is no dependency.
# Instead kernel depends on generated offset.h so to avoid a non-existing circular dependency,
# offset lib only requires the compile options and include directories from zephyr_interface.
target_compile_options( offsets PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS>)
target_compile_definitions(offsets PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS>)
target_include_directories(offsets PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_INCLUDE_DIRECTORIES>)

add_custom_command(
OUTPUT ${OFFSETS_H_PATH}
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/gen_offset_header.py
Expand All @@ -653,47 +666,11 @@ zephyr_get_include_directories_for_lang(C ZEPHYR_INCLUDES)

add_subdirectory(kernel)

# Read list content
get_property(ZEPHYR_LIBS_PROPERTY GLOBAL PROPERTY ZEPHYR_LIBS)

foreach(zephyr_lib ${ZEPHYR_LIBS_PROPERTY})
# TODO: Could this become an INTERFACE property of zephyr_interface?
add_dependencies(${zephyr_lib} offsets_h)

# Verify that all (non-imported) libraries have source
# files. Libraries without source files are not supported because
# they are an indication that something has been misconfigured.
get_target_property(lib_imported ${zephyr_lib} IMPORTED)
get_target_property(lib_sources ${zephyr_lib} SOURCES)
if(lib_sources STREQUAL lib_sources-NOTFOUND
AND (NOT (${zephyr_lib} STREQUAL app))
AND (NOT lib_imported)
)
# app is not checked because it's sources are added to it after
# this CMakeLists.txt file has been processed
message(FATAL_ERROR "\
The Zephyr library '${zephyr_lib}' was created without source files. \
Empty (non-imported) libraries are not supported. \
Either make sure that the library has the sources it should have, \
or make sure it is not created when it has no source files.")
endif()
endforeach()

get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT)

if(CONFIG_APPLICATION_MEMORY)
# Objects default to being in kernel space, and then we exclude
# certain items.
set(kernel_object_file_list
${ZEPHYR_LIBS_PROPERTY}
kernel
)
list(
REMOVE_ITEM
kernel_object_file_list
app
)
get_property(LINKER_SCRIPT_DEFINES GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES)

if(CONFIG_APPLICATION_MEMORY)
# The zephyr libraries in zephyr/lib/ and zephyr/test/ belong in
# userspace.

Expand All @@ -713,71 +690,87 @@ if(CONFIG_APPLICATION_MEMORY)
# prefixed with lib__ or test__ and will end up in the wrong address
# space.
set(application_space_dirs
lib
tests
libapp\.a
liblib.*\.a
libtests.*\.a
)
foreach(f ${kernel_object_file_list})
foreach(app_dir ${application_space_dirs})
if(${f} MATCHES "^${app_dir}__") # Begins with ${app_dir}__, e.g. lib__libc
list(
REMOVE_ITEM
kernel_object_file_list
${f}
)
endif()
endforeach()
endforeach()

# Create a list ks, with relative paths to kernel space libs.
foreach(f ${kernel_object_file_list})
get_target_property(target_name ${f} NAME)
get_target_property(target_binary_dir ${f} BINARY_DIR)

string(REPLACE
${PROJECT_BINARY_DIR}
""
fixed_path
${target_binary_dir}
)

# Append / if not empty
if(fixed_path)
set(fixed_path "${fixed_path}/")
endif()
set(KERNEL_OBJECTS_H ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/kernel_objects.h)
set(IMACROS_KERNEL_OBJECTS_H -imacros ${KERNEL_OBJECTS_H})

# Cut off leading / if present
if(fixed_path MATCHES "^/.+")
string(SUBSTRING ${fixed_path} 1 -1 fixed_path)
endif()

set(fixed_path "${fixed_path}lib${target_name}.a")
add_custom_command(OUTPUT ${KERNEL_OBJECTS_H}
COMMAND ${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/gen_kernel_objects.py
-i '$<TARGET_PROPERTY:memory_space_kernel,COMPILE_DEFINITIONS>'
-o ${KERNEL_OBJECTS_H}
-e '${application_space_dirs}'
COMMENT "Populating ${KERNEL_OBJECTS_H} with files for kernel space"
)
endif(CONFIG_APPLICATION_MEMORY)

if(CMAKE_GENERATOR STREQUAL "Ninja")
# Ninja invokes the linker from the root of the build directory
# (APPLICATION_BINARY_DIR) instead of from the build/zephyr
# directory (PROJECT_BINARY_DIR). So for linker-defs.h to get
# the correct path we need to prefix with zephyr/.
set(fixed_path "zephyr/${fixed_path}")
endif()
# Declare MPU userspace dependencies before the linker scripts to make
# sure the order of dependencies are met
if(CONFIG_CPU_HAS_MPU AND CONFIG_USERSPACE)
if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_APP_SHARED_MEM )
set(APP_SMEM_DEP app_smem_linker)
endif()
if(CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT AND CONFIG_ARC AND CONFIG_APPLICATION_MEMORY)
set(ALIGN_SIZING_DEP app_sizing_prebuilt linker_app_sizing_script)
endif()
if(CONFIG_ARM)
set(PRIV_STACK_DEP priv_stacks_prebuilt)
endif()
endif()

list(APPEND ks ${fixed_path})
endforeach()
function(construct_add_custom_command_for_linker_pass linker_output_name output_variable)
set(linker_cmd_file_name ${linker_output_name}.cmd)

# We are done constructing kernel_object_file_list, now we inject
# this list into the linker script through the define
# KERNELSPACE_OBJECT_FILES
set(def -DKERNELSPACE_OBJECT_FILES=)
foreach(f ${ks})
set(def "${def} ${f}")
endforeach()
set_property(GLOBAL APPEND PROPERTY
PROPERTY_LINKER_SCRIPT_DEFINES
${def}
)
endif() # CONFIG_APPLICATION_MEMORY
if (${linker_output_name} MATCHES "^linker_pass_final$")
set(LINKER_PASS_DEFINE -DLINKER_PASS2)
else()
set(LINKER_PASS_DEFINE "")
endif()

# Different generators deal with depfiles differently.
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
# Note that the IMPLICIT_DEPENDS option is currently supported only
# for Makefile generators and will be ignored by other generators.
set(LINKER_SCRIPT_DEP IMPLICIT_DEPENDS C ${LINKER_SCRIPT})
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
# Using DEPFILE with other generators than Ninja is an error.
set(LINKER_SCRIPT_DEP DEPFILE ${PROJECT_BINARY_DIR}/${linker_cmd_file_name}.dep)
else()
# TODO: How would the linker script dependencies work for non-linker
# script generators.
message(STATUS "Warning; this generator is not well supported. The
Linker script may not be regenerated when it should.")
set(LINKER_SCRIPT_DEP "")
endif()

set(${output_variable}
OUTPUT ${linker_cmd_file_name}
DEPENDS ${LINKER_SCRIPT}
${KERNEL_OBJECTS_H}
${LINKER_SCRIPT_DEP}
COMMAND ${CMAKE_C_COMPILER}
-x assembler-with-cpp
${NOSTDINC_F}
${NOSYSDEF_CFLAG}
-MD -MF ${linker_cmd_file_name}.dep -MT ${BASE_NAME}/${linker_cmd_file_name}
${IMACROS_KERNEL_OBJECTS_H}
${ZEPHYR_INCLUDES}
${LINKER_SCRIPT_DEFINES}
${LINKER_PASS_DEFINE}
-E ${LINKER_SCRIPT}
-P # Prevent generation of debug `#line' directives.
-o ${linker_cmd_file_name}
VERBATIM
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND_EXPAND_LISTS
PARENT_SCOPE
)
endfunction()

get_filename_component(BASE_NAME ${CMAKE_CURRENT_BINARY_DIR} NAME)
construct_add_custom_command_for_linker_pass(linker custom_command)
add_custom_command(
${custom_command}
Expand Down Expand Up @@ -807,17 +800,13 @@ set_property(TARGET

set(zephyr_lnk
${LINKERFLAGPREFIX},-Map=${PROJECT_BINARY_DIR}/${KERNEL_MAP_NAME}
-u_OffsetAbsSyms
-u_ConfigAbsSyms
${LINKERFLAGPREFIX},--whole-archive
${ZEPHYR_LIBS_PROPERTY}
$<TARGET_PROPERTY:zephyr_app_linking,INTERFACE_LINK_LIBRARIES>
${LINKERFLAGPREFIX},--no-whole-archive
kernel
${OFFSETS_O_PATH}
${LIB_INCLUDE_DIR}
-L${PROJECT_BINARY_DIR}
${TOOLCHAIN_LIBS}
)
offsets
)

if(CONFIG_GEN_ISR_TABLES)
if(CONFIG_GEN_SW_ISR_TABLE)
Expand Down Expand Up @@ -1084,6 +1073,8 @@ endif()
get_property(GKOF GLOBAL PROPERTY GENERATED_KERNEL_OBJECT_FILES)
get_property(GKSF GLOBAL PROPERTY GENERATED_KERNEL_SOURCE_FILES)

get_property(TOPT GLOBAL PROPERTY TOPT)
set_ifndef( TOPT -T)

get_property(CSTD GLOBAL PROPERTY CSTD)
set_ifndef(CSTD c99)
Expand Down
7 changes: 6 additions & 1 deletion arch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
add_definitions(-D__ZEPHYR_SUPERVISOR__)

add_library(arch_${ARCH} STATIC "")
target_link_libraries(arch_${ARCH} PUBLIC zephyr_interface)
target_link_libraries(zephyr_app_linking INTERFACE arch_${ARCH})
zephyr_set_property(TARGET arch_${ARCH} MEMORY_SPACE kernel)

add_subdirectory(common)
add_subdirectory(${ARCH})
include_relative(${ARCH}/CMakeLists.txt)
2 changes: 1 addition & 1 deletion arch/arc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ zephyr_cc_option(-fno-delete-null-pointer-checks)

zephyr_cc_option_ifdef (CONFIG_LTO -flto)

add_subdirectory(core)
include_relative(core/CMakeLists.txt)
50 changes: 25 additions & 25 deletions arch/arc/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
zephyr_library()
zephyr_list(SOURCES
OUTPUT PRIVATE_SOURCES
thread.c
thread_entry_wrapper.S
cpu_idle.S
fatal.c
fault.c
fault_s.S
irq_manage.c
cache.c
timestamp.c
isr_wrapper.S
regular_irq.S
swap.S
sys_fatal_error_handler.c
prep_c.c
reset.S
vector_table.c
IFDEF:${CONFIG_ARC_FIRQ} fast_irq.S
IFDEF:${CONFIG_ATOMIC_OPERATIONS_CUSTOM} atomic.c
IFDEF:${CONFIG_USERSPACE} userspace.S
IF_KCONFIG irq_offload.c
)

zephyr_library_sources(
thread.c
thread_entry_wrapper.S
cpu_idle.S
fatal.c
fault.c
fault_s.S
irq_manage.c
cache.c
timestamp.c
isr_wrapper.S
regular_irq.S
swap.S
sys_fatal_error_handler.c
prep_c.c
reset.S
vector_table.c
)
target_sources(arch_arc PRIVATE ${PRIVATE_SOURCES})

zephyr_library_sources_ifdef(CONFIG_ARC_FIRQ fast_irq.S)

zephyr_library_sources_if_kconfig(irq_offload.c)
zephyr_library_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_CUSTOM atomic.c)
add_subdirectory_ifdef(CONFIG_ARC_CORE_MPU mpu)
zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S)
include_relative_ifdef(CONFIG_ARC_CORE_MPU mpu/CMakeLists.txt)
9 changes: 6 additions & 3 deletions arch/arc/core/mpu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
zephyr_library()
zephyr_list(SOURCES
OUTPUT PRIVATE_SOURCES
IF_KCONFIG arc_core_mpu.c
IF_KCONFIG arc_mpu.c
)

zephyr_library_sources_if_kconfig(arc_core_mpu.c)
zephyr_library_sources_if_kconfig(arc_mpu.c)
target_sources(arch_arc PRIVATE ${PRIVATE_SOURCES})
2 changes: 1 addition & 1 deletion arch/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ zephyr_ld_options(
${ARCH_FLAG}
)

add_subdirectory(core)
include_relative(core/CMakeLists.txt)
Loading