-
Notifications
You must be signed in to change notification settings - Fork 42
/
Arduino-toolchain.cmake
98 lines (84 loc) · 3.76 KB
/
Arduino-toolchain.cmake
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
90
91
92
93
94
95
96
97
98
# Copyright (c) 2020 Arduino CMake Toolchain
#=============================================================================
# A toolchain for the Arduino compatile boards.
# Please refer to README.md for the usage.
# If the version of CMake used is below 3.7.0, exit with error.
#
# Intended to support CMake version 3.0.0, but there are limitations which
# requires a minimum CMake version of 3.7.0. However, wherever possible, the
# toolchain remains compatible with 3.0.0, looking for some workarounds for
# the limitations in the future. The limitations are captured below.
#
# Version below 3.2.0 has no support for continue() command. Can be fixed.
#
# Version below 3.4.0 has no support for target properties BINARY_DIR,
# SOURCE_DIR etc. These are required in target command generator expressions.
#
# Version below 3.6.0 has issues in identifying try_compile output for
# static library. So there are some errors during the configuration, but
# may still possibly work.
#
# Version below 3.7.0 has no support for CMAKE_SYSTEM_CUSTOM_CODE, which
# is required when there is some dynamic information, like Board options,
# that needs to be included in the toolchain. Here just including the user
# provided path will not work, because the user variables, cache or root
# binary directory path etc. are not passed to try_compile.
if (CMAKE_VERSION VERSION_LESS 3.7.0)
message(FATAL_ERROR "CMake version below 3.7.0 unsupported!!!")
endif()
# Save the policy state. We will restore it at the end.
cmake_policy(PUSH)
# Set policy to above 3.0.0
cmake_policy(VERSION 3.0.0)
# Interpret if() arguments without quotes as variables/keywords
if (NOT CMAKE_VERSION VERSION_LESS 3.1)
cmake_policy(SET CMP0054 NEW)
endif()
#*****************************************************************************
# Set system name and basic information
set(CMAKE_SYSTEM_NAME "Arduino")
# Set module path to enable local modules search
set(ARDUINO_TOOLCHAIN_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(_ARDUINO_TOOLCHAIN_PARENT "${CMAKE_PARENT_LIST_FILE}")
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_LIST_DIR}")
set (ARDUINO_TOOLCHAIN_VERSION "1.0")
# Include modules
include(Arduino/System/BoardsIndex)
include(Arduino/System/BoardToolchain)
include(Arduino/System/BoardBuildTargets)
#*****************************************************************************
# For improved speed, indexing of boards is done only once during a
# cmake invocation. However, this toolchain file is included multiple
# times in multiple contexts (system determination context, separate
# context for each try compile etc.). After indexing, the selected
# board's toolchain info is configured to a generated file that gets
# included in every other inclusion of this toolchain.
if (NOT _BOARD_INDEXING_COMPLETED)
get_property(_in_try_compile GLOBAL PROPERTY IN_TRY_COMPILE)
# IN_TRY_COMPILE check seems to be not enough. Check for parent
# script works, but may be undocumented!
get_filename_component(parent_script "${_ARDUINO_TOOLCHAIN_PARENT}"
NAME_WE)
if (parent_script STREQUAL "CMakeSystem")
check_board_options_changed(_b_changed)
if (NOT _b_changed)
set(_BOARD_INDEXING_COMPLETED TRUE)
endif()
endif()
endif()
if (NOT _BOARD_INDEXING_COMPLETED)
SetupBoardToolchain()
set(CMAKE_SYSTEM_CUSTOM_CODE
"include(\"${CMAKE_BINARY_DIR}/ArduinoSystem.cmake\")"
)
set (_BOARD_INDEXING_COMPLETED TRUE)
endif()
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
# For libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# Do not try to link during the configure time, due to the dependency on the
# core, which we do not have a target yet.
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
cmake_policy(POP)