cmake: Revert breaking change to CMAKE_SYSTEM_NAME

This commit reverts a breaking change in CMAKE_SYSTEM_NAME introduced by
"Zephyr" back to "Generic") and removes the file
`cmake/modules/Platform/Zephyr`.

Both changes in the aforementioned PR were only introduced to ultimately
modify the value of the global CMake property TARGET_SUPPORTS_SHARED_LIBS
for the special case of building for Xtensa with LLEXT.

The modification of CMAKE_SYSTEM_NAME is considered a breaking change
because it has the potential to alter the build of any non-trivial project
that previously checked for the "Generic" system identifier as
corresponding to Zephyr - for example by doing
`if (CMAKE_SYSTEM_NAME STREQUAL "Generic")`. Such builds may now break in
many ways including silently when there is no `else()` clause with a
`message()` to alert the user that a whole configuration block had been
skipped.

In essence, that CMAKE_SYSTEM_NAME modification was only introduced in
order to have CMake to load `cmake/modules/Platform/Zephyr.cmake` which in
turn adjusted the value of TARGET_SUPPORTS_SHARED_LIBS.

But the use of a CMake platform file like this is ineffective for
non-trivial projects where one or more top level CMake `project()` calls
may happen before the first call to `find_package(Zephyr)` because in such
cases CMAKE_MODULE_PATH will not have been modified yet to contain the
path to <Zephyr_ROOT>/cmake/modules and thus no platform file will be
include by CMake.

This patch moves the conditional override of TARGET_SUPPORTS_SHARED_LIBS
needed by some archs (e.g. Xtensa) into the `kernel.cmake` module which
is known to be the first call to `project()` that enables any language and
thus the one that must come before any artifact target can be defined.

Note commit 64e7d85 added a Kconfig to specify the object type of llext
being built, so it's not tied to the arch anymore but to the
CONFIG_LLEXT_TYPE_ELF_SHAREDLIB option.

Signed-off-by: Nicolas Lebedenco <nicolas@lebedenco.net>
This commit is contained in:
Nicolas Lebedenco 2024-04-25 08:47:10 -04:00 committed by Carles Cufí
parent 0408eee229
commit 6837ca808b
3 changed files with 6 additions and 17 deletions

View file

@ -41,10 +41,7 @@ set(CMAKE_CXX_COMPILER_FORCED 1)
# variable is used for constructing the file names of the platform files # variable is used for constructing the file names of the platform files
# like Linux.cmake or Windows-gcc.cmake. If your target is an embedded # like Linux.cmake or Windows-gcc.cmake. If your target is an embedded
# system without OS set CMAKE_SYSTEM_NAME to "Generic". # system without OS set CMAKE_SYSTEM_NAME to "Generic".
# set(CMAKE_SYSTEM_NAME Generic)
# This will force CMake to load cmake/modules/Platform/Zephyr.cmake,
# allowing Zephyr-specific embedded system features to be enabled.
set(CMAKE_SYSTEM_NAME Zephyr)
# https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_PROCESSOR.html: # https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_PROCESSOR.html:
# The name of the CPU CMake is building for. # The name of the CPU CMake is building for.

View file

@ -1,13 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (c) 2024, Arduino SA
# Perform the same initialization as the Generic platform, then enable
# dynamic library support if CONFIG_LLEXT is enabled.
include(Platform/Generic)
# Enable dynamic library support when CONFIG_LLEXT is enabled.
if(CONFIG_LLEXT)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS true)
endif()

View file

@ -168,6 +168,11 @@ set(KERNEL_STRIP_NAME ${KERNEL_NAME}.strip)
set(KERNEL_META_NAME ${KERNEL_NAME}.meta) set(KERNEL_META_NAME ${KERNEL_NAME}.meta)
set(KERNEL_SYMBOLS_NAME ${KERNEL_NAME}.symbols) set(KERNEL_SYMBOLS_NAME ${KERNEL_NAME}.symbols)
# Enable dynamic library support when required by LLEXT.
if(CONFIG_LLEXT AND CONFIG_LLEXT_TYPE_ELF_SHAREDLIB)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
endif()
include(${BOARD_DIR}/board.cmake OPTIONAL) include(${BOARD_DIR}/board.cmake OPTIONAL)
# If we are using a suitable ethernet driver inside qemu, then these options # If we are using a suitable ethernet driver inside qemu, then these options