1# 2# SPDX-License-Identifier: BSD-3-Clause 3# 4# Copyright © 2022 Keith Packard 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 13# 2. Redistributions in binary form must reproduce the above 14# copyright notice, this list of conditions and the following 15# disclaimer in the documentation and/or other materials provided 16# with the distribution. 17# 18# 3. Neither the name of the copyright holder nor the names of its 19# contributors may be used to endorse or promote products derived 20# from this software without specific prior written permission. 21# 22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33# OF THE POSSIBILITY OF SUCH DAMAGE. 34# 35 36cmake_minimum_required(VERSION 3.20.0) 37 38project(Picolibc VERSION 1.8.8 LANGUAGES C ASM) 39 40# Set a default build type if none was specified 41set(default_build_type "MinSizeRel") 42 43if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES AND NOT DEFINED ZEPHYR_BASE) 44 message(STATUS "Setting build type to '${default_build_type}' as none was specified.") 45 set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE 46 STRING "Choose the type of build." FORCE) 47endif() 48 49find_program(CCACHE_PROGRAM ccache) 50if(CCACHE_PROGRAM) 51 message(STATUS "Using ccache: ${CCACHE_PROGRAM}") 52 set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}") 53endif() 54 55if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64") 56 set(CMAKE_SYSTEM_PROCESSOR "aarch64") 57endif() 58 59set(CMAKE_SYSTEM_SUB_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}) 60 61if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686" OR 62 ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") 63 set(CMAKE_SYSTEM_PROCESSOR "x86") 64endif() 65 66if(ZEPHYR_BASE) 67 if(NOT CONFIG_PICOLIBC_USE_MODULE) 68 return() 69 endif() 70 include(zephyr/zephyr.cmake) 71endif() 72 73include(cmake/picolibc.cmake) 74 75enable_testing() 76 77set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) 78 79# Set all configure values to defaults for now 80 81# Use atomics for fgetc/ungetc for re-entrancy 82set(ATOMIC_UNGETC 1) 83 84# Always optimize strcmp for performance 85if(NOT DEFINED FAST_STRCMP) 86 option(FAST_STRCMP "Always optimize strcmp for performance" ON) 87endif() 88 89# Obsoleted. Use regular syscalls 90set(MISSING_SYSCALL_NAMES 0) 91 92# use global errno variable 93if(NOT DEFINED NEWLIB_GLOBAL_ERRNO) 94 option(NEWLIB_GLOBAL_ERRNO "use global errno variable" OFF) 95endif() 96 97# use thread local storage 98if(NOT DEFINED PICOLIBC_TLS) 99 option(PICOLIBC_TLS "use thread local storage for static data" ON) 100endif() 101 102# use thread local storage 103set(NEWLIB_TLS ${PICOLIBC_TLS}) 104 105# Use open/close/read/write in tinystdio 106option(POSIX_IO "Provide fopen/fdopen using POSIX I/O (open, close, read, write, lseek)" ON) 107 108option(POSIX_CONSOLE "Use POSIX I/O for stdin/stdout/stderr" OFF) 109 110# Optimize for space over speed 111 112if(NOT DEFINED PREFER_SIZE_OVER_SPEED) 113 if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") 114 set(default_prefer_size ON) 115 else() 116 set(default_prefer_size OFF) 117 endif() 118 option(PREFER_SIZE_OVER_SPEED "Prefer smaller code size" ${default_prefer_size}) 119endif() 120 121# Obsoleted. Reentrant syscalls provided for us 122set(REENTRANT_SYSCALLS_PROVIDED 0) 123 124# Use tiny stdio from gcc avr 125option(TINY_STDIO "Use tiny stdio from avr libc" ON) 126 127if(NOT TLS_MODEL) 128 set(TLS_MODEL "local-exec") 129endif() 130 131set(_ATEXIT_DYNAMIC_ALLOC 0) 132 133set(_FSEEK_OPTIMIZATION 0) 134 135set(_FVWRITE_IN_STREAMIO 0) 136 137# Compiler supports alias symbol attribute 138picolibc_flag(_HAVE_ALIAS_ATTRIBUTE) 139 140# The compiler REALLY has the attribute __alloc_size__ 141picolibc_flag(_HAVE_ALLOC_SIZE) 142 143# The compiler supports the always_inline function attribute 144picolibc_flag(_HAVE_ATTRIBUTE_ALWAYS_INLINE) 145 146# The compiler supports the gnu_inline function attribute 147picolibc_flag(_HAVE_ATTRIBUTE_GNU_INLINE) 148 149# Use bitfields in packed structs 150picolibc_flag(_HAVE_BITFIELDS_IN_PACKED_STRUCTS) 151 152# The compiler supports __builtin_alloca 153picolibc_flag(_HAVE_BUILTIN_ALLOCA) 154 155# The compiler supports __builtin_copysign 156picolibc_flag(_HAVE_BUILTIN_COPYSIGN) 157 158# The compiler supports __builtin_copysignl 159picolibc_flag(_HAVE_BUILTIN_COPYSIGNL) 160 161# The compiler supports __builtin_ctz 162picolibc_flag(_HAVE_BUILTIN_CTZ) 163 164# The compiler supports __builtin_ctzl 165picolibc_flag(_HAVE_BUILTIN_CTZL) 166 167# The compiler supports __builtin_ctzll 168picolibc_flag(_HAVE_BUILTIN_CTZLL) 169 170# Compiler has __builtin_expect 171picolibc_flag(_HAVE_BUILTIN_EXPECT) 172 173# The compiler supports __builtin_ffs 174picolibc_flag(_HAVE_BUILTIN_FFS) 175 176# The compiler supports __builtin_ffsl 177picolibc_flag(_HAVE_BUILTIN_FFSL) 178 179# The compiler supports __builtin_ffsll 180picolibc_flag(_HAVE_BUILTIN_FFSLL) 181 182# The compiler supports __builtin_finitel 183picolibc_flag(_HAVE_BUILTIN_FINITEL) 184 185# The compiler supports __builtin_isfinite 186picolibc_flag(_HAVE_BUILTIN_ISFINITE) 187 188# The compiler supports __builtin_isinf 189picolibc_flag(_HAVE_BUILTIN_ISINF) 190 191# The compiler supports __builtin_isinfl 192picolibc_flag(_HAVE_BUILTIN_ISINFL) 193 194# The compiler supports __builtin_isnan 195picolibc_flag(_HAVE_BUILTIN_ISNAN) 196 197# The compiler supports __builtin_isnanl 198picolibc_flag(_HAVE_BUILTIN_ISNANL) 199 200# Compiler has __builtin_mul_overflow 201picolibc_flag(_HAVE_BUILTIN_MUL_OVERFLOW) 202 203# Compiler has __builtin_add_overflow 204picolibc_flag(_HAVE_BUILTIN_ADD_OVERFLOW) 205 206# Compiler has support for flag to prevent mis-optimizing memcpy/memset patterns 207picolibc_flag(_HAVE_CC_INHIBIT_LOOP_TO_LIBCALL) 208 209# Compiler supports _Complex 210picolibc_flag(_HAVE_COMPLEX) 211 212# Compiler supports __builtin_complex 213picolibc_flag(_HAVE_BUILTIN_COMPLEX) 214 215# Compiler supports format function attribute 216picolibc_flag(_HAVE_FORMAT_ATTRIBUTE 1) 217 218# Compiler supports weak attribute 219picolibc_flag(_HAVE_WEAK_ATTRIBUTE) 220 221set(_HAVE_FCNTL 0) 222 223# IEEE fp funcs available 224set(_HAVE_IEEEFP_FUNCS 0) 225 226# compiler supports INIT_ARRAY sections 227set(_HAVE_INITFINI_ARRAY 1) 228 229# Support _init() and _fini() functions 230set(_HAVE_INIT_FINI 1) 231 232# Enable MMU in pico crt startup 233set(_PICOCRT_ENABLE_MMU 1) 234 235# Compiler has long double type 236picolibc_flag(_HAVE_LONG_DOUBLE) 237 238# Compiler attribute to prevent the optimizer from adding new builtin calls 239picolibc_flag(_HAVE_NO_BUILTIN_ATTRIBUTE) 240 241# _set_tls and _init_tls functions available 242if(NOT DEFINED _HAVE_PICOLIBC_TLS_API OR NOT PICOLIBC_TLS) 243 set(_HAVE_PICOLIBC_TLS_API 0) 244endif() 245 246set(_HAVE_SEMIHOST 1) 247set(_ICONV_ENABLE_EXTERNAL_CCS 0) 248set(_ICONV_FROM_ENCODING_ 1) 249set(_ICONV_FROM_ENCODING_BIG5 1) 250set(_ICONV_FROM_ENCODING_CP775 1) 251set(_ICONV_FROM_ENCODING_CP850 1) 252set(_ICONV_FROM_ENCODING_CP852 1) 253set(_ICONV_FROM_ENCODING_CP855 1) 254set(_ICONV_FROM_ENCODING_CP866 1) 255set(_ICONV_FROM_ENCODING_EUC_JP 1) 256set(_ICONV_FROM_ENCODING_EUC_KR 1) 257set(_ICONV_FROM_ENCODING_EUC_TW 1) 258set(_ICONV_FROM_ENCODING_ISO_8859_1 1) 259set(_ICONV_FROM_ENCODING_ISO_8859_10 1) 260set(_ICONV_FROM_ENCODING_ISO_8859_11 1) 261set(_ICONV_FROM_ENCODING_ISO_8859_13 1) 262set(_ICONV_FROM_ENCODING_ISO_8859_14 1) 263set(_ICONV_FROM_ENCODING_ISO_8859_15 1) 264set(_ICONV_FROM_ENCODING_ISO_8859_2 1) 265set(_ICONV_FROM_ENCODING_ISO_8859_3 1) 266set(_ICONV_FROM_ENCODING_ISO_8859_4 1) 267set(_ICONV_FROM_ENCODING_ISO_8859_5 1) 268set(_ICONV_FROM_ENCODING_ISO_8859_6 1) 269set(_ICONV_FROM_ENCODING_ISO_8859_7 1) 270set(_ICONV_FROM_ENCODING_ISO_8859_8 1) 271set(_ICONV_FROM_ENCODING_ISO_8859_9 1) 272set(_ICONV_FROM_ENCODING_ISO_IR_111 1) 273set(_ICONV_FROM_ENCODING_KOI8_R 1) 274set(_ICONV_FROM_ENCODING_KOI8_RU 1) 275set(_ICONV_FROM_ENCODING_KOI8_U 1) 276set(_ICONV_FROM_ENCODING_KOI8_UNI 1) 277set(_ICONV_FROM_ENCODING_UCS_2 1) 278set(_ICONV_FROM_ENCODING_UCS_2BE 1) 279set(_ICONV_FROM_ENCODING_UCS_2LE 1) 280set(_ICONV_FROM_ENCODING_UCS_2_INTERNAL 1) 281set(_ICONV_FROM_ENCODING_UCS_4 1) 282set(_ICONV_FROM_ENCODING_UCS_4BE 1) 283set(_ICONV_FROM_ENCODING_UCS_4LE 1) 284set(_ICONV_FROM_ENCODING_UCS_4_INTERNAL 1) 285set(_ICONV_FROM_ENCODING_US_ASCII 1) 286set(_ICONV_FROM_ENCODING_UTF_16 1) 287set(_ICONV_FROM_ENCODING_UTF_16BE 1) 288set(_ICONV_FROM_ENCODING_UTF_16LE 1) 289set(_ICONV_FROM_ENCODING_UTF_8 1) 290set(_ICONV_FROM_ENCODING_WIN_1250 1) 291set(_ICONV_FROM_ENCODING_WIN_1251 1) 292set(_ICONV_FROM_ENCODING_WIN_1252 1) 293set(_ICONV_FROM_ENCODING_WIN_1253 1) 294set(_ICONV_FROM_ENCODING_WIN_1254 1) 295set(_ICONV_FROM_ENCODING_WIN_1255 1) 296set(_ICONV_FROM_ENCODING_WIN_1256 1) 297set(_ICONV_FROM_ENCODING_WIN_1257 1) 298set(_ICONV_FROM_ENCODING_WIN_1258 1) 299set(_ICONV_TO_ENCODING_ 1) 300set(_ICONV_TO_ENCODING_BIG5 1) 301set(_ICONV_TO_ENCODING_CP775 1) 302set(_ICONV_TO_ENCODING_CP850 1) 303set(_ICONV_TO_ENCODING_CP852 1) 304set(_ICONV_TO_ENCODING_CP855 1) 305set(_ICONV_TO_ENCODING_CP866 1) 306set(_ICONV_TO_ENCODING_EUC_JP 1) 307set(_ICONV_TO_ENCODING_EUC_KR 1) 308set(_ICONV_TO_ENCODING_EUC_TW 1) 309set(_ICONV_TO_ENCODING_ISO_8859_1 1) 310set(_ICONV_TO_ENCODING_ISO_8859_10 1) 311set(_ICONV_TO_ENCODING_ISO_8859_11 1) 312set(_ICONV_TO_ENCODING_ISO_8859_13 1) 313set(_ICONV_TO_ENCODING_ISO_8859_14 1) 314set(_ICONV_TO_ENCODING_ISO_8859_15 1) 315set(_ICONV_TO_ENCODING_ISO_8859_2 1) 316set(_ICONV_TO_ENCODING_ISO_8859_3 1) 317set(_ICONV_TO_ENCODING_ISO_8859_4 1) 318set(_ICONV_TO_ENCODING_ISO_8859_5 1) 319set(_ICONV_TO_ENCODING_ISO_8859_6 1) 320set(_ICONV_TO_ENCODING_ISO_8859_7 1) 321set(_ICONV_TO_ENCODING_ISO_8859_8 1) 322set(_ICONV_TO_ENCODING_ISO_8859_9 1) 323set(_ICONV_TO_ENCODING_ISO_IR_111 1) 324set(_ICONV_TO_ENCODING_KOI8_R 1) 325set(_ICONV_TO_ENCODING_KOI8_RU 1) 326set(_ICONV_TO_ENCODING_KOI8_U 1) 327set(_ICONV_TO_ENCODING_KOI8_UNI 1) 328set(_ICONV_TO_ENCODING_UCS_2 1) 329set(_ICONV_TO_ENCODING_UCS_2BE 1) 330set(_ICONV_TO_ENCODING_UCS_2LE 1) 331set(_ICONV_TO_ENCODING_UCS_2_INTERNAL 1) 332set(_ICONV_TO_ENCODING_UCS_4 1) 333set(_ICONV_TO_ENCODING_UCS_4BE 1) 334set(_ICONV_TO_ENCODING_UCS_4LE 1) 335set(_ICONV_TO_ENCODING_UCS_4_INTERNAL 1) 336set(_ICONV_TO_ENCODING_US_ASCII 1) 337set(_ICONV_TO_ENCODING_UTF_16 1) 338set(_ICONV_TO_ENCODING_UTF_16BE 1) 339set(_ICONV_TO_ENCODING_UTF_16LE 1) 340set(_ICONV_TO_ENCODING_UTF_8 1) 341set(_ICONV_TO_ENCODING_WIN_1250 1) 342set(_ICONV_TO_ENCODING_WIN_1251 1) 343set(_ICONV_TO_ENCODING_WIN_1252 1) 344set(_ICONV_TO_ENCODING_WIN_1253 1) 345set(_ICONV_TO_ENCODING_WIN_1254 1) 346set(_ICONV_TO_ENCODING_WIN_1255 1) 347set(_ICONV_TO_ENCODING_WIN_1256 1) 348set(_ICONV_TO_ENCODING_WIN_1257 1) 349set(_ICONV_TO_ENCODING_WIN_1258 1) 350 351# math library does not set errno (offering only ieee semantics) 352set(_IEEE_LIBM 1) 353 354if(NOT DEFINED _IO_FLOAT_EXACT) 355 option(_IO_FLOAT_EXACT "Provide exact binary/decimal conversion for printf/scanf" ON) 356endif() 357 358set(_LITE_EXIT 1) 359 360set(_PICO_EXIT 1) 361 362if(NOT DEFINED _ASSERT_VERBOSE) 363 option(_ASSERT_VERBOSE "Assert provides verbose information" ON) 364endif() 365 366if(NOT DEFINED _PICOLIBC_ATOMIC_SIGNAL) 367 option(_PICOLIBC_ATOMIC_SIGNAL "Use atomics in signal/raise" ON) 368endif() 369 370if(NOT DEFINED _MB_CAPABLE) 371 option(_MB_CAPABLE "Enable multi-byte support" OFF) 372endif() 373 374set(_NANO_FORMATTED_IO OFF) 375 376option(_NANO_MALLOC "Use smaller malloc implementation" ON) 377 378set(_REENT_GLOBAL_ATEXIT OFF) 379 380set(_UNBUF_STREAM_OPT OFF) 381 382if(NOT DEFINED _WANT_IO_C99_FORMATS) 383 option(_WANT_IO_C99_FORMATS "Support C99 formats in printf/scanf" ON) 384endif() 385 386if(NOT DEFINED _WANT_IO_LONG_LONG) 387 option(_WANT_IO_LONG_LONG "Support long long in integer printf/scanf" OFF) 388endif() 389 390if(NOT DEFINED _WANT_IO_LONG_DOUBLE) 391 option(_WANT_IO_LONG_DOUBLE "Support long double in printf/scanf" OFF) 392endif() 393 394if(NOT DEFINED _WANT_MINIMAL_IO_LONG_LONG) 395 option(_WANT_MINIMAL_IO_LONG_LONG "Support long long in minimal printf/scanf" OFF) 396endif() 397 398if(NOT DEFINED _WANT_IO_POS_ARGS) 399 option(_WANT_IO_POS_ARGS "Support positional args in integer printf/scanf" OFF) 400endif() 401 402option(__IO_FLOAT "Support floating point in printf/scanf by default" ON) 403 404if(NOT DEFINED _PRINTF_SMALL_ULTOA) 405 option(_PRINTF_SMALL_ULTOA "Avoid soft divide in printf" ON) 406endif() 407 408if(NOT DEFINED _PRINTF_PERCENT_N) 409 option(_PRINTF_PERCENT_N "Support %n formats in printf" OFF) 410endif() 411 412if(NOT DEFINED _WANT_IO_PERCENT_B) 413 option(_WANT_IO_PERCENT_B "Support %b/%B formats in printf/scanf" OFF) 414endif() 415 416if(NOT DEFINED _WANT_IO_WCHAR) 417 option(_WANT_IO_WCHAR "Support %ls/%lc formats in printf even without multi-byte" OFF) 418endif() 419 420if(NOT DEFINED _FORMAT_DEFAULT_MINIMAL) 421 set(_FORMAT_DEFAULT_MINIMAL ${IO_MINIMAL}) 422endif() 423 424if(_FORMAT_DEFAULT_MINIMAL) 425 set(_FORMAT_DEFAULT_DOUBLE OFF) 426 set(_FORMAT_DEFAULT_FLOAT OFF) 427 set(_FORMAT_DEFAULT_INTEGER OFF) 428 set(_FORMAT_DEFAULT_LONG_LONG OFF) 429endif() 430 431if(NOT DEFINED _FORMAT_DEFAULT_DOUBLE) 432 set(_FORMAT_DEFAULT_DOUBLE ${__IO_FLOAT}) 433endif() 434 435if(NOT DEFINED _FORMAT_DEFAULT_FLOAT) 436 set(_FORMAT_DEFAULT_FLOAT OFF) 437endif() 438 439if(NOT DEFINED _FORMAT_DEFAULT_LONG_LONG) 440 set(_FORMAT_DEFAULT_LONG_LONG OFF) 441endif() 442 443if(NOT DEFINED _FORMAT_DEFAULT_INTEGER) 444 if (__IO_FLOAT) 445 set(_FORMAT_DEFAULT_INTEGER OFF) 446 else() 447 set(_FORMAT_DEFAULT_INTEGER ON) 448 endif() 449endif() 450 451# math library sets errno 452set(_WANT_MATH_ERRNO OFF) 453 454set(_WANT_REENT_SMALL OFF) 455 456set(_WANT_REGISTER_FINI OFF) 457 458# Obsoleted. Define time_t to long instead of using a 64-bit type 459set(_WANT_USE_LONG_TIME_T OFF) 460 461set(_WIDE_ORIENT OFF) 462 463# locale support 464if(NOT DEFINED __HAVE_LOCALE_INFO__) 465 option(__HAVE_LOCALE_INFO__ "Provide locale support" OFF) 466endif() 467 468# extended locale support 469if(NOT DEFINED __HAVE_LOCALE_INFO_EXTENDED__) 470 option(__HAVE_LOCALE_INFO_EXTENDED__ "Provide even more locale support" OFF) 471endif() 472 473if(__HAVE_LOCALE_INFO_EXTENDED__ AND NOT __HAVE_LOCALE_INFO__) 474 message(FATAL_ERROR "Must have locale support to enable extended locale support") 475endif() 476 477if(NOT DEFINED _ELIX_LEVEL) 478 set(_ELIX_LEVEL 4) 479endif() 480 481# Use old math code for double funcs (0 no, 1 yes) 482set(__OBSOLETE_MATH_FLOAT ON) 483 484# Use old math code for double funcs (0 no, 1 yes) 485set(__OBSOLETE_MATH_DOUBLE ON) 486 487# Compute static memory area sizes at runtime instead of link time 488set(__PICOLIBC_CRT_RUNTIME_SIZE OFF) 489 490if(NOT DEFINED __SINGLE_THREAD__) 491 option(__SINGLE_THREAD__ "Disable multithreading support" OFF) 492endif() 493 494if(__SINGLE_THREAD__) 495 set(_RETARGETABLE_LOCKING OFF) 496else() 497 set(_RETARGETABLE_LOCKING ON) 498endif() 499 500set(NEWLIB_VERSION 4.3.0) 501set(NEWLIB_MAJOR 4) 502set(NEWLIB_MINOR 3) 503set(NEWLIB_PATCH 0) 504 505set(PICOLIBC_INCLUDE ${PROJECT_BINARY_DIR}/picolibc/include) 506 507set(PICOLIBC_SCRIPTS "${CMAKE_CURRENT_SOURCE_DIR}/scripts") 508 509include(CheckIncludeFile) 510 511CHECK_INCLUDE_FILE(xtensa/config/core-isa.h _XTENSA_HAVE_CONFIG_CORE_ISA_H) 512 513configure_file(picolibc.h.in "${PICOLIBC_INCLUDE}/picolibc.h") 514 515set(INCLUDEDIR include) 516set(LIBDIR .) 517if(PICOLIBC_TLS) 518 set(TLSMODEL "-ftls-model=${TLS_MODEL}") 519endif() 520set(LINK_SPEC "") 521set(CC1_SPEC "") 522set(CC1PLUS_SPEC "") 523set(ADDITIONAL_LIBS "") 524set(SPECS_EXTRA "") 525set(SPECS_ISYSTEM "-isystem ${PROJECT_BINARY_DIR}/${include}") 526set(SPECS_LIBPATH "-L${PROJECT_BINARY_DIR}") 527set(SPECS_STARTFILE "${PROJECT_BINARY_DIR}/crt0.o") 528string(APPEND SPECS_PRINTF "%{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfprintf=__f_vfprintf}" 529 " %{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfscanf=__f_vfscanf}" 530 " %{DPICOLIBC_DOUBLE_PRINTF_SCANF:--defsym=vfprintf=__d_vfprintf}" 531 " %{DPICOLIBC_DOUBLE_PRINTF_SCANF:--defsym=vfscanf=__d_vfscanf}" 532 " %{DPICOLIBC_INTEGER_PRINTF_SCANF:--defsym=vfprintf=__i_vfprintf}" 533 " %{DPICOLIBC_INTEGER_PRINTF_SCANF:--defsym=vfscanf=__i_vfscanff}" 534 " %{DPICOLIBC_MINIMAL_PRINTF_SCANF:--defsym=vfprintf=__m_vfprintf}" 535 " %{DPICOLIBC_MINIMAL_PRINTF_SCANF:--defsym=vfscanf=__i_vfscanff}" 536 ) 537set(PREFIX "${PROJECT_BINARY_DIR}") 538 539configure_file(picolibc.specs.in "${PROJECT_BINARY_DIR}/picolibc.specs" @ONLY) 540 541set(PICOLIBC_COMPILE_OPTIONS 542 "-nostdlib" 543 "-D_LIBC" 544 ${TLSMODEL} 545 ${TARGET_COMPILE_OPTIONS} 546 ${PICOLIBC_EXTRA_COMPILE_OPTIONS} 547 ${PICOLIBC_MATH_FLAGS} 548 ) 549 550# Strip out any generator expressions as those cannot be used with 551# try_compile 552 553foreach(c_option "${PICOLIBC_COMPILE_OPTIONS}") 554 if(NOT "${c_option}" MATCHES "\\$") 555 list(APPEND PICOLIBC_TEST_COMPILE_OPTIONS "${c_option}") 556 endif() 557endforeach() 558 559picolibc_supported_compile_options( 560 "-fno-common" 561 "-fno-stack-protector" 562 "-ffunction-sections" 563 "-fdata-sections" 564 "-Wall" 565 "-Wextra" 566 "-Werror=implicit-function-declaration" 567 "-Werror=vla" 568 "-Warray-bounds" 569 "-Wold-style-definition" 570 "-frounding-math" 571 "-fsignaling-nans" 572 ) 573 574add_library(c STATIC) 575 576target_compile_options(c PRIVATE ${PICOLIBC_COMPILE_OPTIONS}) 577 578set(PICOLIBC_INCLUDE_DIRECTORIES 579 "${PICOLIBC_INCLUDE}") 580 581target_include_directories(c SYSTEM PUBLIC ${PICOLIBC_INCLUDE_DIRECTORIES}) 582 583define_property(GLOBAL PROPERTY PICOLIBC_HEADERS 584 BRIEF_DOCS "Installed header files" 585 FULL_DOCS "These are names of header files which are to be installed.") 586 587add_subdirectory(newlib) 588 589install(TARGETS c 590 LIBRARY DESTINATION lib 591 PUBLIC_HEADER DESTINATION include) 592 593option(TESTS "Enable tests" OFF) 594if(TESTS) 595 596 # This could use some generalization, but it's good enough to do 597 # semihosting-based tests 598 599 add_subdirectory(semihost) 600 add_subdirectory(picocrt) 601 602 set(PICOCRT_OBJ $<TARGET_OBJECTS:picocrt>) 603 set(PICOCRT_SEMIHOST_OBJ $<TARGET_OBJECTS:picocrt-semihost>) 604 605 # semihost and libc have mutual-dependencies, so place them in a 606 # linker group 607 608 set(PICOLIBC_TEST_LINK_LIBRARIES 609 ${PICOCRT_SEMIHOST_OBJ} 610 -Wl,--start-group c semihost -Wl,--end-group 611 ${PICOLIBC_LINK_FLAGS} 612 ) 613 614 add_subdirectory(test) 615 616endif() 617 618install(FILES ${CMAKE_BINARY_DIR}/picolibc.specs DESTINATION lib) 619install(FILES ${CMAKE_BINARY_DIR}/picolibc/include/picolibc.h DESTINATION include) 620