1# SPDX-License-Identifier: Apache-2.0 2 3zephyr_library() 4zephyr_library_sources(libc-hooks.c) 5 6# Do not allow LTO when compiling libc-hooks.c file 7set_source_files_properties(libc-hooks.c PROPERTIES COMPILE_OPTIONS $<TARGET_PROPERTY:compiler,prohibit_lto>) 8 9# Zephyr normally uses -ffreestanding, which with current GNU toolchains 10# means that the flag macros used by newlib 3.x <inttypes.h> to signal 11# support for PRI.64 macros are not present. To make them available we 12# need to hook into the include path before the system files and 13# explicitly include the newlib header that provides those macros. 14zephyr_include_directories(include) 15 16# LIBC_LIBRARY_DIR may or may not have been set by the toolchain. E.g. when 17# using ZEPHYR_TOOLCHAIN_VARIANT=cross-compile it will be either up to the 18# toolchain to know where it's libc implementation is, or if it is 19# unable to, it will be up to the user to specify LIBC_LIBRARY_DIR vars to 20# point to a newlib implementation. 21if(LIBC_LIBRARY_DIR) 22 set(LIBC_LIBRARY_DIR_FLAG -L${LIBC_LIBRARY_DIR}) 23endif() 24 25# Define _ANSI_SOURCE in order to prevent Newlib from defining POSIX primitives 26# in its headers when GNU dialect is used (-std=gnu*). Newlib features.h 27# defines _DEFAULT_SOURCE when __STRICT_ANSI__ is not defined by GCC (i.e. when 28# -std=gnu*), which leads to various POSIX definitions being provided by the 29# Newlib headers and conflicts with the POSIX definitions provided by Zephyr. 30zephyr_compile_definitions(_ANSI_SOURCE) 31 32# define __LINUX_ERRNO_EXTENSIONS__ so we get errno defines like -ESHUTDOWN 33# used by the network stack 34zephyr_compile_definitions(__LINUX_ERRNO_EXTENSIONS__) 35 36if(CMAKE_C_COMPILER_ID STREQUAL "GNU") 37 zephyr_link_libraries( 38 ${LIBC_LIBRARY_DIR_FLAG} # NB: Optional 39 $<$<BOOL:${CONFIG_NEWLIB_LIBC_FLOAT_PRINTF}>:-u_printf_float> 40 $<$<BOOL:${CONFIG_NEWLIB_LIBC_FLOAT_SCANF}>:-u_scanf_float> 41 ) 42endif() 43 44if(CONFIG_NEWLIB_LIBC_NANO) 45 zephyr_link_libraries( 46 -specs=nano.specs 47 ) 48 zephyr_compile_options( 49 -specs=nano.specs 50 ) 51endif() 52