diff --git a/CMakeLists.txt b/CMakeLists.txt index 755e3d2..fce5da6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,16 +5,23 @@ # Description: Arduino CMake example # # # #=============================================================================# -set(CMAKE_TOOLCHAIN_FILE cmake/ArduinoToolchain.cmake) # Arduino Toolchain +cmake_minimum_required(VERSION 2.8) +project(ARDUINO C CXX) +# ----------------------------------------------------------------------------- +# Enable SuperBuild option +# ----------------------------------------------------------------------------- +option(ARDUINO_SUPERBUILD "Superbuild option." ON) + +if(ARDUINO_SUPERBUILD) + include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SuperBuild.cmake) + return() +endif(ARDUINO_SUPERBUILD) -cmake_minimum_required(VERSION 2.8) #====================================================================# # Setup Project # #====================================================================# -project(ArduinoExample C CXX) - print_board_list() print_programmer_list() - +# add_subdirectory(example) #add the example directory into build diff --git a/cmake/ArduinoToolchain.cmake b/cmake/ArduinoToolchain.cmake deleted file mode 100644 index 16e4037..0000000 --- a/cmake/ArduinoToolchain.cmake +++ /dev/null @@ -1,76 +0,0 @@ -#=============================================================================# -# 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/. -#=============================================================================# -set(CMAKE_SYSTEM_NAME Arduino) - -set(CMAKE_C_COMPILER avr-gcc) -set(CMAKE_CXX_COMPILER avr-g++) - -# Add current directory to CMake Module path automatically -if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/Platform/Arduino.cmake) - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}) -endif() - -#=============================================================================# -# System Paths # -#=============================================================================# -if(UNIX) - include(Platform/UnixPaths) - if(APPLE) - list(APPEND CMAKE_SYSTEM_PREFIX_PATH ~/Applications - /Applications - /Developer/Applications - /sw # Fink - /opt/local) # MacPorts - endif() -elseif(WIN32) - include(Platform/WindowsPaths) -endif() - - -#=============================================================================# -# Detect Arduino SDK # -#=============================================================================# -if(NOT 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() - - file(GLOB SDK_PATH_HINTS /usr/share/arduino* - /opt/local/arduino* - /opt/arduino* - /usr/local/share/arduino*) - list(SORT SDK_PATH_HINTS) - list(REVERSE SDK_PATH_HINTS) -endif() - -find_path(ARDUINO_SDK_PATH - NAMES lib/version.txt - PATH_SUFFIXES share/arduino - Arduino.app/Contents/Resources/Java/ - ${ARDUINO_PATHS} - HINTS ${SDK_PATH_HINTS} - DOC "Arduino SDK path.") - -if(ARDUINO_SDK_PATH) - list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr/bin) - list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr/utils/bin) -else() - message(FATAL_ERROR "Could not find Arduino SDK (set ARDUINO_SDK_PATH)!") -endif() diff --git a/cmake/Platform/Arduino.cmake b/cmake/Platform/Arduino.cmake index 2eb97e3..9fb8905 100644 --- a/cmake/Platform/Arduino.cmake +++ b/cmake/Platform/Arduino.cmake @@ -285,11 +285,6 @@ cmake_minimum_required(VERSION 2.8.5) include(CMakeParseArguments) - - - - - #=============================================================================# # User Functions #=============================================================================# @@ -400,7 +395,6 @@ function(GENERATE_ARDUINO_LIBRARY INPUT_NAME) set_target_properties(${INPUT_NAME} PROPERTIES COMPILE_FLAGS "${ARDUINO_COMPILE_FLAGS} ${COMPILE_FLAGS} ${LIB_DEP_INCLUDES}" LINK_FLAGS "${ARDUINO_LINK_FLAGS} ${LINK_FLAGS}") - target_link_libraries(${INPUT_NAME} ${ALL_LIBS} "-lc -lm") endfunction() @@ -1447,7 +1441,6 @@ function(detect_arduino_version VAR_NAME) elseif("${RAW_VERSION}" MATCHES "[ ]*([0-9]+[.][0-9]+)") set(PARSED_VERSION ${CMAKE_MATCH_1}.0) endif() - if(NOT PARSED_VERSION STREQUAL "") string(REPLACE "." ";" SPLIT_VERSION ${PARSED_VERSION}) list(GET SPLIT_VERSION 0 SPLIT_VERSION_MAJOR) @@ -2038,11 +2031,6 @@ function(ERROR_FOR_UNPARSED PREFIX) endif() endfunction() - - - - - #=============================================================================# # C Flags #=============================================================================# @@ -2105,6 +2093,7 @@ set(ARDUINO_AVRDUDE_FLAGS -V CACHE STRING "") #=============================================================================# # Initialization #=============================================================================# + if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH) register_hardware_platform(${ARDUINO_SDK_PATH}/hardware/arduino/) @@ -2158,18 +2147,20 @@ if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH) AVRSIZE_PROGRAM MSG "Invalid Arduino SDK path (${ARDUINO_SDK_PATH}).\n") - detect_arduino_version(ARDUINO_SDK_VERSION) - set(ARDUINO_SDK_VERSION ${ARDUINO_SDK_VERSION} CACHE STRING "Arduino SDK Version") - set(ARDUINO_SDK_VERSION_MAJOR ${ARDUINO_SDK_VERSION_MAJOR} CACHE STRING "Arduino SDK Major Version") - set(ARDUINO_SDK_VERSION_MINOR ${ARDUINO_SDK_VERSION_MINOR} CACHE STRING "Arduino SDK Minor Version") - set(ARDUINO_SDK_VERSION_PATCH ${ARDUINO_SDK_VERSION_PATCH} CACHE STRING "Arduino SDK Patch Version") + if(NOT ARDUINO_SDK_VERSION) + detect_arduino_version(ARDUINO_SDK_VERSION) + set(ARDUINO_SDK_VERSION ${ARDUINO_SDK_VERSION} CACHE STRING "Arduino SDK Version") + set(ARDUINO_SDK_VERSION_MAJOR ${ARDUINO_SDK_VERSION_MAJOR} CACHE STRING "Arduino SDK Major Version") + set(ARDUINO_SDK_VERSION_MINOR ${ARDUINO_SDK_VERSION_MINOR} CACHE STRING "Arduino SDK Minor Version") + set(ARDUINO_SDK_VERSION_PATCH ${ARDUINO_SDK_VERSION_PATCH} CACHE STRING "Arduino SDK Patch Version") + endif() if(ARDUINO_SDK_VERSION VERSION_LESS 0.19) message(FATAL_ERROR "Unsupported Arduino SDK (require verion 0.19 or higher)") endif() message(STATUS "Arduino SDK version ${ARDUINO_SDK_VERSION}: ${ARDUINO_SDK_PATH}") - + setup_arduino_size_script(ARDUINO_SIZE_SCRIPT) set(ARDUINO_SIZE_SCRIPT ${ARDUINO_SIZE_SCRIPT} CACHE INTERNAL "Arduino Size Script") diff --git a/cmake/SuperBuild.cmake b/cmake/SuperBuild.cmake new file mode 100644 index 0000000..869e189 --- /dev/null +++ b/cmake/SuperBuild.cmake @@ -0,0 +1,146 @@ +########################################################################### +# +# Copyright (c) Kitware Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +########################################################################### + +set(ARDUINO_DEPENDENCIES ARDUINO_SDK AVRDUDE) + +#----------------------------------------------------------------------------- +# WARNING - No change should be required after this comment +# when you are adding a new external project dependency. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Needed to build the arduino sdk sources +#----------------------------------------------------------------------------- +find_program(PATCH_EXECUTABLE patch) + +# ----------------------------------------------------------------------------- +# Path to ARDUINO cmake modules +# ----------------------------------------------------------------------------- +set(ARDUINO_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +#----------------------------------------------------------------------------- +# Update CMake module path +# +set(CMAKE_MODULE_PATH ${ARDUINO_MODULE_PATH} ${ARDUINO_MODULE_PATH}) + +#----------------------------------------------------------------------------- +# Enable and setup External project global properties +# +include(ExternalProject) +include(SuperBuild/CheckExternalProjectDependency) +include(SuperBuild/Versions) + +set(ep_install_dir ${CMAKE_BINARY_DIR}/SuperBuild) +set(ep_suffix "-cmake") + +set(ep_common_c_flags "${CMAKE_C_FLAGS_INIT} ${ADDITIONAL_C_FLAGS}") +set(ep_common_cxx_flags "${CMAKE_CXX_FLAGS_INIT} ${ADDITIONAL_CXX_FLAGS}") + +# Compute -G arg for configuring external projects with the same CMake generator: +if(CMAKE_EXTRA_GENERATOR) + set(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}") +else() + set(gen "${CMAKE_GENERATOR}") +endif() + +# This variable will contain the list of CMake variable specific to each external project +# that should passed to ARDUINO. +# The item of this list should have the following form: -D_DIR:PATH=${_DIR} +# where '' is an external project name. +set(ARDUINO_SUPERBUILD_EP_ARGS) + +CheckExternalProjectDependency(ARDUINO) + +#----------------------------------------------------------------------------- +# Makes sure ${CMAKE_BINARY_DIR}/bin and ${CMAKE_BINARY_DIR}/lib exists +#----------------------------------------------------------------------------- +IF(NOT EXISTS ${CMAKE_BINARY_DIR}/bin) + FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +ENDIF() +IF(NOT EXISTS ${CMAKE_BINARY_DIR}/lib) + FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +ENDIF() + +#----------------------------------------------------------------------------- +# Set CMake OSX variable to pass down the external project +#----------------------------------------------------------------------------- +set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS) +if(APPLE) + list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}) +endif() + +#----------------------------------------------------------------------------- +# ARDUINO Configure +#----------------------------------------------------------------------------- +ExternalProject_Add(ARDUINO-Configure + SOURCE_DIR ${ARDUINO_SOURCE_DIR} + BINARY_DIR ${CMAKE_BINARY_DIR}/ARDUINO-build + DOWNLOAD_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + CMAKE_GENERATOR ${gen} + CMAKE_ARGS + -DCMAKE_SYSTEM_NAME=Arduino + ${CMAKE_OSX_EXTERNAL_PROJECT_ARGS} + -DARDUINO_SUPERBUILD:BOOL=OFF + -DARDUINO_SDK_VERSION:STRING=${ARDUINO_MAJOR}.${ARDUINO_MINOR}.${ARDUINO_PATCH} + -DARDUINO_SDK_VERSION_MAJOR:STRING=${ARDUINO_MAJOR} + -ARDUINO_SDK_VERSION_MINOR:STRING=${ARDUINO_MINOR} + -DARDUINO_SDK_VERSION_PATCH:STRING=${ARDUINO_PATCH} + -DCMAKE_MODULE_PATH:PATH=${ARDUINO_MODULE_PATH} + -DCMAKE_FIND_ROOT_PATH=${CMAKE_FIND_ROOT_PATH} + -DCMAKE_PREFIX_PATH:PATH=${ep_install_dir}/avr + -DCMAKE_INCLUDE_PATH:PATH=${ep_install_dir}/etc + ${ARDUINO_SUPERBUILD_EP_ARGS} + + DEPENDS + ${ARDUINO_DEPENDENCIES} + ) + +if(CMAKE_GENERATOR MATCHES ".*Makefiles.*") + set(arduino_build_cmd "$(MAKE)") +else() + set(arduino_build_cmd ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/ARDUINO-build --config ${CMAKE_CFG_INTDIR}) +endif() + +# #----------------------------------------------------------------------------- +# # ARDUINO +# # +if(NOT DEFINED SUPERBUILD_EXCLUDE_ARDUINO_BUILD_TARGET OR NOT SUPERBUILD_EXCLUDE_ARDUINO_BUILD_TARGET) + set(ARDUINO_BUILD_TARGET_ALL_OPTION "ALL") +else() + set(ARDUINO_BUILD_TARGET_ALL_OPTION "") +endif() + +add_custom_target(ARDUINO-Build ${ARDUINO_BUILD_TARGET_ALL_OPTION} + COMMAND ${arduino_build_cmd} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ARDUINO-build + ) +add_dependencies(ARDUINO-Build ARDUINO-Configure ) + +# #----------------------------------------------------------------------------- +# # Custom target allowing to drive the build of ARDUINO project itself +# # +add_custom_target(ARDUINO + COMMAND ${arduino_build_cmd} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/ARDUINO-build + ) + diff --git a/cmake/SuperBuild/30-binutils-2.20.1-avr-size.patch b/cmake/SuperBuild/30-binutils-2.20.1-avr-size.patch new file mode 100644 index 0000000..6bb152b --- /dev/null +++ b/cmake/SuperBuild/30-binutils-2.20.1-avr-size.patch @@ -0,0 +1,521 @@ +AVR specific only +=========================================================== +--- binutils/size.c 2007-08-06 13:56:14.000000000 -0600 ++++ binutils/size.c 2007-09-13 09:13:10.281250000 -0600 +@@ -36,10 +36,31 @@ + #include "getopt.h" + #include "bucomm.h" + +-#ifndef BSD_DEFAULT +-#define BSD_DEFAULT 1 ++typedef enum ++{ ++ format_sysv = 0, ++ format_bsd = 1, ++ format_avr = 2, ++} format_type_t; ++ ++ ++/* Set the default format. */ ++#define FORMAT_DEFAULT_SYSV 0 ++#define FORMAT_DEFAULT_BSD 1 ++#define FORMAT_DEFAULT_AVR 0 ++ ++#if FORMAT_DEFAULT_SYSV ++ #define FORMAT_DEFAULT format_sysv ++ #define FORMAT_NAME "sysv" ++#elif FORMAT_DEFAULT_BSD ++ #define FORMAT_DEFAULT format_bsd ++ #define FORMAT_NAME "berkeley" ++#elif FORMAT_DEFAULT_AVR ++ #define FORMAT_DEFAULT format_avr ++ #define FORMAT_NAME "avr" + #endif + ++ + /* Program options. */ + + static enum +@@ -48,9 +69,8 @@ static enum + } + radix = decimal; + +-/* 0 means use AT&T-style output. */ +-static int berkeley_format = BSD_DEFAULT; + ++format_type_t format = FORMAT_DEFAULT; + static int show_version = 0; + static int show_help = 0; + static int show_totals = 0; +@@ -64,6 +84,246 @@ static bfd_size_type total_textsize; + /* Program exit status. */ + static int return_code = 0; + ++ ++/* AVR Size specific stuff */ ++ ++#define AVR64 64UL ++#define AVR128 128UL ++#define AVR256 256UL ++#define AVR512 512UL ++#define AVR1K 1024UL ++#define AVR2K 2048UL ++#define AVR4K 4096UL ++#define AVR8K 8192UL ++#define AVR16K 16384UL ++#define AVR20K 20480UL ++#define AVR24K 24576UL ++#define AVR32K 32768UL ++#define AVR36K 36864UL ++#define AVR40K 40960UL ++#define AVR64K 65536UL ++#define AVR68K 69632UL ++#define AVR128K 131072UL ++#define AVR136K 139264UL ++#define AVR200K 204800UL ++#define AVR256K 262144UL ++#define AVR264K 270336UL ++ ++typedef struct ++{ ++ char *name; ++ long flash; ++ long ram; ++ long eeprom; ++} avr_device_t; ++ ++avr_device_t avr[] = ++{ ++ {"atxmega256a3", AVR264K, AVR16K, AVR4K}, ++ {"atxmega256a3b", AVR264K, AVR16K, AVR4K}, ++ {"atxmega256d3", AVR264K, AVR16K, AVR4K}, ++ ++ {"atmega2560", AVR256K, AVR8K, AVR4K}, ++ {"atmega2561", AVR256K, AVR8K, AVR4K}, ++ ++ {"atxmega192a3", AVR200K, AVR16K, AVR2K}, ++ {"atxmega192d3", AVR200K, AVR16K, AVR2K}, ++ ++ {"atxmega128a1", AVR136K, AVR8K, AVR2K}, ++ {"atxmega128a1u", AVR136K, AVR8K, AVR2K}, ++ {"atxmega128a3", AVR136K, AVR8K, AVR2K}, ++ {"atxmega128d3", AVR136K, AVR8K, AVR2K}, ++ ++ {"at43usb320", AVR128K, 608UL, 0UL}, ++ {"at90can128", AVR128K, AVR4K, AVR4K}, ++ {"at90usb1286", AVR128K, AVR8K, AVR4K}, ++ {"at90usb1287", AVR128K, AVR8K, AVR4K}, ++ {"atmega128", AVR128K, AVR4K, AVR4K}, ++ {"atmega1280", AVR128K, AVR8K, AVR4K}, ++ {"atmega1281", AVR128K, AVR8K, AVR4K}, ++ {"atmega1284p", AVR128K, AVR16K, AVR4K}, ++ {"atmega128rfa1", AVR128K, AVR16K, AVR4K}, ++ {"atmega103", AVR128K, 4000UL, AVR4K}, ++ ++ {"atxmega64a1", AVR68K, AVR4K, AVR2K}, ++ {"atxmega64a1u", AVR68K, AVR4K, AVR2K}, ++ {"atxmega64a3", AVR68K, AVR4K, AVR2K}, ++ {"atxmega64d3", AVR68K, AVR4K, AVR2K}, ++ ++ {"at90can64", AVR64K, AVR4K, AVR2K}, ++ {"at90scr100", AVR64K, AVR4K, AVR2K}, ++ {"at90usb646", AVR64K, AVR4K, AVR2K}, ++ {"at90usb647", AVR64K, AVR4K, AVR2K}, ++ {"atmega64", AVR64K, AVR4K, AVR2K}, ++ {"atmega640", AVR64K, AVR8K, AVR4K}, ++ {"atmega644", AVR64K, AVR4K, AVR2K}, ++ {"atmega644a", AVR64K, AVR4K, AVR2K}, ++ {"atmega644p", AVR64K, AVR4K, AVR2K}, ++ {"atmega644pa", AVR64K, AVR4K, AVR2K}, ++ {"atmega645", AVR64K, AVR4K, AVR2K}, ++ {"atmega645a", AVR64K, AVR4K, AVR2K}, ++ {"atmega645p", AVR64K, AVR4K, AVR2K}, ++ {"atmega6450", AVR64K, AVR4K, AVR2K}, ++ {"atmega6450a", AVR64K, AVR4K, AVR2K}, ++ {"atmega6450p", AVR64K, AVR4K, AVR2K}, ++ {"atmega649", AVR64K, AVR4K, AVR2K}, ++ {"atmega649a", AVR64K, AVR4K, AVR2K}, ++ {"atmega649p", AVR64K, AVR4K, AVR2K}, ++ {"atmega6490", AVR64K, AVR4K, AVR2K}, ++ {"atmega6490a", AVR64K, AVR4K, AVR2K}, ++ {"atmega6490p", AVR64K, AVR4K, AVR2K}, ++ {"atmega64c1", AVR64K, AVR4K, AVR2K}, ++ {"atmega64hve", AVR64K, AVR4K, AVR1K}, ++ {"atmega64m1", AVR64K, AVR4K, AVR2K}, ++ {"m3000", AVR64K, AVR4K, 0UL}, ++ ++ {"atmega406", AVR40K, AVR2K, AVR512}, ++ ++ {"atxmega32a4", AVR36K, AVR4K, AVR1K}, ++ {"atxmega32d4", AVR36K, AVR4K, AVR1K}, ++ ++ {"at90can32", AVR32K, AVR2K, AVR1K}, ++ {"at94k", AVR32K, AVR4K, 0UL}, ++ {"atmega32", AVR32K, AVR2K, AVR1K}, ++ {"atmega323", AVR32K, AVR2K, AVR1K}, ++ {"atmega324a", AVR32K, AVR2K, AVR1K}, ++ {"atmega324p", AVR32K, AVR2K, AVR1K}, ++ {"atmega324pa", AVR32K, AVR2K, AVR1K}, ++ {"atmega325", AVR32K, AVR2K, AVR1K}, ++ {"atmega325a", AVR32K, AVR2K, AVR1K}, ++ {"atmega325p", AVR32K, AVR2K, AVR1K}, ++ {"atmega3250", AVR32K, AVR2K, AVR1K}, ++ {"atmega3250a", AVR32K, AVR2K, AVR1K}, ++ {"atmega3250p", AVR32K, AVR2K, AVR1K}, ++ {"atmega328", AVR32K, AVR2K, AVR1K}, ++ {"atmega328p", AVR32K, AVR2K, AVR1K}, ++ {"atmega329", AVR32K, AVR2K, AVR1K}, ++ {"atmega329a", AVR32K, AVR2K, AVR1K}, ++ {"atmega329p", AVR32K, AVR2K, AVR1K}, ++ {"atmega329pa", AVR32K, AVR2K, AVR1K}, ++ {"atmega3290", AVR32K, AVR2K, AVR1K}, ++ {"atmega3290a", AVR32K, AVR2K, AVR1K}, ++ {"atmega3290p", AVR32K, AVR2K, AVR1K}, ++ {"atmega32hvb", AVR32K, AVR2K, AVR1K}, ++ {"atmega32c1", AVR32K, AVR2K, AVR1K}, ++ {"atmega32hvb", AVR32K, AVR2K, AVR1K}, ++ {"atmega32m1", AVR32K, AVR2K, AVR1K}, ++ {"atmega32u2", AVR32K, AVR1K, AVR1K}, ++ {"atmega32u4", AVR32K, 2560UL, AVR1K}, ++ {"atmega32u6", AVR32K, 2560UL, AVR1K}, ++ ++ {"at43usb355", AVR24K, 1120UL, 0UL}, ++ ++ {"atxmega16a4", AVR20K, AVR2K, AVR1K}, ++ {"atxmega16d4", AVR20K, AVR2K, AVR1K}, ++ ++ {"at76c711", AVR16K, AVR2K, 0UL}, ++ {"at90pwm216", AVR16K, AVR1K, AVR512}, ++ {"at90pwm316", AVR16K, AVR1K, AVR512}, ++ {"at90usb162", AVR16K, AVR512, AVR512}, ++ {"atmega16", AVR16K, AVR1K, AVR512}, ++ {"atmega16a", AVR16K, AVR1K, AVR512}, ++ {"atmega161", AVR16K, AVR1K, AVR512}, ++ {"atmega162", AVR16K, AVR1K, AVR512}, ++ {"atmega163", AVR16K, AVR1K, AVR512}, ++ {"atmega164", AVR16K, AVR1K, AVR512}, ++ {"atmega164a", AVR16K, AVR1K, AVR512}, ++ {"atmega164p", AVR16K, AVR1K, AVR512}, ++ {"atmega165a", AVR16K, AVR1K, AVR512}, ++ {"atmega165", AVR16K, AVR1K, AVR512}, ++ {"atmega165p", AVR16K, AVR1K, AVR512}, ++ {"atmega168", AVR16K, AVR1K, AVR512}, ++ {"atmega168a", AVR16K, AVR1K, AVR512}, ++ {"atmega168p", AVR16K, AVR1K, AVR512}, ++ {"atmega169", AVR16K, AVR1K, AVR512}, ++ {"atmega169a", AVR16K, AVR1K, AVR512}, ++ {"atmega169p", AVR16K, AVR1K, AVR512}, ++ {"atmega169pa", AVR16K, AVR1K, AVR512}, ++ {"atmega16hva", AVR16K, 768UL, AVR256}, ++ {"atmega16hva2", AVR16K, AVR1K, AVR256}, ++ {"atmega16hvb", AVR16K, AVR1K, AVR512}, ++ {"atmega16m1", AVR16K, AVR1K, AVR512}, ++ {"atmega16u2", AVR16K, AVR512, AVR512}, ++ {"atmega16u4", AVR16K, 1280UL, AVR512}, ++ {"attiny167", AVR16K, AVR512, AVR512}, ++ ++ {"at90c8534", AVR8K, 352UL, AVR512}, ++ {"at90pwm1", AVR8K, AVR512, AVR512}, ++ {"at90pwm2", AVR8K, AVR512, AVR512}, ++ {"at90pwm2b", AVR8K, AVR512, AVR512}, ++ {"at90pwm3", AVR8K, AVR512, AVR512}, ++ {"at90pwm3b", AVR8K, AVR512, AVR512}, ++ {"at90pwm81", AVR8K, AVR256, AVR512}, ++ {"at90s8515", AVR8K, AVR512, AVR512}, ++ {"at90s8535", AVR8K, AVR512, AVR512}, ++ {"at90usb82", AVR8K, AVR512, AVR512}, ++ {"ata6289", AVR8K, AVR512, 320UL}, ++ {"atmega8", AVR8K, AVR1K, AVR512}, ++ {"atmega8515", AVR8K, AVR512, AVR512}, ++ {"atmega8535", AVR8K, AVR512, AVR512}, ++ {"atmega88", AVR8K, AVR1K, AVR512}, ++ {"atmega88a", AVR8K, AVR1K, AVR512}, ++ {"atmega88p", AVR8K, AVR1K, AVR512}, ++ {"atmega88pa", AVR8K, AVR1K, AVR512}, ++ {"atmega8hva", AVR8K, 768UL, AVR256}, ++ {"atmega8u2", AVR8K, AVR512, AVR512}, ++ {"attiny84", AVR8K, AVR512, AVR512}, ++ {"attiny84a", AVR8K, AVR512, AVR512}, ++ {"attiny85", AVR8K, AVR512, AVR512}, ++ {"attiny861", AVR8K, AVR512, AVR512}, ++ {"attiny861a", AVR8K, AVR512, AVR512}, ++ {"attiny87", AVR8K, AVR512, AVR512}, ++ {"attiny88", AVR8K, AVR512, AVR64}, ++ ++ {"at90s4414", AVR4K, 352UL, AVR256}, ++ {"at90s4433", AVR4K, AVR128, AVR256}, ++ {"at90s4434", AVR4K, 352UL, AVR256}, ++ {"atmega48", AVR4K, AVR512, AVR256}, ++ {"atmega48a", AVR4K, AVR512, AVR256}, ++ {"atmega48p", AVR4K, AVR512, AVR256}, ++ {"attiny4313", AVR4K, AVR256, AVR256}, ++ {"attiny43u", AVR4K, AVR256, AVR64}, ++ {"attiny44", AVR4K, AVR256, AVR256}, ++ {"attiny44a", AVR4K, AVR256, AVR256}, ++ {"attiny45", AVR4K, AVR256, AVR256}, ++ {"attiny461", AVR4K, AVR256, AVR256}, ++ {"attiny461a", AVR4K, AVR256, AVR256}, ++ {"attiny48", AVR4K, AVR256, AVR64}, ++ ++ {"at86rf401", AVR2K, 224UL, AVR128}, ++ {"at90s2313", AVR2K, AVR128, AVR128}, ++ {"at90s2323", AVR2K, AVR128, AVR128}, ++ {"at90s2333", AVR2K, 224UL, AVR128}, ++ {"at90s2343", AVR2K, AVR128, AVR128}, ++ {"attiny20", AVR2K, AVR128, 0UL}, ++ {"attiny22", AVR2K, 224UL, AVR128}, ++ {"attiny2313", AVR2K, AVR128, AVR128}, ++ {"attiny2313a", AVR2K, AVR128, AVR128}, ++ {"attiny24", AVR2K, AVR128, AVR128}, ++ {"attiny24a", AVR2K, AVR128, AVR128}, ++ {"attiny25", AVR2K, AVR128, AVR128}, ++ {"attiny26", AVR2K, AVR128, AVR128}, ++ {"attiny261", AVR2K, AVR128, AVR128}, ++ {"attiny261a", AVR2K, AVR128, AVR128}, ++ {"attiny28", AVR2K, 0UL, 0UL}, ++ {"attiny40", AVR2K, AVR256, 0UL}, ++ ++ {"at90s1200", AVR1K, 0UL, AVR64}, ++ {"attiny9", AVR1K, 32UL, 0UL}, ++ {"attiny10", AVR1K, 32UL, 0UL}, ++ {"attiny11", AVR1K, 0UL, AVR64}, ++ {"attiny12", AVR1K, 0UL, AVR64}, ++ {"attiny13", AVR1K, AVR64, AVR64}, ++ {"attiny13a", AVR1K, AVR64, AVR64}, ++ {"attiny15", AVR1K, 0UL, AVR64}, ++ ++ {"attiny4", AVR512, 32UL, 0UL}, ++ {"attiny5", AVR512, 32UL, 0UL}, ++}; ++ ++static char *avrmcu = NULL; ++ ++ + static char *target = NULL; + + /* Forward declarations. */ +@@ -79,7 +337,8 @@ usage (FILE *stream, int status) + fprintf (stream, _(" Displays the sizes of sections inside binary files\n")); + fprintf (stream, _(" If no input file(s) are specified, a.out is assumed\n")); + fprintf (stream, _(" The options are:\n\ +- -A|-B --format={sysv|berkeley} Select output style (default is %s)\n\ ++ -A|-B|-C --format={sysv|berkeley|avr} Select output style (default is %s)\n\ ++ --mcu= MCU name for AVR format only\n\ + -o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex\n\ + -t --totals Display the total sizes (Berkeley only)\n\ + --common Display total size for *COM* syms\n\ +@@ -88,11 +337,7 @@ usage (FILE *stream, int status) + -h --help Display this information\n\ + -v --version Display the program's version\n\ + \n"), +-#if BSD_DEFAULT +- "berkeley" +-#else +- "sysv" +-#endif ++FORMAT_NAME + ); + list_supported_targets (program_name, stream); + if (REPORT_BUGS_TO[0] && status == 0) +@@ -103,6 +359,7 @@ usage (FILE *stream, int status) + #define OPTION_FORMAT (200) + #define OPTION_RADIX (OPTION_FORMAT + 1) + #define OPTION_TARGET (OPTION_RADIX + 1) ++#define OPTION_MCU (OPTION_TARGET + 1) + + static struct option long_options[] = + { +@@ -110,6 +368,7 @@ static struct option long_options[] = + {"format", required_argument, 0, OPTION_FORMAT}, + {"radix", required_argument, 0, OPTION_RADIX}, + {"target", required_argument, 0, OPTION_TARGET}, ++ {"mcu", required_argument, 0, 203}, + {"totals", no_argument, &show_totals, 1}, + {"version", no_argument, &show_version, 1}, + {"help", no_argument, &show_help, 1}, +@@ -141,7 +399,7 @@ main (int argc, char **argv) + bfd_init (); + set_default_bfd_target (); + +- while ((c = getopt_long (argc, argv, "ABHhVvdfotx", long_options, ++ while ((c = getopt_long (argc, argv, "ABCHhVvdfotx", long_options, + (int *) 0)) != EOF) + switch (c) + { +@@ -150,11 +409,15 @@ main (int argc, char **argv) + { + case 'B': + case 'b': +- berkeley_format = 1; ++ format = format_bsd; + break; + case 'S': + case 's': +- berkeley_format = 0; ++ format = format_sysv; ++ break; ++ case 'A': ++ case 'a': ++ format = format_avr; + break; + default: + non_fatal (_("invalid argument to --format: %s"), optarg); +@@ -162,6 +424,10 @@ main (int argc, char **argv) + } + break; + ++ case OPTION_MCU: ++ avrmcu = optarg; ++ break; ++ + case OPTION_TARGET: + target = optarg; + break; +@@ -190,11 +457,14 @@ main (int argc, char **argv) + break; + + case 'A': +- berkeley_format = 0; ++ format = format_sysv; + break; + case 'B': +- berkeley_format = 1; ++ format = format_bsd; + break; ++ case 'C': ++ format = format_avr; ++ break; + case 'v': + case 'V': + show_version = 1; +@@ -240,7 +509,7 @@ main (int argc, char **argv) + for (; optind < argc;) + display_file (argv[optind++]); + +- if (show_totals && berkeley_format) ++ if (show_totals && format == format_bsd) + { + bfd_size_type total = total_textsize + total_datasize + total_bsssize; + +@@ -599,13 +869,117 @@ print_sysv_format (bfd *file) + printf ("\n\n"); + } + ++ ++static avr_device_t * ++avr_find_device (void) ++{ ++ unsigned int i; ++ if (avrmcu != NULL) ++ { ++ for (i = 0; i < sizeof(avr) / sizeof(avr[0]); i++) ++ { ++ if (strcmp(avr[i].name, avrmcu) == 0) ++ { ++ /* Match found */ ++ return (&avr[i]); ++ } ++ } ++ } ++ return (NULL); ++} ++ ++ ++ ++static void ++print_avr_format (bfd *file) ++{ ++ char *avr_name = "Unknown"; ++ int flashmax = 0; ++ int rammax = 0; ++ int eeprommax = 0; ++ asection *section; ++ ++ ++ ++ bfd_size_type bootloadersize = 0; ++ bfd_size_type noinitsize = 0; ++ bfd_size_type eepromsize = 0; ++ ++ avr_device_t *avrdevice = avr_find_device(); ++ if (avrdevice != NULL) ++ { ++ avr_name = avrdevice->name; ++ flashmax = avrdevice->flash; ++ rammax = avrdevice->ram; ++ eeprommax = avrdevice->eeprom; ++ } ++ ++ if ((section = bfd_get_section_by_name (file, ".data")) != NULL) ++ datasize = bfd_section_size (file, section); ++ if ((section = bfd_get_section_by_name (file, ".text")) != NULL) ++ textsize = bfd_section_size (file, section); ++ if ((section = bfd_get_section_by_name (file, ".bss")) != NULL) ++ bsssize = bfd_section_size (file, section); ++ if ((section = bfd_get_section_by_name (file, ".bootloader")) != NULL) ++ bootloadersize = bfd_section_size (file, section); ++ if ((section = bfd_get_section_by_name (file, ".noinit")) != NULL) ++ noinitsize = bfd_section_size (file, section); ++ if ((section = bfd_get_section_by_name (file, ".eeprom")) != NULL) ++ eepromsize = bfd_section_size (file, section); ++ ++ bfd_size_type text = textsize + datasize + bootloadersize; ++ bfd_size_type data = datasize + bsssize + noinitsize; ++ bfd_size_type eeprom = eepromsize; ++ ++ printf ("AVR Memory Usage\n" ++ "----------------\n" ++ "Device: %s\n\n", avr_name); ++ ++ /* Text size */ ++ printf ("Program:%8ld bytes", text); ++ if (flashmax > 0) ++ { ++ printf (" (%2.1f%% Full)", ((float)text / flashmax) * 100); ++ } ++ printf ("\n(.text + .data + .bootloader)\n\n"); ++ ++ /* Data size */ ++ printf ("Data: %8ld bytes", data); ++ if (rammax > 0) ++ { ++ printf (" (%2.1f%% Full)", ((float)data / rammax) * 100); ++ } ++ printf ("\n(.data + .bss + .noinit)\n\n"); ++ ++ /* EEPROM size */ ++ if (eeprom > 0) ++ { ++ printf ("EEPROM: %8ld bytes", eeprom); ++ if (eeprommax > 0) ++ { ++ printf (" (%2.1f%% Full)", ((float)eeprom / eeprommax) * 100); ++ } ++ printf ("\n(.eeprom)\n\n"); ++ } ++} ++ ++ + static void + print_sizes (bfd *file) + { + if (show_common) + calculate_common_size (file); +- if (berkeley_format) +- print_berkeley_format (file); +- else +- print_sysv_format (file); ++ switch (format) ++ { ++ case format_sysv: ++ print_sysv_format (file); ++ break; ++ case format_bsd: ++ print_berkeley_format (file); ++ break; ++ case format_avr: ++ default: ++ print_avr_format (file); ++ break; ++ } + } diff --git a/cmake/SuperBuild/CheckExternalProjectDependency.cmake b/cmake/SuperBuild/CheckExternalProjectDependency.cmake new file mode 100644 index 0000000..75aff36 --- /dev/null +++ b/cmake/SuperBuild/CheckExternalProjectDependency.cmake @@ -0,0 +1,85 @@ +########################################################################### +# +# Copyright (c) Kitware Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +########################################################################### + +#! +#! Convenient macro allowing to define a "empty" project in case an external one is provided +#! using for example _DIR. +#! Doing so allows to keep the external project dependency system happy. +#! +#! \ingroup CMakeUtilities +macro(EmptyExternalProject proj dependencies) + + ExternalProject_Add(${proj} + SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj} + BINARY_DIR ${proj}-build + DOWNLOAD_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + DEPENDS + ${dependencies} + ) +endmacro() + +macro(CheckExternalProjectDependency project) + # Set indent variable if needed + if(NOT DEFINED __indent) + set(__indent "") + else() + set(__indent "${__indent} ") + endif() + + # Sanity checks + if(NOT DEFINED ${project}_DEPENDENCIES) + message(FATAL_ERROR "${__indent}${project}_DEPENDENCIES variable is NOT defined !") + endif() + + # Display dependency of projectect being processed + if("${${project}_DEPENDENCIES}" STREQUAL "") + message(STATUS "SuperBuild - ${__indent}${project}[OK]") + else() + set(dependency_str " ") + foreach(dep ${${project}_DEPENDENCIES}) + if(External_${dep}_FILE_INCLUDED) + set(dependency_str "${dependency_str}${dep}[INCLUDED], ") + else() + set(dependency_str "${dependency_str}${dep}, ") + endif() + endforeach() + message(STATUS "SuperBuild - ${__indent}${project} => Requires${dependency_str}") + endif() + + # Include dependencies + foreach(dep ${${project}_DEPENDENCIES}) + if(NOT External_${dep}_FILE_INCLUDED) + include(SuperBuild/External_${dep}) + endif() + endforeach() + + # If projectect being process has dependencies, indicates it has also been added. + if(NOT "${${project}_DEPENDENCIES}" STREQUAL "") + message(STATUS "SuperBuild - ${__indent}${project}[OK]") + endif() + + # Update indent variable + string(LENGTH "${__indent}" __indent_length) + math(EXPR __indent_length "${__indent_length}-2") + if(NOT ${__indent_length} LESS 0) + string(SUBSTRING "${__indent}" 0 ${__indent_length} __indent) + endif() +endmacro() diff --git a/cmake/SuperBuild/External_ARDUINO_SDK.cmake b/cmake/SuperBuild/External_ARDUINO_SDK.cmake new file mode 100644 index 0000000..65ef5df --- /dev/null +++ b/cmake/SuperBuild/External_ARDUINO_SDK.cmake @@ -0,0 +1,68 @@ +########################################################################### +# +# ARDUINO_SDK +# +########################################################################### + +# Make sure this file is included only once +get_filename_component(CMAKE_CURRENT_LIST_FILENAME ${CMAKE_CURRENT_LIST_FILE} NAME_WE) +if(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED) + return() +endif() +set(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED 1) + +# Sanity checks +if(DEFINED ARDUINO_SDK_DIR AND NOT EXISTS ${ARDUINO_SDK_DIR}) + message(FATAL_ERROR "ARDUINO_SDK_DIR variable is defined but corresponds to non-existing directory") +endif() + +set(ARDUINO_SDK_DEPENDENCIES "AVR_BINUTILS;AVR_GCC;AVR_LIBC") + +# Include dependent projects if any +CheckExternalProjectDependency(ARDUINO_SDK) +set(proj ARDUINO_SDK) + +if(NOT DEFINED ARDUINO_SDK_DIR) + # Set CMake OSX variable to pass down the external project + set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS) + if(APPLE) + list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}) + endif() + + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SuperBuild/arduino_configure_step.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/arduino_configure_step.cmake @ONLY) + + set(ARDUINO_CONFIGURE_COMMAND + ${CMAKE_COMMAND} + -P ${CMAKE_CURRENT_BINARY_DIR}/arduino_configure_step.cmake + ) + + ExternalProject_Add(${proj} + SOURCE_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj} + BINARY_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj}-build + PREFIX ${proj}${ep_suffix} + URL ${ARDUINO_URL}/${ARDUINO_GZ} + URL_HASH SHA1=${ARDUINO_SHA1} + UPDATE_COMMAND "" + INSTALL_COMMAND "" + CONFIGURE_COMMAND ${ARDUINO_CONFIGURE_COMMAND} + BUILD_COMMAND "" + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 + DEPENDS + ${ARDUINO_SDK_DEPENDENCIES} + ) + set(${proj}_DIR ${CMAKE_BINARY_DIR}/${proj}-build) + +else() + EmptyExternalProject(${proj} "${ARDUINO_SDK_DEPENDENCIES}") +endif() + +list(APPEND ARDUINO_SUPERBUILD_EP_ARGS -DARDUINO_SDK_PATH:PATH=${CMAKE_BINARY_DIR}/SuperBuild/${proj}-build ) + + diff --git a/cmake/SuperBuild/External_AVRDUDE.cmake b/cmake/SuperBuild/External_AVRDUDE.cmake new file mode 100644 index 0000000..e65020e --- /dev/null +++ b/cmake/SuperBuild/External_AVRDUDE.cmake @@ -0,0 +1,59 @@ +########################################################################### +# +# AVRDUDE +# +########################################################################### + +# Make sure this file is included only once +get_filename_component(CMAKE_CURRENT_LIST_FILENAME ${CMAKE_CURRENT_LIST_FILE} NAME_WE) +if(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED) + return() +endif() +set(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED 1) + +# Sanity checks +if(DEFINED AVRDUDE_DIR AND NOT EXISTS ${AVRDUDE_DIR}) + message(FATAL_ERROR "AVRDUDE_DIR variable is defined but corresponds to non-existing directory") +endif() + +set(AVRDUDE_DEPENDENCIES "") + +# Include dependent projects if any +CheckExternalProjectDependency(AVRDUDE) +set(proj AVRDUDE) + +if(NOT DEFINED AVRDUDE_DIR) + # Set CMake OSX variable to pass down the external project + set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS) + if(APPLE) + list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}) + endif() + + set(AVR_GCC_DIR ${ep_install_dir}/avr) + + ExternalProject_Add(${proj} + SOURCE_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj} + BINARY_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj}-build + PREFIX ${proj}${ep_suffix} + URL ${AVRDUDE_URL}/${AVRDUDE_GZ} + URL_HASH SHA1=${AVRDUDE_SHA1} + UPDATE_COMMAND "" + INSTALL_COMMAND make install + CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/SuperBuild/${proj}/configure --prefix=${ep_install_dir}/avr + BUILD_COMMAND make + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 + DEPENDS + ${AVRDUDE_DEPENDENCIES} + ) + set(${proj}_DIR ${CMAKE_BINARY_DIR}/${proj}-build) + +else() + EmptyExternalProject(${proj} "${proj_DEPENDENCIES}") +endif() + diff --git a/cmake/SuperBuild/External_AVR_BINUTILS.cmake b/cmake/SuperBuild/External_AVR_BINUTILS.cmake new file mode 100644 index 0000000..79988ff --- /dev/null +++ b/cmake/SuperBuild/External_AVR_BINUTILS.cmake @@ -0,0 +1,68 @@ +########################################################################### +# +# AVR_BINUTILS +# +########################################################################### + +# Make sure this file is included only once +get_filename_component(CMAKE_CURRENT_LIST_FILENAME ${CMAKE_CURRENT_LIST_FILE} NAME_WE) +if(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED) + return() +endif() +set(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED 1) + +# Sanity checks +if(DEFINED AVR_BINUTILS_DIR AND NOT EXISTS ${AVR_BINUTILS_DIR}) + message(FATAL_ERROR "AVR_BINUTILS_DIR variable is defined but corresponds to non-existing directory") +endif() + +set(AVR_BINUTILS_DEPENDENCIES "") + +# Include dependent projects if any +CheckExternalProjectDependency(AVR_BINUTILS) +set(proj AVR_BINUTILS) + +if(NOT DEFINED AVR_BINUTILS_DIR) + + # Set CMake OSX variable to pass down the external project + set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS) + if(APPLE) + list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}) + endif() + + set(BINUTILS_PATCH_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/SuperBuild/30-binutils-2.20.1-avr-size.patch) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SuperBuild/binutils_patch_step.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/binutils_patch_step.cmake @ONLY) + + set(BINUTILS_PATCH_COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/binutils_patch_step.cmake) + ExternalProject_Add(${proj} + SOURCE_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj} + BINARY_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj}-build + PREFIX ${proj}${ep_suffix} + URL ${BINUTILS_URL}/${BINUTILS_GZ} + URL_HASH SHA1=${BINUTILS_SHA1} + UPDATE_COMMAND "" + PATCH_COMMAND ${BINUTILS_PATCH_COMMAND} + INSTALL_COMMAND make install + CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/SuperBuild/${proj}/configure + --prefix=${ep_install_dir}/avr + --target=avr + --program-prefix='avr-' + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 + DEPENDS + ${AVR_BINUTILS_DEPENDENCIES} + ) + set(${proj}_DIR ${CMAKE_BINARY_DIR}/${proj}-build) + +else() + EmptyExternalProject(${proj} "${AVR_BINUTILS_DEPENDENCIES}") +endif() + +list(APPEND CMAKE_PREFIX_PATH ${ep_install_dir}/avr/avr ${ep_install_dir}/avr) + diff --git a/cmake/SuperBuild/External_AVR_GCC.cmake b/cmake/SuperBuild/External_AVR_GCC.cmake new file mode 100644 index 0000000..c9f7d92 --- /dev/null +++ b/cmake/SuperBuild/External_AVR_GCC.cmake @@ -0,0 +1,67 @@ +########################################################################### +# +# AVR_GCC +# +########################################################################### + +# Make sure this file is included only once +get_filename_component(CMAKE_CURRENT_LIST_FILENAME ${CMAKE_CURRENT_LIST_FILE} NAME_WE) +if(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED) + return() +endif() +set(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED 1) + +# Sanity checks +if(DEFINED AVR_GCC_DIR AND NOT EXISTS ${AVR_GCC_DIR}) + message(FATAL_ERROR "AVR_GCC_DIR variable is defined but corresponds to non-existing directory") +endif() + +set(AVR_GCC_DEPENDENCIES "AVR_BINUTILS") + +# Include dependent projects if any +CheckExternalProjectDependency(AVR_GCC) +set(proj AVR_GCC) + +if(NOT DEFINED AVR_GCC_DIR) + + # Set CMake OSX variable to pass down the external project + set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS) + if(APPLE) + list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}) + endif() + + ExternalProject_Add(${proj} + SOURCE_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj} + BINARY_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj}-build + PREFIX ${proj}${ep_suffix} + URL ${GCC_URL}/${GCC_GZ} + URL_HASH SHA1=${GCC_SHA1} + UPDATE_COMMAND "" + CONFIGURE_COMMAND ${CMAKE_BINARY_DIR}/SuperBuild/${proj}/configure + --prefix=${ep_install_dir}/avr + --target=avr + --enable-languages=c,c++ + --program-prefix='avr-' + INSTALL_COMMAND make install + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 + DEPENDS + ${AVR_GCC_DEPENDENCIES} + ) + set(${proj}_DIR ${CMAKE_BINARY_DIR}/${proj}-build) + +else() + EmptyExternalProject(${proj} "${proj_DEPENDENCIES}") +endif() + +list(APPEND ARDUINO_SUPERBUILD_EP_ARGS + -DCMAKE_C_COMPILER=${ep_install_dir}/avr/bin/avr-gcc + -DCMAKE_CXX_COMPILER=${ep_install_dir}/avr/bin/avr-g++ + ) + +list(APPEND CMAKE_FIND_ROOT_PATH ${ep_install_dir}/avr) diff --git a/cmake/SuperBuild/External_AVR_LIBC.cmake b/cmake/SuperBuild/External_AVR_LIBC.cmake new file mode 100644 index 0000000..228b24b --- /dev/null +++ b/cmake/SuperBuild/External_AVR_LIBC.cmake @@ -0,0 +1,80 @@ +########################################################################### +# +# AVR_LIBC +# +########################################################################### + +# Make sure this file is included only once +get_filename_component(CMAKE_CURRENT_LIST_FILENAME ${CMAKE_CURRENT_LIST_FILE} NAME_WE) +if(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED) + return() +endif() +set(${CMAKE_CURRENT_LIST_FILENAME}_FILE_INCLUDED 1) + +# Sanity checks +if(DEFINED AVR_LIBC_DIR AND NOT EXISTS ${AVR_LIBC_DIR}) + message(FATAL_ERROR "AVR_LIBC_DIR variable is defined but corresponds to non-existing directory") +endif() + +set(AVR_LIBC_DEPENDENCIES "AVR_GCC;AVR_BINUTILS") + +# Include dependent projects if any +CheckExternalProjectDependency(AVR_LIBC) +set(proj AVR_LIBC) + +if(NOT DEFINED AVR_LIBC_DIR) + # Set CMake OSX variable to pass down the external project + set(CMAKE_OSX_EXTERNAL_PROJECT_ARGS) + if(APPLE) + list(APPEND CMAKE_OSX_EXTERNAL_PROJECT_ARGS + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} + -DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}) + endif() + + set(AVR_GCC_DIR ${ep_install_dir}/avr) + + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SuperBuild/avr_libc_configure_step.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/avr_libc_configure_step.cmake @ONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SuperBuild/avr_libc_build_step.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/avr_libc_build_step.cmake @ONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/SuperBuild/avr_libc_install_step.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/avr_libc_install_step.cmake @ONLY) + + set(AVR_LIBC_CONFIGURE_COMMAND + ${CMAKE_COMMAND} + -P ${CMAKE_CURRENT_BINARY_DIR}/avr_libc_configure_step.cmake + ) + set(AVR_LIBC_BUILD_COMMAND + ${CMAKE_COMMAND} + -P ${CMAKE_CURRENT_BINARY_DIR}/avr_libc_build_step.cmake + ) + set(AVR_LIBC_INSTALL_COMMAND + ${CMAKE_COMMAND} + -P ${CMAKE_CURRENT_BINARY_DIR}/avr_libc_install_step.cmake + ) + + ExternalProject_Add(${proj} + SOURCE_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj} + BINARY_DIR ${CMAKE_BINARY_DIR}/SuperBuild/${proj}-build + PREFIX ${proj}${ep_suffix} + URL ${AVR_LIBC_URL}/${AVR_LIBC_GZ} + URL_HASH SHA1=${AVR_LIBC_SHA1} + UPDATE_COMMAND "" + INSTALL_COMMAND ${AVR_LIBC_INSTALL_COMMAND} + CONFIGURE_COMMAND ${AVR_LIBC_CONFIGURE_COMMAND} + BUILD_COMMAND ${AVR_LIBC_BUILD_COMMAND} + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 + LOG_INSTALL 1 + DEPENDS + ${AVR_LIBC_DEPENDENCIES} + ) + set(${proj}_DIR ${CMAKE_BINARY_DIR}/${proj}-build) + +else() + EmptyExternalProject(${proj} "${proj_DEPENDENCIES}") +endif() + +list(APPEND CMAKE_FIND_ROOT_PATH ${ep_install_dir}/avr/avr) diff --git a/cmake/SuperBuild/Versions.cmake b/cmake/SuperBuild/Versions.cmake new file mode 100644 index 0000000..86704f6 --- /dev/null +++ b/cmake/SuperBuild/Versions.cmake @@ -0,0 +1,41 @@ +set(ARDUINO_DEPENDENCIES_URL "$ENV{HOME}/Downloads" CACHE PATH "Path for external packages." ) + +set(BINUTILS_MAJOR 2) +set(BINUTILS_MINOR 23) +set(BINUTILS_VERSION ${BINUTILS_MAJOR}.${BINUTILS_MINOR}) +set(BINUTILS_URL http://ftp.gnu.org/gnu/binutils) +set(BINUTILS_GZ binutils-${BINUTILS_VERSION}.tar.gz) +set(BINUTILS_SHA1 470c388c97ac8d216de33fa397d7be9f96c3fe04) + +set(GCC_MAJOR 4) +set(GCC_MINOR 7) +set(GCC_PATCH 2) +set(GCC_VERSION ${GCC_MAJOR}.${GCC_MINOR}.${GCC_PATCH}) +set(GCC_URL http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}) +set(GCC_GZ gcc-${GCC_VERSION}.tar.gz) +set(GCC_SHA1 39b5662c4bdffa8d8b8f31f61764de2a9e3b69b0) + +set(AVR_LIBC_MAJOR 1) +set(AVR_LIBC_MINOR 8) +set(AVR_LIBC_PATCH 0) +set(AVR_LIBC_VERSION ${AVR_LIBC_MAJOR}.${AVR_LIBC_MINOR}.${AVR_LIBC_PATCH}) +set(AVR_LIBC_URL http://download.savannah.gnu.org/releases/avr-libc) +set(AVR_LIBC_GZ avr-libc-${AVR_LIBC_VERSION}.tar.bz2) +set(AVR_LIBC_SHA1 2e3815221be8e22f5f2c07b922ce92ecfa85bade) + +set(ARDUINO_MAJOR 1) +set(ARDUINO_MINOR 0) +set(ARDUINO_PATCH 3) +set(ARDUINO_VERSION ${ARDUINO_MAJOR}.${ARDUINO_MINOR}.${ARDUINO_PATCH}) +set(ARDUINO_URL https://arduino.googlecode.com/files) +set(ARDUINO_GZ arduino-${ARDUINO_VERSION}-src.tar.gz) +set(ARDUINO_SHA1 b1b3a99df4f016b7c021173f2d0ced300cb7587c) + +set(AVRDUDE_MAJOR 6) +set(AVRDUDE_MINOR 0) +set(AVRDUDE_PATCH 1) +set(AVRDUDE_VERSION ${AVRDUDE_MAJOR}.${AVRDUDE_MINOR}.${AVRDUDE_PATCH}) +set(AVRDUDE_URL http://download.savannah.gnu.org/releases/avrdude) +set(AVRDUDE_GZ avrdude-${AVRDUDE_VERSION}.tar.gz) +set(AVRDUDE_SHA1 b0f440f1b1ba3890da6e5b752003ca99e550e3bf) + diff --git a/cmake/SuperBuild/arduino_configure_step.cmake.in b/cmake/SuperBuild/arduino_configure_step.cmake.in new file mode 100644 index 0000000..a51ef1a --- /dev/null +++ b/cmake/SuperBuild/arduino_configure_step.cmake.in @@ -0,0 +1,6 @@ + +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory @ARDUINO_BINARY_DIR@/SuperBuild/@proj@/hardware @ARDUINO_BINARY_DIR@/SuperBuild/@proj@-build/hardware WORKING_DIRECTORY @ARDUINO_BINARY_DIR@/SuperBuild/@proj@) + +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory @ARDUINO_BINARY_DIR@/SuperBuild/@proj@/libraries @ARDUINO_BINARY_DIR@/SuperBuild/@proj@-build/libraries WORKING_DIRECTORY @ARDUINO_BINARY_DIR@/SuperBuild/@proj@) + +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory @ARDUINO_BINARY_DIR@/SuperBuild/@proj@/build/shared/examples @ARDUINO_BINARY_DIR@/SuperBuild/@proj@-build/examples WORKING_DIRECTORY @ARDUINO_BINARY_DIR@/SuperBuild/@proj@) diff --git a/cmake/SuperBuild/avr_libc_build_step.cmake.in b/cmake/SuperBuild/avr_libc_build_step.cmake.in new file mode 100644 index 0000000..03fbb27 --- /dev/null +++ b/cmake/SuperBuild/avr_libc_build_step.cmake.in @@ -0,0 +1,3 @@ + +set(ENV{PATH} "@AVR_GCC_DIR@/bin:$ENV{PATH}") +execute_process(COMMAND make WORKING_DIRECTORY @ARDUINO_BINARY_DIR@/SuperBuild/@proj@-build) diff --git a/cmake/SuperBuild/avr_libc_configure_step.cmake.in b/cmake/SuperBuild/avr_libc_configure_step.cmake.in new file mode 100644 index 0000000..23def0d --- /dev/null +++ b/cmake/SuperBuild/avr_libc_configure_step.cmake.in @@ -0,0 +1,6 @@ + +set(ENV{PATH} "@AVR_GCC_DIR@/bin:$ENV{PATH}") +execute_process(COMMAND @ARDUINO_BINARY_DIR@/SuperBuild/@proj@/configure + --prefix=@ep_install_dir@/avr + --host=avr + WORKING_DIRECTORY @ARDUINO_BINARY_DIR@/SuperBuild/@proj@-build) diff --git a/cmake/SuperBuild/avr_libc_install_step.cmake.in b/cmake/SuperBuild/avr_libc_install_step.cmake.in new file mode 100644 index 0000000..c3e46cb --- /dev/null +++ b/cmake/SuperBuild/avr_libc_install_step.cmake.in @@ -0,0 +1,3 @@ + +set(ENV{PATH} "@AVR_GCC_DIR@/bin:$ENV{PATH}") +execute_process(COMMAND make install WORKING_DIRECTORY @ARDUINO_BINARY_DIR@/SuperBuild/@proj@-build) diff --git a/cmake/SuperBuild/binutils_patch_step.cmake.in b/cmake/SuperBuild/binutils_patch_step.cmake.in new file mode 100644 index 0000000..f19d9f4 --- /dev/null +++ b/cmake/SuperBuild/binutils_patch_step.cmake.in @@ -0,0 +1,2 @@ + +execute_process(COMMAND @PATCH_EXECUTABLE@ -p0 -i @BINUTILS_PATCH_FILE@ WORKING_DIRECTORY @ARDUINO_BINARY_DIR@/SuperBuild/@proj@)