Skip to content

Commit f62c147

Browse files
committed
cmake: toolchain: Introduce TOOLCHAIN_HAS_GLIBCXX
This commit introduces `TOOLCHAIN_HAS_GLIBCXX` CMake variable, which is set to `y` when GNU C++ Standard Library aka. libstdc++ is available. This helps filter libstdc++-specific Kconfig and tests in a more refined manner. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 07aca01 commit f62c147

File tree

6 files changed

+17
-2
lines changed

6 files changed

+17
-2
lines changed

cmake/modules/kconfig.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ else()
135135
set(_local_TOOLCHAIN_HAS_PICOLIBC n)
136136
endif()
137137

138+
if(TOOLCHAIN_HAS_GLIBCXX)
139+
set(_local_TOOLCHAIN_HAS_GLIBCXX y)
140+
else()
141+
set(_local_TOOLCHAIN_HAS_GLIBCXX n)
142+
endif()
143+
138144
# APP_DIR: Path to the main image (sysbuild) or synonym for APPLICATION_SOURCE_DIR (non-sysbuild)
139145
zephyr_get(APP_DIR VAR APP_DIR APPLICATION_SOURCE_DIR)
140146

@@ -159,6 +165,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
159165
TOOLCHAIN_KCONFIG_DIR=${TOOLCHAIN_KCONFIG_DIR}
160166
TOOLCHAIN_HAS_NEWLIB=${_local_TOOLCHAIN_HAS_NEWLIB}
161167
TOOLCHAIN_HAS_PICOLIBC=${_local_TOOLCHAIN_HAS_PICOLIBC}
168+
TOOLCHAIN_HAS_GLIBCXX=${_local_TOOLCHAIN_HAS_GLIBCXX}
162169
EDT_PICKLE=${EDT_PICKLE}
163170
# Export all Zephyr modules to Kconfig
164171
${ZEPHYR_KCONFIG_MODULES_DIR}

cmake/toolchain/espressif/generic.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ if(NOT CROSS_COMPILE_TARGET)
5454
endif()
5555

5656
set(TOOLCHAIN_HAS_NEWLIB ON CACHE BOOL "True if toolchain supports newlib")
57+
set(TOOLCHAIN_HAS_GLIBCXX ON CACHE BOOL "True if toolchain supports libstdc++")

cmake/toolchain/gnuarmemb/generic.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ set(SYSROOT_TARGET arm-none-eabi)
1818

1919
set(CROSS_COMPILE ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-)
2020
set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})
21+
2122
set(TOOLCHAIN_HAS_NEWLIB ON CACHE BOOL "True if toolchain supports newlib")
23+
set(TOOLCHAIN_HAS_GLIBCXX ON CACHE BOOL "True if toolchain supports libstdc++")
2224

2325
message(STATUS "Found toolchain: gnuarmemb (${GNUARMEMB_TOOLCHAIN_PATH})")

cmake/toolchain/host/generic.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ set(LINKER ld)
55
set(BINTOOLS host-gnu)
66

77
set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib")
8+
set(TOOLCHAIN_HAS_GLIBCXX ON CACHE BOOL "True if toolchain supports libstdc++")
89

910
message(STATUS "Found toolchain: host (gcc/ld)")

cmake/toolchain/zephyr/generic.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ include(${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr/generic.cmake)
44

55
set(TOOLCHAIN_KCONFIG_DIR ${ZEPHYR_SDK_INSTALL_DIR}/cmake/zephyr)
66

7-
message(STATUS "Found toolchain: zephyr ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR})")
7+
# Zephyr SDK < 0.17.1 does not set TOOLCHAIN_HAS_GLIBCXX
8+
set(TOOLCHAIN_HAS_GLIBCXX ON CACHE BOOL "True if toolchain supports libstdc++")
9+
10+
message(STATUS "Found toolchain: zephyr-sdk-gnu ${SDK_VERSION} (${ZEPHYR_SDK_INSTALL_DIR})")

lib/cpp/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ choice LIBCPP_IMPLEMENTATION
9696
prompt "C++ Standard Library Implementation"
9797
default EXTERNAL_LIBCPP if REQUIRES_FULL_LIBCPP && NATIVE_BUILD
9898
default LIBCXX_LIBCPP if REQUIRES_FULL_LIBCPP && "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "llvm"
99-
default GLIBCXX_LIBCPP if REQUIRES_FULL_LIBCPP
99+
default GLIBCXX_LIBCPP if REQUIRES_FULL_LIBCPP && "$(TOOLCHAIN_HAS_GLIBCXX)" = "y"
100100
default MINIMAL_LIBCPP
101101

102102
config MINIMAL_LIBCPP
@@ -111,6 +111,7 @@ config MINIMAL_LIBCPP
111111

112112
config GLIBCXX_LIBCPP
113113
bool "GNU C++ Standard Library"
114+
depends on "$(TOOLCHAIN_HAS_GLIBCXX)" = "y"
114115
depends on NEWLIB_LIBC || PICOLIBC
115116
select FULL_LIBCPP_SUPPORTED
116117
help

0 commit comments

Comments
 (0)