Skip to content

Commit

Permalink
cmake: Revert breaking change to CMAKE_SYSTEM_NAME and unecessary int…
Browse files Browse the repository at this point in the history
…roduction of cmake/modules/Platform/Zephyr.cmake

This commit reverts a breaking change in CMAKE_SYSTEM_NAME introduced by
zephyrproject-rtos#67997 (changing it from
"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
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.

Signed-off-by: Nicolas Lebedenco <nicolas@lebedenco.net>
  • Loading branch information
nlebedenco committed Apr 14, 2024
1 parent 0b51d37 commit 4d8e45c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
5 changes: 1 addition & 4 deletions cmake/modules/FindTargetTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ set(CMAKE_CXX_COMPILER_FORCED 1)
# 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
# system without OS set CMAKE_SYSTEM_NAME to "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)
set(CMAKE_SYSTEM_NAME Generic)

# https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_PROCESSOR.html:
# The name of the CPU CMake is building for.
Expand Down
13 changes: 0 additions & 13 deletions cmake/modules/Platform/Zephyr.cmake

This file was deleted.

5 changes: 5 additions & 0 deletions cmake/modules/kernel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ set(KERNEL_STRIP_NAME ${KERNEL_NAME}.strip)
set(KERNEL_META_NAME ${KERNEL_NAME}.meta)
set(KERNEL_SYMBOLS_NAME ${KERNEL_NAME}.symbols)

# Enable dynamic library support required by CONFIG_XTENSA for CONFIG_LLEXT support.
if(CONFIG_XTENSA AND CONFIG_LLEXT)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
endif()

include(${BOARD_DIR}/board.cmake OPTIONAL)

# If we are using a suitable ethernet driver inside qemu, then these options
Expand Down

0 comments on commit 4d8e45c

Please sign in to comment.