@@ -11,7 +11,7 @@ pico_find_compiler(PICO_OBJCOPY llvm-objcopy)
1111pico_find_compiler(PICO_OBJDUMP llvm-objdump)
1212
1313# Specify the cross compiler.
14- set (CMAKE_C_COMPILER ${PICO_COMPILER_CC} CACHE FILEPATH "C compiler" )
14+ set (CMAKE_C_COMPILER ${PICO_COMPILER_CC} CACHE FILEPATH "C compiler" )
1515set (CMAKE_CXX_COMPILER ${PICO_COMPILER_CXX} CACHE FILEPATH "C++ compiler" )
1616set (CMAKE_ASM_COMPILER ${PICO_COMPILER_ASM} CACHE FILEPATH "ASM compiler" )
1717
@@ -44,81 +44,48 @@ endforeach()
4444list (APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PICO_CLIB)
4545
4646set (_CLANG_RUNTIMES_DIR "${PICO_COMPILER_DIR} /../lib/clang-runtimes" )
47- set (_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR} /arm-none-eabi" )
47+ cmake_path(NORMAL_PATH _CLANG_RUNTIMES_DIR)
48+ set (PICO_CLIB_ROOT "${_CLANG_RUNTIMES_DIR} " )
49+
50+ if (NOT PICO_CLIB OR PICO_CLIB STREQUAL "" )
51+ # newlib is primary if no clib specified
52+ if (EXISTS "${_CLANG_RUNTIMES_DIR} /newlib" )
53+ set (PICO_CLIB "newlib" )
54+ else ()
55+ set (PICO_CLIB "picolibc" )
56+ endif ()
57+ set (CACHE {PICO_CLIB} TYPE STRING FORCE VALUE ${PICO_CLIB} )
58+ endif ()
4859
49- if (NOT PICO_CLIB OR PICO_CLIB STREQUAL "" OR PICO_CLIB STREQUAL "newlib" )
50- # newlib is 1st class choice
51- if (EXISTS "${_CLANG_RUNTIMES_DIR} /newlib/arm-none-eabi" )
52- set (_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR} /newlib/arm-none-eabi" )
60+ if (PICO_CLIB STREQUAL "newlib" )
61+ if (EXISTS "${_CLANG_RUNTIMES_DIR} /newlib" )
62+ set (PICO_CLIB_ROOT "${_CLANG_RUNTIMES_DIR} /newlib" )
5363 endif ()
5464elseif (PICO_CLIB STREQUAL "llvm_libc" )
55- if (EXISTS "${_CLANG_RUNTIMES_DIR} /llvmlibc/arm-none-eabi " )
56- set (_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR} /llvmlibc/arm-none-eabi " )
65+ if (EXISTS "${_CLANG_RUNTIMES_DIR} /llvmlibc" )
66+ set (PICO_CLIB_ROOT "${_CLANG_RUNTIMES_DIR} /llvmlibc" )
5767 endif ()
5868elseif (PICO_CLIB STREQUAL "picolibc" )
59- if (EXISTS "${_CLANG_RUNTIMES_DIR} /picolibc/arm-none-eabi " )
60- set (_PICO_CLIB_PATH "${_CLANG_RUNTIMES_DIR} /picolibc/arm-none-eabi " )
69+ if (EXISTS "${_CLANG_RUNTIMES_DIR} /picolibc" )
70+ set (PICO_CLIB_ROOT "${_CLANG_RUNTIMES_DIR} /picolibc" )
6171 endif ()
6272else ()
6373 message (FATAL_ERROR "PICO_CLIB must be one of newlib, picolib, llvm_libc or empty (but is '${PICO_CLIB} ')" )
6474endif ()
6575
66- foreach (PICO_CLANG_RUNTIME IN LISTS PICO_CLANG_RUNTIMES)
67- # LLVM embedded-toolchain for ARM style
68- find_path (PICO_COMPILER_SYSROOT NAMES lib/libc.a
69- HINTS
70- ${_PICO_CLIB_PATH} /${PICO_CLANG_RUNTIME}
71- ${_CLANG_RUNTIMES_DIR} /${PICO_CLANG_RUNTIME}
72- )
73-
74- if (PICO_COMPILER_SYSROOT)
75- if (NOT PICO_CLIB)
76- # this is a bit of a hack; to try to autodetect the C library used:
77- # `picolibc.h` seems to exist on the newer versions of LLVM embedded toolchain for ARM using picolibc whereas
78- # `newlib.h` appears in all versions, so isn't very useful
79- if (EXISTS "${PICO_COMPILER_SYSROOT} /include/picolibc.h" )
80- message ("Setting default C library to picolibc as LLVM appears to be using it" )
81- set (PICO_CLIB "picolibc" CACHE INTERNAL "" )
82- endif ()
83- endif ()
84- break ()
85- endif ()
86- # llvm_libc style
87- find_path (PICO_COMPILER_SYSROOT NAMES stdio.h
88- HINTS
89- ${PICO_COMPILER_DIR} /../include /${PICO_CLANG_RUNTIME}
90- )
91- if (PICO_COMPILER_SYSROOT)
92- if (NOT PICO_CLIB)
93- message ("Setting default C library to llvm_libc as LLVM appears to be using it" )
94- set (PICO_CLIB "llvm_libc" CACHE INTERNAL "" )
95- endif ()
96- break ()
97- endif ()
98- endforeach ()
99- if (NOT PICO_COMPILER_SYSROOT)
100- message (FATAL_ERROR "Could not find an llvm runtime for '${PICO_CLANG_RUNTIME} '" )
101- endif ()
102- set (PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} --sysroot ${PICO_COMPILER_SYSROOT} " )
103-
104- # add some system includes due to structure of ATfE-21.1.1 header structure
105- # required for llvmlibc / newlib, NOT for picolibc
106- if (EXISTS "${PICO_COMPILER_SYSROOT} /../include/c++/v1" )
107- set (PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -isystem ${PICO_COMPILER_SYSROOT} /../include/c++/v1" )
108- endif ()
109- if (EXISTS "${PICO_COMPILER_SYSROOT} /../include" )
110- set (PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} -isystem ${PICO_COMPILER_SYSROOT} /../include" )
111- endif ()
76+ set (PICO_COMMON_LANG_FLAGS "${PICO_COMMON_LANG_FLAGS} --sysroot ${PICO_CLIB_ROOT} " )
11277
11378# moving this here as a reminder from pico_standard_link; it was commented out theee, but if ever needed,
11479# it belongs here as part of LINKER_FLAGS_INIT
11580#target_link_options(pico_standard_link INTERFACE "LINKER:-fuse-ld=lld")
11681
11782if (PICO_CLIB STREQUAL "llvm_libc" )
118- # TODO: Remove -nostdlib++ once we include libc++ in the toolchain.
11983 # TODO: Move -nostartfiles to the appropriate library.
12084 foreach (TYPE IN ITEMS EXE SHARED MODULE)
121- set (CMAKE_${TYPE} _LINKER_FLAGS_INIT "-nostdlib++ - nostartfiles" )
85+ set (CMAKE_${TYPE} _LINKER_FLAGS_INIT "-nostartfiles" )
12286 endforeach ()
12387endif ()
88+
89+ message (STATUS "Taking '${PICO_CLIB} ' from '${PICO_CLIB_ROOT} '" )
90+
12491include (${CMAKE_CURRENT_LIST_DIR} /set_flags.cmake)
0 commit comments