-
Notifications
You must be signed in to change notification settings - Fork 14
/
generate-gcc-cmake-toolchain.sh
executable file
·89 lines (74 loc) · 2.86 KB
/
generate-gcc-cmake-toolchain.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
## generate-gcc-cmake-toolchain.sh
#
# This generates a cmake-toolchains(7) file to configure CMake for
# cross-compiling with GCC.
#
# Docs: https://cmake.org/cmake/help/v3.15/manual/cmake-toolchains.7.html
set -e
set -x
set -o pipefail
if ! [ "$#" -ge 2 ]; then
echo "Usage: $0 <target> <prefix_dir> <cflags...>"
exit 2
fi;
## Take configuration from arguments
# This is the gcc target triple
toolchain_target="${1}"
# This is the directory where the toolchain has been installed.
toolchain_dest="${2}"
# Remaining cflags for build configurations
toolchain_cflags=("${@:3}")
cmake_cflags=""
for flag in "${toolchain_cflags[@]}"; do
if [ -z "${cmake_cflags}" ]; then
cmake_cflags+="${flag}";
else
cmake_cflags+=";${flag}"
fi
done
config_dest="${toolchain_dest}/${toolchain_target}-gcc.cmake"
sysroot_config=""
system_name=""
case "${toolchain_target}" in
riscv*-*-linux-gnu)
system_name="Linux"
sysroot_config="set(CMAKE_SYSROOT \"\${LOWRISC_TOOLCHAIN}/${toolchain_target}/sysroot\" CACHE STRING \"\" FORCE)";
;;
riscv*-*-elf)
system_name="Generic"
;;
esac;
tee "${config_dest}" <<CONFIG
# Autogenerated by ${0} on $(date -u)
# Problems? Bug reporting instructions in ${toolchain_dest}/buildinfo
#
# If you have relocated this toolchain, pass '-DLOWRISC_TOOLCHAIN=' to point to
# the new location of the toolchain when invoking CMake, before the -C argument
# which points to this file.
if(NOT LOWRISC_TOOLCHAIN)
set(LOWRISC_TOOLCHAIN "${toolchain_dest}")
endif()
set(CMAKE_SYSTEM_NAME "${system_name}")
set(CMAKE_SYSTEM_PROCESSOR ${toolchain_target%%-*})
${sysroot_config}
set(CMAKE_C_COMPILER "\${LOWRISC_TOOLCHAIN}/bin/${toolchain_target}-gcc" CACHE STRING "" FORCE)
set(CMAKE_C_COMPILER_TARGET "${toolchain_target}" CACHE STRING "" FORCE)
set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "\${LOWRISC_TOOLCHAIN}" CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS "${cmake_cflags}" CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER "\${LOWRISC_TOOLCHAIN}/bin/${toolchain_target}-g++" CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER_TARGET "${toolchain_target}" CACHE STRING "" FORCE)
set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "\${LOWRISC_TOOLCHAIN}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${cmake_cflags}" CACHE STRING "" FORCE)
set(CMAKE_ASM_COMPILER "\${LOWRISC_TOOLCHAIN}/bin/${toolchain_target}-as" CACHE STRING "" FORCE)
set(CMAKE_ASM_COMPILER_TARGET "${toolchain_target}" CACHE STRING "" FORCE)
set(CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN "\${LOWRISC_TOOLCHAIN}" CACHE STRING "" FORCE)
set(CMAKE_ASM_FLAGS "${cmake_cflags}" CACHE STRING "" FORCE)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
CONFIG