|
4 | 4 | # A toolchain for the Arduino compatile boards.
|
5 | 5 | # Please refer to README.md for the usage.
|
6 | 6 |
|
7 |
| -# If the version of CMake used is below 3.7.0, exit with error. |
8 |
| -# |
9 |
| -# Intended to support CMake version 3.0.0, but there are limitations which |
10 |
| -# requires a minimum CMake version of 3.7.0. However, wherever possible, the |
11 |
| -# toolchain remains compatible with 3.0.0, looking for some workarounds for |
12 |
| -# the limitations in the future. The limitations are captured below. |
13 |
| -# |
14 |
| -# Version below 3.2.0 has no support for continue() command. Can be fixed. |
15 |
| -# |
16 |
| -# Version below 3.4.0 has no support for target properties BINARY_DIR, |
17 |
| -# SOURCE_DIR etc. These are required in target command generator expressions. |
18 |
| -# |
19 |
| -# Version below 3.6.0 has issues in identifying try_compile output for |
20 |
| -# static library. So there are some errors during the configuration, but |
21 |
| -# may still possibly work. |
| 7 | +# If the version of CMake used is below 3.9, exit with error. |
| 8 | +# Version below 3.9.0 has no proper support for INTERPROCEDURAL_OPTIMIZATION. |
22 | 9 | #
|
23 | 10 | # Version below 3.7.0 has no support for CMAKE_SYSTEM_CUSTOM_CODE, which
|
24 | 11 | # is required when there is some dynamic information, like Board options,
|
25 | 12 | # that needs to be included in the toolchain. Here just including the user
|
26 | 13 | # provided path will not work, because the user variables, cache or root
|
27 | 14 | # binary directory path etc. are not passed to try_compile.
|
28 | 15 |
|
29 |
| -if (CMAKE_VERSION VERSION_LESS 3.7.0) |
30 |
| - message(FATAL_ERROR "CMake version below 3.7.0 unsupported!!!") |
| 16 | +#[[ |
| 17 | +CLang building works only with llvm toolchain. |
| 18 | +
|
| 19 | +todo: CMAKE_<LANG>_FLAGS_INIT¶ |
| 20 | +
|
| 21 | +USE_CLANG_AS_COMPILER - ON means CLang, OFF means GCC |
| 22 | +
|
| 23 | +GCC_COMPILERS_IN_USR_BIN - ON - GCC compilers are in /usr/bin, OFF - GCC compilers are in the dedicated dir |
| 24 | +GCC_PREFIX_DOUBLE_USE - ON - gcc compilers name begins with "target double", OFF - doesn't |
| 25 | +GCC_SUFFIX_VERSION_USE - ON means the tools will be called like gcc-11, OFF means tools will not have the postfix |
| 26 | +
|
| 27 | +LLVM_TOOLS_IN_USR_BIN - ON - LLVM compilers are in /usr/bin, OFF - LLVM compilers are in the dedicated dir |
| 28 | +LLVM_SUFFIX_VERSION_USE - ON means the tools will be called like llvm-readelf-14 and clang-14, OFF means tools will not have the postfix |
| 29 | +#]] |
| 30 | + |
| 31 | +cmake_minimum_required(VERSION 3.9 FATAL_ERROR) |
| 32 | + |
| 33 | +set(USE_CLANG_AS_COMPILER ON) |
| 34 | +#set(REST_OF_TOOLCHAIN_IS_LLVM ON) |
| 35 | +set(GCC_PREFIX_DOUBLE_USE ON) |
| 36 | +set(GCC_COMPILERS_IN_USR_BIN OFF) |
| 37 | +set(GCC_SUFFIX_VERSION_USE OFF) |
| 38 | + |
| 39 | + |
| 40 | +if(NOT DEFINED CMAKE_HOST_WIN32) |
| 41 | + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") |
| 42 | + set(CMAKE_HOST_WIN32 ON) |
| 43 | + else() |
| 44 | + set(CMAKE_HOST_WIN32 OFF) |
| 45 | + endif() |
| 46 | +endif() |
| 47 | + |
| 48 | +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") |
| 49 | + if(NOT DEFINED llvm_Version) |
| 50 | + set(llvm_Version 14) |
| 51 | + endif() |
| 52 | + |
| 53 | + if(NOT DEFINED LLVM_SUFFIX_VERSION_USE) |
| 54 | + set(LLVM_SUFFIX_VERSION_USE OFF) |
| 55 | + endif() |
| 56 | + if(NOT DEFINED GCC_PREFIX_DOUBLE_USE) |
| 57 | + set(GCC_PREFIX_DOUBLE_USE OFF) |
| 58 | + endif() |
| 59 | + if(NOT DEFINED GCC_SUFFIX_VERSION_USE) |
| 60 | + set(GCC_SUFFIX_VERSION_USE OFF) |
| 61 | + endif() |
| 62 | + if(NOT DEFINED GCC_SUFFIX_FLAVOUR_USE) |
| 63 | + set(GCC_SUFFIX_FLAVOUR_USE OFF) |
| 64 | + endif() |
| 65 | + |
| 66 | + get_filename_component(DUMP_DIR "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY) # CACHE PATH "The dir where we have unpacked CLang" |
| 67 | + message(STATUS "DUMP_DIR ${DUMP_DIR}") |
| 68 | +else() |
| 69 | + if(NOT DEFINED GCC_COMPILERS_IN_USR_BIN) |
| 70 | + set(GCC_COMPILERS_IN_USR_BIN ON) |
| 71 | + endif() |
| 72 | + |
| 73 | + if(NOT DEFINED LLVM_TOOLS_IN_USR_BIN) |
| 74 | + set(LLVM_TOOLS_IN_USR_BIN OFF) |
| 75 | + endif() |
| 76 | +endif() |
| 77 | + |
| 78 | +if(NOT DEFINED USE_CLANG_AS_COMPILER) |
| 79 | + message(FATAL_ERROR "Set USE_CLANG_AS_COMPILER into ON if you want to build with CLang(++) and into OFF if you want to build with G(CC|++).") |
| 80 | +endif() |
| 81 | + |
| 82 | +if(NOT DEFINED REST_OF_TOOLCHAIN_IS_LLVM) |
| 83 | + if(USE_CLANG_AS_COMPILER) |
| 84 | + set(REST_OF_TOOLCHAIN_IS_LLVM ON) |
| 85 | + else() |
| 86 | + set(REST_OF_TOOLCHAIN_IS_LLVM OFF) |
| 87 | + endif() |
| 88 | +endif() |
| 89 | + |
| 90 | + |
| 91 | +if(CMAKE_HOST_WIN32) |
| 92 | + set(GCC_COMPILERS_IN_USR_BIN OFF) |
| 93 | + set(LLVM_TOOLS_IN_USR_BIN OFF) |
| 94 | +else() |
| 95 | + if(NOT DEFINED GCC_COMPILERS_IN_USR_BIN) |
| 96 | + message(FATAL_ERROR "You must specify GCC_COMPILERS_IN_USR_BIN") |
| 97 | + endif() |
| 98 | +endif() |
| 99 | + |
| 100 | +if(NOT DEFINED LLVM_TOOLS_IN_USR_BIN) |
| 101 | + message(FATAL_ERROR "You must specify LLVM_TOOLS_IN_USR_BIN") |
| 102 | +endif() |
| 103 | + |
| 104 | +if(GCC_COMPILERS_IN_USR_BIN) |
| 105 | + if(NOT DEFINED GCC_PREFIX_DOUBLE_USE) |
| 106 | + set(GCC_PREFIX_DOUBLE_USE ON) |
| 107 | + endif() |
| 108 | + if(NOT DEFINED GCC_SUFFIX_VERSION_USE) |
| 109 | + set(GCC_SUFFIX_VERSION_USE OFF) |
| 110 | + endif() |
| 111 | +endif() |
| 112 | + |
| 113 | +if(NOT DEFINED GCC_PREFIX_DOUBLE_USE) |
| 114 | + message(FATAL_ERROR "You must specify GCC_PREFIX_DOUBLE_USE") |
31 | 115 | endif()
|
32 | 116 |
|
33 |
| -# Save the policy state. We will restore it at the end. |
34 |
| -cmake_policy(PUSH) |
| 117 | +if(NOT DEFINED GCC_SUFFIX_VERSION_USE) |
| 118 | + message(FATAL_ERROR "You must specify GCC_SUFFIX_VERSION_USE") |
| 119 | +endif() |
35 | 120 |
|
36 |
| -# Set policy to above 3.0.0 |
37 |
| -cmake_policy(VERSION 3.0.0) |
| 121 | +if(NOT DEFINED TOOLCHAIN_NAME) |
| 122 | + set(TOOLCHAIN_NAME "avr") |
| 123 | +endif() |
38 | 124 |
|
39 |
| -# Interpret if() arguments without quotes as variables/keywords |
40 |
| -if (NOT CMAKE_VERSION VERSION_LESS 3.1) |
41 |
| - cmake_policy(SET CMP0054 NEW) |
| 125 | +if(DEFINED ARDUINO_INSTALL_PATH) |
| 126 | + if(NOT DEFINED AVR_GCC_ROOT) |
| 127 | + set(AVR_GCC_ROOT "${ARDUINO_INSTALL_PATH}/hardware/tools/${TOOLCHAIN_NAME}") |
| 128 | + endif() |
42 | 129 | endif()
|
| 130 | +message(STATUS "AVR_GCC_ROOT ${AVR_GCC_ROOT}") |
| 131 | + |
| 132 | +if(REST_OF_TOOLCHAIN_IS_LLVM OR USE_CLANG_AS_COMPILER) |
| 133 | + if(NOT DEFINED LLVM_SUFFIX_VERSION_USE) |
| 134 | + if(LLVM_TOOLS_IN_USR_BIN) |
| 135 | + set(LLVM_SUFFIX_VERSION_USE ON) |
| 136 | + else() |
| 137 | + set(LLVM_SUFFIX_VERSION_USE OFF) |
| 138 | + endif() |
| 139 | + endif() |
| 140 | + |
| 141 | + if(NOT DEFINED llvm_Version) |
| 142 | + if(CMAKE_HOST_WIN32) |
| 143 | + message(FATAL_ERROR "You must specify LLVM version into llvm_Version. It is used to set the right additional flags for clang.") |
| 144 | + else() |
| 145 | + include("${CMAKE_CURRENT_LIST_DIR}/Arduino/System/DetectInstalledLLVMVersion.cmake") |
| 146 | + detect_llvm_version(llvm_Version LLVM_ROOT "/usr/lib") |
| 147 | + endif() |
| 148 | + endif() |
| 149 | + |
| 150 | + if(CMAKE_HOST_WIN32) |
| 151 | + if(NOT DEFINED LLVM_ROOT) |
| 152 | + if(DEFINED DUMP_DIR) |
| 153 | + set(LLVM_ROOT "${DUMP_DIR}/LLVM-${llvm_Version}.0.0-win32") |
| 154 | + else() |
| 155 | + message(FATAL_ERROR "You must set DUMP_DIR if you don't specify the full path to CLang base dir in LLVM_ROOT") # CACHE PATH "Path to Clang root" |
| 156 | + endif() |
| 157 | + endif() |
| 158 | + else() |
| 159 | + if(NOT DEFINED LLVM_ROOT) |
| 160 | + if(LLVM_TOOLS_IN_USR_BIN) |
| 161 | + set(LLVM_ROOT "") # CACHE PATH "Path to Clang root" |
| 162 | + else() |
| 163 | + set(LLVM_ROOT "/usr/lib/llvm-${llvm_Version}") # CACHE PATH "Path to Clang root" |
| 164 | + endif() |
| 165 | + endif() |
| 166 | + endif() |
| 167 | + |
| 168 | + if(NOT DEFINED LLVM_SUFFIX_VERSION_USE) |
| 169 | + message(FATAL_ERROR "You must specify LLVM_SUFFIX_VERSION_USE") |
| 170 | + endif() |
| 171 | + |
| 172 | + if(NOT DEFINED AVR_GCC_ROOT) |
| 173 | + set(AVR_GCC_ROOT "/usr/${double}") |
| 174 | + endif()# CACHE PATH "Path to MinGW root" |
| 175 | + |
| 176 | + message(STATUS "CLang root: ${LLVM_ROOT}") |
| 177 | + message(STATUS "AVR GCC root: ${AVR_GCC_ROOT}") |
| 178 | +endif() |
| 179 | + |
43 | 180 |
|
44 | 181 | #*****************************************************************************
|
45 | 182 | # Set system name and basic information
|
@@ -97,5 +234,3 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/build_opt.h" "")
|
97 | 234 | # Do not try to link during the configure time, due to the dependency on the
|
98 | 235 | # core, which we do not have a target yet.
|
99 | 236 | set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
100 |
| - |
101 |
| -cmake_policy(POP) |
|
0 commit comments