2 set(arm_none_eabi_triplet "arm-none-eabi")
4 # Keep version in sync with the distribution files below
5 set(arm_none_eabi_gcc_version "10.2.1")
6 set(arm_none_eabi_base_url "https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major")
8 set(arm_none_eabi_win32 "win32.zip" 5ee6542a2af847934177bc8fa1294c0d)
9 set(arm_none_eabi_linux_amd64 "x86_64-linux.tar.bz2" 8312c4c91799885f222f663fc81f9a31)
10 set(arm_none_eabi_linux_aarch64 "aarch64-linux.tar.bz2" 1c3b8944c026d50362eef1f01f329a8e)
11 set(arm_none_eabi_gcc_macos "mac.tar.bz2" e588d21be5a0cc9caa60938d2422b058)
13 function(arm_none_eabi_gcc_distname var)
14 string(REPLACE "/" ";" url_parts ${arm_none_eabi_base_url})
15 list(LENGTH url_parts n)
16 math(EXPR last "${n} - 1")
17 list(GET url_parts ${last} basename)
18 set(${var} ${basename} PARENT_SCOPE)
21 function(host_uname_machine var)
22 # We need to call uname -m manually, since at the point
23 # this file is included CMAKE_HOST_SYSTEM_PROCESSOR is
24 # empty because we haven't called project() yet.
25 execute_process(COMMAND uname -m
26 OUTPUT_STRIP_TRAILING_WHITESPACE
27 OUTPUT_VARIABLE machine)
29 set(${var} ${machine} PARENT_SCOPE)
32 function(arm_none_eabi_gcc_install)
34 if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
35 set(dist ${arm_none_eabi_win32})
36 elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD")
37 if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
38 message("-- no compiler binaries available for ${CMAKE_HOST_SYSTEM_NAME}, using Linux binaries as a fallback")
40 host_uname_machine(machine)
41 # Linux returns x86_64, FreeBSD returns amd64
42 if(machine STREQUAL "x86_64" OR machine STREQUAL "amd64")
43 set(dist ${arm_none_eabi_linux_amd64})
44 elseif(machine STREQUAL "aarch64")
45 set(dist ${arm_none_eabi_linux_aarch64})
47 message("-- no precompiled ${arm_none_eabi_triplet} toolchain for machine ${machine}")
49 elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
50 set(dist ${arm_none_eabi_gcc_macos})
54 message(FATAL_ERROR "could not install ${arm_none_eabi_triplet}-gcc automatically")
56 list(GET dist 0 dist_suffix)
57 list(GET dist 1 dist_checksum)
58 set(dist_url "${arm_none_eabi_base_url}-${dist_suffix}")
59 string(REPLACE "/" ";" url_parts ${dist_url})
60 list(LENGTH url_parts n)
61 math(EXPR last "${n} - 1")
62 list(GET url_parts ${last} basename)
63 set(output "${DOWNLOADS_DIR}/${basename}")
64 message("-- downloading ${arm_none_eabi_triplet}-gcc ${arm_none_eabi_gcc_version} from ${dist_url}")
65 file(DOWNLOAD ${dist_url} ${output}
69 EXPECTED_HASH MD5=${dist_checksum}
72 list(GET status 0 status_code)
73 if(NOT status_code EQUAL 0)
74 list(GET status 1 status_message)
75 message(FATAL_ERROR "error downloading ${basename}: ${status_message}")
77 message("-- extracting ${basename}")
78 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${TOOLS_DIR})
79 execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf ${output}
80 RESULT_VARIABLE status
81 WORKING_DIRECTORY ${TOOLS_DIR}
83 if(NOT status EQUAL 0)
84 message(FATAL_ERROR "error extracting ${basename}: ${status}")
88 function(arm_none_eabi_gcc_add_path)
89 arm_none_eabi_gcc_distname(dist_name)
90 set(gcc_path "${TOOLS_DIR}/${dist_name}/bin")
91 if(CMAKE_HOST_SYSTEM MATCHES ".*Windows.*")
96 set(ENV{PATH} "${gcc_path}${sep}$ENV{PATH}")
99 function(arm_none_eabi_gcc_check)
100 gcc_get_version(version
101 TRIPLET ${arm_none_eabi_triplet}
103 PROGRAM_PATH prog_path
106 message("-- could not find ${prog}")
107 arm_none_eabi_gcc_install()
110 message("-- found ${prog} ${version} at ${prog_path}")
111 if(COMPILER_VERSION_CHECK AND NOT arm_none_eabi_gcc_version STREQUAL version)
112 message("-- expecting ${prog} version ${arm_none_eabi_gcc_version}, but got version ${version} instead")
113 arm_none_eabi_gcc_install()
118 arm_none_eabi_gcc_add_path()
119 arm_none_eabi_gcc_check()