Skip to content

Commit ec2c4fd

Browse files
committed
Merge branch 'cmake-upgrade'
2 parents 27c55f8 + b8c1106 commit ec2c4fd

37 files changed

+4492
-2320
lines changed

.travis.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
---
22
sudo: required
3-
dist: trusty
3+
dist: focal
44

55
language:
66
- c
77

88
cache:
99
- ccache
1010

11+
before_install:
12+
- wget http://downloads.arduino.cc/arduino-1.8.3-linux64.tar.xz
13+
- tar xf arduino-1.8.3-linux64.tar.xz
14+
- sudo mv arduino-1.8.3 /usr/local/share/arduino
15+
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
16+
17+
install:
18+
- arduino --install-boards "arduino:avr:1.8.3"
19+
- arduino --install-library Servo:1.1.6
20+
- mkdir -p $TRAVIS_BUILD_DIR/libraries
21+
- mv ~/Arduino/libraries/* $TRAVIS_BUILD_DIR/libraries
22+
1123
addons:
1224
apt:
1325
packages:
14-
- gcc-avr
15-
- binutils-avr
16-
- avr-libc
17-
- arduino
18-
- python3.4
26+
- python3.6
1927

20-
script: tools/compile_test.py
28+
script:
29+
- tools/compile_test.py

Arduino_Pedelec_Controller/CMakeLists.txt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}
1010

1111
set(FIRMWARE_NAME pcontroller)
1212

13-
set(${FIRMWARE_NAME}_BOARD ${FC_PROCESSOR})
14-
set(${FIRMWARE_NAME}_PORT /dev/ttyUSB0) # Serial upload port
15-
1613
# special compile flags for the Travis CI environment
1714
# (avr-gcc is rather outdated and outputs crazy warnings)
1815
if("$ENV{TRAVIS}" STREQUAL "true")
@@ -26,7 +23,7 @@ endif("$ENV{TRAVIS}" STREQUAL "true")
2623
# and move everything to main.cpp
2724
configure_file(Arduino_Pedelec_Controller.ino main.cpp COPYONLY)
2825

29-
set(${FIRMWARE_NAME}_SRCS # Source code
26+
add_executable(${FIRMWARE_NAME}
3027
${CMAKE_CURRENT_BINARY_DIR}/main.cpp
3128
BMP085.cpp
3229
BMP085.h
@@ -71,9 +68,8 @@ set(${FIRMWARE_NAME}_SRCS # Source code
7168
switches.h
7269
switches_action.h
7370
)
74-
generate_arduino_firmware(${FIRMWARE_NAME})
71+
target_link_arduino_libraries(${FIRMWARE_NAME} PRIVATE AUTO_PUBLIC)
7572

76-
# Dirty hack to solve compile error on Fedora 15
77-
#target_link_libraries(${FIRMWARE_NAME} m)
78-
#target_link_libraries(${FIRMWARE_NAME} c)
79-
#target_link_libraries(${FIRMWARE_NAME} m)
73+
# Upload support: Usage:
74+
# make upload-pcontroller SERIAL_PORT=/dev/ttyUSB0
75+
target_enable_arduino_upload(${FIRMWARE_NAME})

CMakeLists.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@
55
# Description: Pedelec controller cmake project #
66
# #
77
#=============================================================================#
8-
set(CMAKE_TOOLCHAIN_FILE cmake/ArduinoToolchain.cmake) # Arduino Toolchain
9-
10-
cmake_minimum_required(VERSION 2.8)
11-
project(Pedelec_Controller C CXX)
12-
8+
set(CMAKE_TOOLCHAIN_FILE cmake/Arduino-toolchain.cmake) # Arduino Toolchain
139

1410
# "grep" for FC 2.0 hardware in config.h
11+
# Do this before project() since it invokes toolchain detection
1512
file(STRINGS Arduino_Pedelec_Controller/config.h config_h_lines REGEX "^#define HARDWARE_REV 2[0-9]")
1613
if (config_h_lines)
1714
message("Building firmware for FC 2.0 or higher")
18-
set(FC_PROCESSOR mega2560)
15+
set(ARDUINO_BOARD "Arduino Mega or Mega 2560 [avr.mega]")
16+
set(ARDUINO_AVR_MEGA_MENU_CPU_ATMEGA2560 TRUE)
1917
else(config_h_lines)
20-
set(FC_PROCESSOR atmega328)
18+
set(ARDUINO_BOARD "Arduino Nano [avr.nano]")
19+
20+
option(OLD_BOOTLOADER "Arduino Nano uses old bootloader (57600 baud)" OFF)
21+
if (OLD_BOOTLOADER)
22+
set(ARDUINO_AVR_NANO_MENU_CPU_ATMEGA328OLD TRUE)
23+
else (OLD_BOOTLOADER)
24+
set(ARDUINO_AVR_NANO_MENU_CPU_ATMEGA328 TRUE)
25+
endif (OLD_BOOTLOADER)
2126
endif(config_h_lines)
27+
set(ARDUINO_PROGRAMMER "Arduino as ISP [avr.arduinoasisp]")
28+
29+
cmake_minimum_required(VERSION 3.7.0)
30+
project(Pedelec_Controller C CXX)
2231

2332
# Documentation
2433
option(DOCUMENTATION "Generate API documentation with Doxygen" OFF)

Hardware_Test/CMakeLists.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ configure_file(Hardware_Test.ino testprogram.cpp COPYONLY)
1212

1313
# Hardware test program
1414
set(TESTPROGRAM_NAME testprogram)
15-
set(${TESTPROGRAM_NAME}_BOARD ${FC_PROCESSOR})
16-
set(${TESTPROGRAM_NAME}_PORT /dev/ttyUSB0)
1715

18-
set(${TESTPROGRAM_NAME}_SRCS
16+
add_executable(${TESTPROGRAM_NAME}
1917
${CMAKE_CURRENT_BINARY_DIR}/testprogram.cpp
2018
PCD8544_charset.cpp
2119
PCD8544_nano.cpp
2220
)
23-
generate_arduino_firmware(${TESTPROGRAM_NAME})
21+
target_link_arduino_libraries(${TESTPROGRAM_NAME} PRIVATE EEPROM core)
2422

25-
# Dirty hack to solve compile error on Fedora 15
26-
#target_link_libraries(${TESTPROGRAM_NAME} m)
27-
#target_link_libraries(${TESTPROGRAM_NAME} c)
28-
#target_link_libraries(${TESTPROGRAM_NAME} m)
23+
# Upload support: Usage:
24+
# make upload-testprogram SERIAL_PORT=/dev/ttyUSB0
25+
target_enable_arduino_upload(${TESTPROGRAM_NAME})

cmake/Arduino-toolchain.cmake

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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

Comments
 (0)