Skip to content

Commit 9624ce6

Browse files
committed
now using multilib concept which makes everything much cleaner and clearer
1 parent fe941af commit 9624ce6

File tree

3 files changed

+28
-66
lines changed

3 files changed

+28
-66
lines changed
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
set(CMAKE_SYSTEM_PROCESSOR cortex-m0plus)
22

3-
# these are all the directories under LLVM embedded toolchain for ARM (newlib or pibolibc) and under llvm_libc
4-
set(PICO_CLANG_RUNTIMES armv6m_soft_nofp armv6m_soft_nofp_size armv6m-unknown-none-eabi)
5-
6-
set(PICO_COMMON_LANG_FLAGS "--target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m")
3+
set(PICO_COMMON_LANG_FLAGS "--target=arm-none-eabi -mcpu=cortex-m0plus -mfloat-abi=soft")
74

85
include(${CMAKE_CURRENT_LIST_DIR}/util/pico_arm_clang_common.cmake)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
set(CMAKE_SYSTEM_PROCESSOR cortex-m33)
22

3-
# these are all the directories under LLVM embedded toolchain for ARM (newlib or pibolibc) and under llvm_libc
4-
set(PICO_CLANG_RUNTIMES armv8m.main_soft_nofp armv8m.main_soft_nofp_unaligned armv8m.main_soft_nofp_unaligned_size armv8m.main-unknown-none-eabi)
5-
6-
set(PICO_COMMON_LANG_FLAGS "-mcpu=cortex-m33 --target=armv8m.main-none-eabi -mfloat-abi=softfp -march=armv8m.main+fp+dsp")
3+
set(PICO_COMMON_LANG_FLAGS "--target=arm-none-eabi -mfloat-abi=hard -march=armv8m.main+fp+dsp")
74
set(PICO_DISASM_OBJDUMP_ARGS --mcpu=cortex-m33 --arch=armv8m.main+fp+dsp)
5+
86
include(${CMAKE_CURRENT_LIST_DIR}/util/pico_arm_clang_common.cmake)

cmake/preload/toolchains/util/pico_arm_clang_common.cmake

Lines changed: 25 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pico_find_compiler(PICO_OBJCOPY llvm-objcopy)
1111
pico_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")
1515
set(CMAKE_CXX_COMPILER ${PICO_COMPILER_CXX} CACHE FILEPATH "C++ compiler")
1616
set(CMAKE_ASM_COMPILER ${PICO_COMPILER_ASM} CACHE FILEPATH "ASM compiler")
1717

@@ -44,81 +44,48 @@ endforeach()
4444
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PICO_CLIB)
4545

4646
set(_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()
5464
elseif(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()
5868
elseif(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()
6272
else()
6373
message(FATAL_ERROR "PICO_CLIB must be one of newlib, picolib, llvm_libc or empty (but is '${PICO_CLIB}')")
6474
endif()
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

11782
if (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()
12387
endif()
88+
89+
message(STATUS "Taking '${PICO_CLIB}' from '${PICO_CLIB_ROOT}'")
90+
12491
include(${CMAKE_CURRENT_LIST_DIR}/set_flags.cmake)

0 commit comments

Comments
 (0)