Skip to content

Commit 19dd5f5

Browse files
xtremekforeverrauhul
authored andcommitted
Dynamically set zephyr_interface defines as -Xcc flags for Swift
1 parent 74ba8b3 commit 19dd5f5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

nrfx-blink-sdk/CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,24 @@ add_compile_options(
2828
# Disable PIC
2929
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fno-pic>"
3030

31-
# Assortment of defines for Zephyr
32-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -DKERNEL -Xcc -DNRF52840_XXAA -Xcc -DPICOLIBC_INTEGER_PRINTF_SCANF -Xcc -D_FORTIFY_SOURCE=1 -Xcc -D_POSIX_C_SOURCE=200809 -Xcc -D__LINUX_ERRNO_EXTENSIONS__ -Xcc -D__PROGRAM_START -Xcc -D__ZEPHYR__=1>"
33-
3431
# Add Libc include paths
3532
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -I -Xcc ${ZEPHYR_SDK_INSTALL_DIR}/arm-zephyr-eabi/picolibc/include>"
3633
)
3734

35+
# Add definitions from Zephyr to -Xcc flags
36+
get_target_property(ZEPHYR_DEFINES zephyr_interface INTERFACE_COMPILE_DEFINITIONS)
37+
if(ZEPHYR_DEFINES)
38+
foreach(flag ${ZEPHYR_DEFINES})
39+
# Ignore expressions like "$<SOMETHING>"
40+
string(FIND "${flag}" "$<" start_of_expression)
41+
if(NOT start_of_expression EQUAL -1)
42+
continue()
43+
endif()
44+
45+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -D${flag}>")
46+
endforeach()
47+
endif()
48+
3849
target_sources(app PRIVATE Stubs.c)
3950

4051
# The Swift code providing "main" needs to be in an OBJECT library (instead of STATIC library) to make sure it actually gets linker.

0 commit comments

Comments
 (0)