Skip to content

Commit 2937d74

Browse files
Added preliminary Clang CMake toolchain and multilib.yml files
1 parent 369921a commit 2937d74

2 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright (C) 2024 by Skyward
2+
#
3+
# This program is free software; you can redistribute it and/or
4+
# it under the terms of the GNU General Public License as published
5+
# the Free Software Foundation; either version 2 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# As a special exception, if other files instantiate templates or use
14+
# macros or inline functions from this file, or you compile this file
15+
# and link it with other works to produce a work based on this file,
16+
# this file does not by itself cause the resulting work to be covered
17+
# by the GNU General Public License. However the source code for this
18+
# file must still be made available in accordance with the GNU
19+
# Public License. This exception does not invalidate any other
20+
# why a work based on this file might be covered by the GNU General
21+
# Public License.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with this program; if not, see <http://www.gnu.org/licenses/>
25+
26+
# Add the miosix/cmake path to find the Miosix.cmake platform file
27+
# that defines the Miosix system name
28+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/..)
29+
30+
# Tell CMake that we are building for an embedded ARM system
31+
set(CMAKE_SYSTEM_NAME Miosix)
32+
33+
# Names of the compiler and other tools
34+
set(CMAKE_ASM_COMPILER clang)
35+
set(CMAKE_C_COMPILER clang)
36+
set(CMAKE_CXX_COMPILER clang++)
37+
set(CMAKE_AR llvm-ar)
38+
set(CMAKE_OBJCOPY llvm-objcopy)
39+
set(CMAKE_OBJDUMP llvm-objdump)
40+
set(CMAKE_SIZE llvm-size)
41+
42+
# Optimization flags for each language and build configuration
43+
set(CMAKE_ASM_FLAGS_DEBUG "")
44+
set(CMAKE_C_FLAGS_DEBUG "-Og -g")
45+
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g")
46+
set(CMAKE_ASM_FLAGS_RELEASE "")
47+
set(CMAKE_C_FLAGS_RELEASE "-O2")
48+
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
49+
set(CMAKE_ASM_FLAGS_RELWITHDEBINFO "")
50+
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
51+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
52+
set(CMAKE_ASM_FLAGS_MINSIZEREL "")
53+
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
54+
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
55+
56+
# Setting the target for crosscompilation
57+
# https://stackoverflow.com/questions/54539682/how-to-set-up-cmake-to-cross-compile-with-clang-for-arm-embedded-on-windows
58+
set(CLANG_TARGET_TRIPLE arm-none-eabi)
59+
set(CMAKE_ASM_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
60+
set(CMAKE_C_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
61+
set(CMAKE_CXX_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
62+
63+
# Setting the include paths for system libraries
64+
include_directories(SYSTEM
65+
"/opt/arm-miosix-eabi/arm-miosix-eabi/include/c++/9.2.0/arm-miosix-eabi"
66+
"/opt/arm-miosix-eabi/arm-miosix-eabi/include/c++/9.2.0"
67+
"/opt/arm-miosix-eabi/arm-miosix-eabi/include"
68+
)
69+
70+
# We want to test for a static library and not an executable
71+
# reference: https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program
72+
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
73+
74+
# Defines used by the Miosix patches to the libraries/opt/arm-miosix-eabi/arm-miosix-eabi/lib/thumb/cm4/hardfp/fpv4sp
75+
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:__GXX_TYPEINFO_EQUALITY_INLINE=0>)
76+
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:_MIOSIX>)
77+
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:_MIOSIX_GCC_PATCH_MAJOR=3>)
78+
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:_MIOSIX_GCC_PATCH_MINOR=1>)
79+
80+
link_directories(SYSTEM
81+
# /opt/arm-miosix-eabi/arm-miosix-eabi/lib/thumb/cm4/hardfp/fpv4sp
82+
/opt/arm-miosix-eabi/lib/gcc/arm-miosix-eabi/9.2.0/thumb/cm4/hardfp/fpv4sp
83+
)
84+
set(CMAKE_SYSROOT
85+
/opt/arm-miosix-eabi/arm-miosix-eabi
86+
# # /opt/arm-miosix-eabi/lib/gcc/arm-miosix-eabi/9.2.0
87+
)
88+
# add_link_options("-fuse-ld=/usr/bin/arm-miosix-eabi-ld")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
MultilibVersion: 1.0
2+
3+
# The file is in two parts:
4+
# 1. A list of multilib variants.
5+
# 2. A list of regular expressions that may match flags generated from
6+
# command line options, and further flags that shall be added if the
7+
# regular expression matches.
8+
9+
# List of multilib variants.
10+
# Required.
11+
Variants:
12+
- Dir: thumb/cm0
13+
Flags: [-mthumb, -mcpu=cortex-m0]
14+
- Dir: thumb/cm3
15+
Flags: [-mthumb, -mcpu=cortex-m3]
16+
- Dir: thumb/cm3/pie/single-pic-base
17+
Flags: [-mthumb, -mcpu=cortex-m3, -fpie, -msingle-pic-base]
18+
- Dir: thumb/cm4/hardfp/fpv4sp
19+
Flags: [-mthumb, -mcpu=cortex-m4, -mfloat-abi=hard, -mfpu=fpv4-sp-d16]
20+
- Dir: thumb/cm4/hardfp/fpv4sp/pie/single-pic-base
21+
Flags: [-mthumb, -mcpu=cortex-m4, -mfloat-abi=hard, -mfpu=fpv4-sp-d16@fpie, -msingle-pic-base]
22+
- Dir: thumb/cm7/hardfp/fpv5
23+
Flags: [-mthumb, -mcpu=cortex-m7, -mfloat-abi=hard, -mfpu=fpv5-d16]
24+
- Dir: thumb/cm7/hardfp/fpv5/pie/single-pic-base
25+
Flags: [-mthumb, -mcpu=cortex-m7, -mfloat-abi=hard, -mfpu=fpv5-d16@fpie@msingle-pic-base]
26+
27+
# List of regular expressions that are used to map from flags generated
28+
# from command line options to custom flags.
29+
# This is optional.
30+
Mappings:

0 commit comments

Comments
 (0)