|
| 1 | +# Copyright (c) 2020 Arduino CMake Toolchain |
| 2 | + |
| 3 | +#============================================================================= |
| 4 | +# A toolchain for the Arduino compatile boards. |
| 5 | +# Please refer to README.md for the usage. |
| 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. |
| 22 | +# |
| 23 | +# Version below 3.7.0 has no support for CMAKE_SYSTEM_CUSTOM_CODE, which |
| 24 | +# is required when there is some dynamic information, like Board options, |
| 25 | +# that needs to be included in the toolchain. Here just including the user |
| 26 | +# provided path will not work, because the user variables, cache or root |
| 27 | +# binary directory path etc. are not passed to try_compile. |
| 28 | + |
| 29 | +if (CMAKE_VERSION VERSION_LESS 3.7.0) |
| 30 | + message(FATAL_ERROR "CMake version below 3.7.0 unsupported!!!") |
| 31 | +endif() |
| 32 | + |
| 33 | +# Save the policy state. We will restore it at the end. |
| 34 | +cmake_policy(PUSH) |
| 35 | + |
| 36 | +# Set policy to above 3.0.0 |
| 37 | +cmake_policy(VERSION 3.0.0) |
| 38 | + |
| 39 | +# Interpret if() arguments without quotes as variables/keywords |
| 40 | +if (NOT CMAKE_VERSION VERSION_LESS 3.1) |
| 41 | + cmake_policy(SET CMP0054 NEW) |
| 42 | +endif() |
| 43 | + |
| 44 | +#***************************************************************************** |
| 45 | +# Set system name and basic information |
| 46 | +set(CMAKE_SYSTEM_NAME "Arduino") |
| 47 | + |
| 48 | +# Set module path to enable local modules search |
| 49 | +set(ARDUINO_TOOLCHAIN_DIR "${CMAKE_CURRENT_LIST_DIR}") |
| 50 | +set(_ARDUINO_TOOLCHAIN_PARENT "${CMAKE_PARENT_LIST_FILE}") |
| 51 | +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_LIST_DIR}") |
| 52 | +set (ARDUINO_TOOLCHAIN_VERSION "1.0") |
| 53 | + |
| 54 | +# Include modules |
| 55 | +include(Arduino/System/BoardsIndex) |
| 56 | +include(Arduino/System/BoardToolchain) |
| 57 | +include(Arduino/System/BoardBuildTargets) |
| 58 | + |
| 59 | +#***************************************************************************** |
| 60 | +# For improved speed, indexing of boards is done only once during a |
| 61 | +# cmake invocation. However, this toolchain file is included multiple |
| 62 | +# times in multiple contexts (system determination context, separate |
| 63 | +# context for each try compile etc.). After indexing, the selected |
| 64 | +# board's toolchain info is configured to a generated file that gets |
| 65 | +# included in every other inclusion of this toolchain. |
| 66 | +if (NOT _BOARD_INDEXING_COMPLETED) |
| 67 | + get_property(_in_try_compile GLOBAL PROPERTY IN_TRY_COMPILE) |
| 68 | + # IN_TRY_COMPILE check seems to be not enough. Check for parent |
| 69 | + # script works, but may be undocumented! |
| 70 | + get_filename_component(parent_script "${_ARDUINO_TOOLCHAIN_PARENT}" |
| 71 | + NAME_WE) |
| 72 | + if (parent_script STREQUAL "CMakeSystem") |
| 73 | + check_board_options_changed(_b_changed) |
| 74 | + if (NOT _b_changed) |
| 75 | + set(_BOARD_INDEXING_COMPLETED TRUE) |
| 76 | + endif() |
| 77 | + endif() |
| 78 | +endif() |
| 79 | + |
| 80 | +if (NOT _BOARD_INDEXING_COMPLETED) |
| 81 | + SetupBoardToolchain() |
| 82 | + set(CMAKE_SYSTEM_CUSTOM_CODE |
| 83 | + "include(\"${CMAKE_BINARY_DIR}/ArduinoSystem.cmake\")" |
| 84 | + ) |
| 85 | + set (_BOARD_INDEXING_COMPLETED TRUE) |
| 86 | +endif() |
| 87 | + |
| 88 | +# Search for programs in the build host directories |
| 89 | +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH) |
| 90 | +# For libraries and headers in the target directories |
| 91 | +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 92 | +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| 93 | + |
| 94 | +# Do not try to link during the configure time, due to the dependency on the |
| 95 | +# core, which we do not have a target yet. |
| 96 | +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) |
| 97 | + |
| 98 | +cmake_policy(POP) |
0 commit comments