forked from arduino-cmake/arduino-cmake
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathArduinoToolchain.cmake
111 lines (97 loc) · 4.4 KB
/
ArduinoToolchain.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
99
100
101
102
103
104
105
106
107
108
109
#=============================================================================#
# Author: Tomasz Bogdal (QueezyTheGreat)
# Home: https://github.com/queezythegreat/arduino-cmake
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#=============================================================================#
if (_IS_TOOLCHAIN_PROCESSED)
return()
endif ()
set(_IS_TOOLCHAIN_PROCESSED True)
macro(dump_all)
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endmacro(dump_all)
IF(NOT DEFINED PLATFORM_ARCHITECTURE)
SET(PLATFORM_ARCHITECTURE "avr")
ENDIF(NOT DEFINED PLATFORM_ARCHITECTURE)
set(CMAKE_SYSTEM_NAME Arduino)
# Add current directory to CMake Module path automatically
IF(NOT DEFINED ARDUINO_CMAKE_TOP_FOLDER)
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/Platform/Arduino.cmake)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
endif ()
SET(ARDUINO_CMAKE_TOP_FOLDER ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
ENDIF(NOT DEFINED ARDUINO_CMAKE_TOP_FOLDER)
#=============================================================================#
# System Paths #
#=============================================================================#
if (CMAKE_HOST_UNIX)
include(Platform/UnixPaths)
if (CMAKE_HOST_APPLE)
list(APPEND CMAKE_SYSTEM_PREFIX_PATH ~/Applications
/Applications
/Developer/Applications
/sw # Fink
/opt/local) # MacPorts
endif ()
elseif (CMAKE_HOST_WIN32)
include(Platform/WindowsPaths)
endif ()
#=============================================================================#
# Detect Arduino SDK #
#=============================================================================#
if ((NOT ARDUINO_SDK_PATH) AND (NOT DEFINED ENV{_ARDUINO_CMAKE_WORKAROUND_ARDUINO_SDK_PATH}))
set(ARDUINO_PATHS)
foreach (DETECT_VERSION_MAJOR 1)
foreach (DETECT_VERSION_MINOR RANGE 5 0)
list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR})
foreach (DETECT_VERSION_PATCH RANGE 3 0)
list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR}.${DETECT_VERSION_PATCH})
endforeach ()
endforeach ()
endforeach ()
foreach (VERSION RANGE 23 19)
list(APPEND ARDUINO_PATHS arduino-00${VERSION})
endforeach ()
if (CMAKE_HOST_UNIX)
file(GLOB SDK_PATH_HINTS
/usr/share/arduino*
/opt/local/arduino*
/opt/arduino*
/usr/local/share/arduino*)
elseif (CMAKE_HOST_WIN32)
set(SDK_PATH_HINTS
"C:\\Program Files\\Arduino"
"C:\\Program Files (x86)\\Arduino")
endif ()
list(SORT SDK_PATH_HINTS)
list(REVERSE SDK_PATH_HINTS)
if (DEFINED ENV{ARDUINO_SDK_PATH})
list(APPEND SDK_PATH_HINTS $ENV{ARDUINO_SDK_PATH})
endif ()
find_path(ARDUINO_SDK_PATH
NAMES lib/version.txt
PATH_SUFFIXES share/arduino Arduino.app/Contents/Resources/Java/ Arduino.app/Contents/Java/ ${ARDUINO_PATHS}
HINTS ${SDK_PATH_HINTS}
DOC "Arduino SDK base directory")
elseif ((NOT ARDUINO_SDK_PATH) AND (DEFINED ENV{_ARDUINO_CMAKE_WORKAROUND_ARDUINO_SDK_PATH}))
set(ARDUINO_SDK_PATH "$ENV{_ARDUINO_CMAKE_WORKAROUND_ARDUINO_SDK_PATH}")
endif ()
MESSAGE(STATUS "Architecture is ${PLATFORM_ARCHITECTURE}, System is ${CMAKE_SYSTEM_NAME}")
STRING(TOUPPER "${PLATFORM_ARCHITECTURE}" upper_arch)
IF("${upper_arch}" MATCHES "STM32.*" )
SET(PLATFORM_ARCHITECTURE_POSTFIX "Stm32")
ELSEIF(PLATFORM_ARCHITECTURE STREQUAL "avr" )
SET(PLATFORM_ARCHITECTURE_POSTFIX "Avr")
ELSEIF(PLATFORM_ARCHITECTURE STREQUAL "ESP32" )
SET(PLATFORM_ARCHITECTURE_POSTFIX "Esp32")
ELSE(PLATFORM_ARCHITECTURE STREQUAL "ESP32" )
MESSAGE(FATAL_ERROR "Unknown architecture : ${PLATFORM_ARCHITECTURE} (${upper_arch})")
ENDIF("${upper_arch}" MATCHES "STM32.*" )
include(${CMAKE_CURRENT_LIST_DIR}/ArduinoToolchain${PLATFORM_ARCHITECTURE_POSTFIX}.cmake)