From d2896df82133797c77fd41cfff330e17e024f940 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Wed, 30 Oct 2024 11:56:14 +0100 Subject: [PATCH] cmake: set minimal C++ linker properties in minimal C++ CMake impl The property based toolchain integration allows a cleaner design by letting the toolchain define its properties and values and let CMake implementation of Zephyr provided C and C++ libraries adjust those properties when minimal C or C++ libraries are used. This commit moves handling of C++ linker library properties into the minimal C++ CMake implementation. Signed-off-by: Torsten Rasmussen --- cmake/linker/ld/linker_libraries.cmake | 1 - cmake/linker/lld/linker_flags.cmake | 2 +- cmake/linker/lld/linker_libraries.cmake | 1 - cmake/linker/xt-ld/linker_flags.cmake | 2 +- lib/cpp/minimal/CMakeLists.txt | 4 ++++ 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/linker/ld/linker_libraries.cmake b/cmake/linker/ld/linker_libraries.cmake index 1305d682ab5..489f1f3859b 100644 --- a/cmake/linker/ld/linker_libraries.cmake +++ b/cmake/linker/ld/linker_libraries.cmake @@ -16,7 +16,6 @@ if(NOT CONFIG_NATIVE_BUILD) endif() if(CONFIG_CPP - AND NOT CONFIG_MINIMAL_LIBCPP AND NOT CONFIG_NATIVE_LIBRARY # When new link principle is fully introduced, then the below condition can # be removed, and instead the external module c++ should use: diff --git a/cmake/linker/lld/linker_flags.cmake b/cmake/linker/lld/linker_flags.cmake index f11139aa1e2..48085df4443 100644 --- a/cmake/linker/lld/linker_flags.cmake +++ b/cmake/linker/lld/linker_flags.cmake @@ -7,7 +7,7 @@ # and adjust for lld specifics afterwards. include(${ZEPHYR_BASE}/cmake/linker/ld/linker_flags.cmake OPTIONAL) -if(NOT CONFIG_MINIMAL_LIBCPP AND NOT CONFIG_NATIVE_LIBRARY AND NOT CONFIG_EXTERNAL_MODULE_LIBCPP) +if(NOT CONFIG_NATIVE_LIBRARY AND NOT CONFIG_EXTERNAL_MODULE_LIBCPP) set_property(TARGET linker PROPERTY cpp_base ${LINKERFLAGPREFIX},-z,norelro) endif() diff --git a/cmake/linker/lld/linker_libraries.cmake b/cmake/linker/lld/linker_libraries.cmake index 2347898ad64..69690d2a051 100644 --- a/cmake/linker/lld/linker_libraries.cmake +++ b/cmake/linker/lld/linker_libraries.cmake @@ -8,7 +8,6 @@ set_linker_property(NO_CREATE TARGET linker PROPERTY rt_library "") set_linker_property(TARGET linker PROPERTY c++_library "-lc++;-lc++abi") if(CONFIG_CPP - AND NOT CONFIG_MINIMAL_LIBCPP AND NOT CONFIG_NATIVE_LIBRARY # When new link principle is fully introduced, then the below condition can # be removed, and instead the external module c++ should use: diff --git a/cmake/linker/xt-ld/linker_flags.cmake b/cmake/linker/xt-ld/linker_flags.cmake index af464509b87..ab66461e452 100644 --- a/cmake/linker/xt-ld/linker_flags.cmake +++ b/cmake/linker/xt-ld/linker_flags.cmake @@ -7,7 +7,7 @@ check_set_linker_property(TARGET linker PROPERTY base ${LINKERFLAGPREFIX},--build-id=none ) -if(NOT CONFIG_MINIMAL_LIBCPP AND NOT CONFIG_NATIVE_LIBRARY AND NOT CONFIG_EXTERNAL_MODULE_LIBCPP) +if(NOT CONFIG_NATIVE_LIBRARY AND NOT CONFIG_EXTERNAL_MODULE_LIBCPP) set_property(TARGET linker PROPERTY cpp_base -lstdc++) endif() diff --git a/lib/cpp/minimal/CMakeLists.txt b/lib/cpp/minimal/CMakeLists.txt index a79ca36d5e1..850087bcafa 100644 --- a/lib/cpp/minimal/CMakeLists.txt +++ b/lib/cpp/minimal/CMakeLists.txt @@ -1,5 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 +# Clear the toolchain defined C++ library property when using minimal C++ lib. +set_linker_property(PROPERTY c++_library "") +set_linker_property(PROPERTY cpp_base "") + zephyr_system_include_directories(include) zephyr_sources(