1
1
#=============================================================================#
2
+ # Arduino Toolchain for CMake
3
+ # Copyright (c) 2016 Philip Roan
4
+ # Forked from Tomasz Bogdal's github.com project:
5
+ #
6
+ # https://github.com/queezythegreat/arduino-cmake
7
+ #
8
+ # This Source Code Form is subject to the terms of the Mozilla Public
9
+ # License, v. 2.0. If a copy of the MPL was not distributed with this file,
10
+ # You can obtain one at http://mozilla.org/MPL/2.0/.
11
+ #=============================================================================#
12
+ #
13
+ #=============================================================================#
2
14
# generate_arduino_firmware(name
3
15
# [BOARD board_id]
4
16
# [SKETCH sketch_path |
90
102
# Alternatively you can specify the option by variables:
91
103
#
92
104
# set(test_SRCS test.cpp test2.cpp)
93
- # set(test_HDRS test.h test2.h
105
+ # set(test_HDRS test.h test2.h)
94
106
# set(test_BOARD uno)
95
107
#
96
108
# generate_avr_firmware(test)
130
142
# Alternatively you can specify the option by variables:
131
143
#
132
144
# set(test_SRCS test.cpp test2.cpp)
133
- # set(test_HDRS test.h test2.h
145
+ # set(test_HDRS test.h test2.h)
134
146
# set(test_BOARD uno)
135
147
#
136
148
# generate_arduino_library(test)
@@ -618,6 +630,7 @@ function(GENERATE_ARDUINO_EXAMPLE INPUT_NAME)
618
630
endif ()
619
631
620
632
find_arduino_libraries(TARGET_LIBS "${ALL_SRCS} " "" )
633
+
621
634
set (LIB_DEP_INCLUDES)
622
635
foreach (LIB_DEP ${TARGET_LIBS} )
623
636
set (LIB_DEP_INCLUDES "${LIB_DEP_INCLUDES} -I\" ${LIB_DEP} \" " )
@@ -656,31 +669,37 @@ function(REGISTER_HARDWARE_PLATFORM PLATFORM_PATH)
656
669
657
670
find_file (${PLATFORM} _CORES_PATH
658
671
NAMES cores
659
- PATHS ${PLATFORM_PATH}
672
+ PATHS ${PLATFORM_PATH} ${PLATFORM_PATH} /avr
660
673
DOC "Path to directory containing the Arduino core sources." )
661
674
662
675
find_file (${PLATFORM} _VARIANTS_PATH
663
676
NAMES variants
664
- PATHS ${PLATFORM_PATH}
677
+ PATHS ${PLATFORM_PATH} ${PLATFORM_PATH} /avr
665
678
DOC "Path to directory containing the Arduino variant sources." )
679
+
680
+ find_file (${PLATFORM} _ARCHITECTURE_LIBRARIES_PATH
681
+ NAMES libraries
682
+ PATHS ${PLATFORM_PATH} ${PLATFORM_PATH} /avr
683
+ DOC "Path to diretory containing the Arduino libraries that are specific to this architecture." )
666
684
667
685
find_file (${PLATFORM} _BOOTLOADERS_PATH
668
686
NAMES bootloaders
669
- PATHS ${PLATFORM_PATH}
687
+ PATHS ${PLATFORM_PATH} ${PLATFORM_PATH} /avr
670
688
DOC "Path to directory containing the Arduino bootloader images and sources." )
671
689
672
690
find_file (${PLATFORM} _PROGRAMMERS_PATH
673
691
NAMES programmers.txt
674
- PATHS ${PLATFORM_PATH}
692
+ PATHS ${PLATFORM_PATH} ${PLATFORM_PATH} /avr
675
693
DOC "Path to Arduino programmers definition file." )
676
694
677
695
find_file (${PLATFORM} _BOARDS_PATH
678
696
NAMES boards.txt
679
- PATHS ${PLATFORM_PATH}
697
+ PATHS ${PLATFORM_PATH} ${PLATFORM_PATH} /avr
680
698
DOC "Path to Arduino boards definition file." )
681
699
682
700
if (${PLATFORM} _BOARDS_PATH)
683
- load_arduino_style_settings(${PLATFORM} _BOARDS "${PLATFORM_PATH} /boards.txt" )
701
+ #load_arduino_style_settings(${PLATFORM}_BOARDS "${PLATFORM_PATH}/boards.txt")
702
+ load_arduino_style_settings(${PLATFORM} _BOARDS ${${PLATFORM} _BOARDS_PATH})
684
703
endif ()
685
704
686
705
if (${PLATFORM} _PROGRAMMERS_PATH)
@@ -787,8 +806,8 @@ function(get_arduino_flags COMPILE_FLAGS_VAR LINK_FLAGS_VAR BOARD_ID MANUAL)
787
806
set (BOARD_CORE ${${BOARD_ID} .build .core})
788
807
if (BOARD_CORE)
789
808
if (ARDUINO_SDK_VERSION MATCHES "([0-9]+)[.]([0-9]+)" )
790
- string (REPLACE "." "" ARDUINO_VERSION_DEFINE "${ARDUINO_SDK_VERSION} " ) # Normalize version (remove all periods)
791
- set (ARDUINO_VERSION_DEFINE "" )
809
+ # string(REPLACE "." "" ARDUINO_VERSION_DEFINE "${ARDUINO_SDK_VERSION}") # Normalize version (remove all periods)
810
+ set (ARDUINO_VERSION_DEFINE "" ) # This overwrites the line above, so just comment that line out
792
811
if (CMAKE_MATCH_1 GREATER 0)
793
812
set (ARDUINO_VERSION_DEFINE "${CMAKE_MATCH_1} " )
794
813
endif ()
@@ -800,9 +819,22 @@ function(get_arduino_flags COMPILE_FLAGS_VAR LINK_FLAGS_VAR BOARD_ID MANUAL)
800
819
else ()
801
820
message ("Invalid Arduino SDK Version (${ARDUINO_SDK_VERSION} )" )
802
821
endif ()
822
+ # Handle patch version
823
+ if (ARDUINO_SDK_VERSION MATCHES "([0-9]+)[.]([0-9]+)[.]([0-9]+)" )
824
+ if (CMAKE_MATCH_3 GREATER 10)
825
+ set (ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}${CMAKE_MATCH_3} " )
826
+ else ()
827
+ set (ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE} 0${CMAKE_MATCH_3} " )
828
+ endif ()
829
+ endif ()
830
+
831
+ # Define flags for Arduino architecture and cpu
832
+ if (${${BOARD_ID} .build .board} MATCHES "AVR" )
833
+ set (ARDUINO_ARCH_FLAGS "-DARDUINO_ARCH_AVR -DARDUINO_${${BOARD_ID} .build.board}" )
834
+ endif ()
803
835
804
836
# output
805
- set (COMPILE_FLAGS "-DF_CPU=${${BOARD_ID} .build.f_cpu} -DARDUINO=${ARDUINO_VERSION_DEFINE} -mmcu=${${BOARD_ID} .build.mcu}" )
837
+ set (COMPILE_FLAGS "-DF_CPU=${${BOARD_ID} .build.f_cpu} -DARDUINO=${ARDUINO_VERSION_DEFINE} -mmcu=${${BOARD_ID} .build.mcu} ${ARDUINO_ARCH_FLAGS} " )
806
838
if (DEFINED ${BOARD_ID} .build .vid)
807
839
set (COMPILE_FLAGS "${COMPILE_FLAGS} -DUSB_VID=${${BOARD_ID} .build.vid}" )
808
840
endif ()
@@ -921,9 +953,12 @@ function(find_arduino_libraries VAR_NAME SRCS ARDLIBS)
921
953
DIRECTORY # Property Scope
922
954
PROPERTY LINK_DIRECTORIES )
923
955
foreach (LIB_SEARCH_PATH ${LIBRARY_SEARCH_PATH} ${ARDUINO_LIBRARIES_PATH} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} /libraries ${ARDUINO_EXTRA_LIBRARIES_PATH} )
924
- if (EXISTS ${LIB_SEARCH_PATH} /${INCLUDE_NAME} /${CMAKE_MATCH_1} )
956
+ if (EXISTS " ${LIB_SEARCH_PATH} /${INCLUDE_NAME} /${CMAKE_MATCH_1} " )
925
957
list (APPEND ARDUINO_LIBS ${LIB_SEARCH_PATH} /${INCLUDE_NAME} )
926
958
break ()
959
+ elseif (EXISTS "${LIB_SEARCH_PATH} /${INCLUDE_NAME} /src/${CMAKE_MATCH_1} " )
960
+ list (APPEND ARDUINO_LIBS ${LIB_SEARCH_PATH} /${INCLUDE_NAME} /src)
961
+ break ()
927
962
endif ()
928
963
if (EXISTS ${LIB_SEARCH_PATH} /${CMAKE_MATCH_1} )
929
964
list (APPEND ARDUINO_LIBS ${LIB_SEARCH_PATH} )
@@ -962,6 +997,9 @@ endfunction()
962
997
set (Wire_RECURSE True )
963
998
set (Ethernet_RECURSE True )
964
999
set (SD_RECURSE True )
1000
+ set (TFT_RECURSE True )
1001
+ set (WiFi_RECURSE True )
1002
+ set (Robot_Control_RECURSE True )
965
1003
function (setup_arduino_library VAR_NAME BOARD_ID LIB_PATH COMPILE_FLAGS LINK_FLAGS )
966
1004
set (LIB_TARGETS)
967
1005
set (LIB_INCLUDES)
@@ -976,7 +1014,7 @@ function(setup_arduino_library VAR_NAME BOARD_ID LIB_PATH COMPILE_FLAGS LINK_FLA
976
1014
set (${LIB_SHORT_NAME} _RECURSE False )
977
1015
endif ()
978
1016
979
- find_sources(LIB_SRCS ${LIB_PATH} ${${LIB_SHORT_NAME} _RECURSE})
1017
+ find_sources(LIB_SRCS ${LIB_PATH} ${LIB_PATH} /src ${ ${LIB_SHORT_NAME} _RECURSE})
980
1018
if (LIB_SRCS)
981
1019
982
1020
arduino_debug_msg("Generating Arduino ${LIB_NAME} library" )
@@ -1174,7 +1212,7 @@ function(setup_arduino_bootloader_upload TARGET_NAME BOARD_ID PORT AVRDUDE_FLAGS
1174
1212
endif ()
1175
1213
set (TARGET_PATH ${EXECUTABLE_OUTPUT_PATH} /${TARGET_NAME} )
1176
1214
1177
- list (APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_PATH} .hex" )
1215
+ list (APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_PATH} .hex:i " )
1178
1216
list (APPEND AVRDUDE_ARGS "-Ueeprom:w:${TARGET_PATH} .eep:i" )
1179
1217
add_custom_target (${UPLOAD_TARGET}
1180
1218
${ARDUINO_AVRDUDE_PROGRAM}
@@ -1222,7 +1260,7 @@ function(setup_arduino_programmer_burn TARGET_NAME BOARD_ID PROGRAMMER PORT AVRD
1222
1260
endif ()
1223
1261
set (TARGET_PATH ${EXECUTABLE_OUTPUT_PATH} /${TARGET_NAME} )
1224
1262
1225
- list (APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_PATH} .hex" )
1263
+ list (APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_PATH} .hex:i " )
1226
1264
1227
1265
add_custom_target (${PROGRAMMER_TARGET}
1228
1266
${ARDUINO_AVRDUDE_PROGRAM}
@@ -1258,15 +1296,20 @@ function(setup_arduino_bootloader_burn TARGET_NAME BOARD_ID PROGRAMMER PORT AVRD
1258
1296
return ()
1259
1297
endif ()
1260
1298
1261
- foreach ( ITEM unlock_bits high_fuses low_fuses path file)
1299
+ foreach ( ITEM unlock_bits high_fuses low_fuses file )
1262
1300
if (NOT ${BOARD_ID} .bootloader.${ITEM} )
1263
1301
message ("Missing ${BOARD_ID} .bootloader.${ITEM} , not creating bootloader burn target ${BOOTLOADER_TARGET} ." )
1264
1302
return ()
1265
1303
endif ()
1266
1304
endforeach ()
1267
1305
1268
- if (NOT EXISTS "${ARDUINO_BOOTLOADERS_PATH} /${${BOARD_ID} .bootloader.path}/${${BOARD_ID} .bootloader.file}" )
1269
- message ("${ARDUINO_BOOTLOADERS_PATH} /${${BOARD_ID} .bootloader.path}/${${BOARD_ID} .bootloader.file}" )
1306
+ # If there is a .path entry, combine with file (as done in newer Arduino distributions)
1307
+ if (${BOARD_ID} .bootloader.path )
1308
+ set (${BOARD_ID} .bootloader.file "${${BOARD_ID} .bootloader.path}/${$(BOARD_ID}.bootloader.file}" )
1309
+ endif ()
1310
+ #
1311
+ if (NOT EXISTS "${ARDUINO_BOOTLOADERS_PATH} /${${BOARD_ID} .bootloader.file}" )
1312
+ message ("${ARDUINO_BOOTLOADERS_PATH} /${${BOARD_ID} .bootloader.file}" )
1270
1313
message ("Missing bootloader image, not creating bootloader burn target ${BOOTLOADER_TARGET} ." )
1271
1314
return ()
1272
1315
endif ()
@@ -1291,10 +1334,10 @@ function(setup_arduino_bootloader_burn TARGET_NAME BOARD_ID PROGRAMMER PORT AVRD
1291
1334
1292
1335
# Create burn bootloader target
1293
1336
add_custom_target (${BOOTLOADER_TARGET}
1294
- ${ARDUINO_AVRDUDE_PROGRAM}
1295
- ${AVRDUDE_ARGS}
1296
- WORKING_DIRECTORY ${ARDUINO_BOOTLOADERS_PATH} /${ ${BOARD_ID} .bootloader. path }
1297
- DEPENDS ${TARGET_NAME} )
1337
+ ${ARDUINO_AVRDUDE_PROGRAM}
1338
+ ${AVRDUDE_ARGS}
1339
+ WORKING_DIRECTORY ${ARDUINO_BOOTLOADERS_PATH}
1340
+ DEPENDS ${TARGET_NAME} )
1298
1341
endfunction ()
1299
1342
1300
1343
#=============================================================================#
@@ -1546,6 +1589,29 @@ function(LOAD_ARDUINO_STYLE_SETTINGS SETTINGS_LIST SETTINGS_PATH)
1546
1589
1547
1590
foreach (FILE_ENTRY ${FILE_ENTRIES} )
1548
1591
if ("${FILE_ENTRY} " MATCHES "^[^#]+=.*" )
1592
+ #
1593
+ # menu handling code
1594
+ # Newer versions of the Arduino IDE have allowed for multiple cpu types on
1595
+ # the same board. A menu has been introduced into the boards.txt file.
1596
+ # This code uses the variable MENU_SELECTION (set in the top-level CMakeLists.txt
1597
+ # to remove the menu text from the selected target board. This is not the
1598
+ # ideal solution to this problem.
1599
+ #
1600
+ if (MENU_SELECTION)
1601
+ list (LENGTH MENU_SELECTION NUM_MENUS)
1602
+ if (NOT NUM_MENUS EQUAL "1" )
1603
+ message (FATAL_ERROR "Only 1 menu selection is currently supported. You have ${NUM_MENUS} ." )
1604
+ endif ()
1605
+ #if("${FILE_ENTRY}" MATCHES ${MENU_OPTION})
1606
+ if ("${FILE_ENTRY} " MATCHES ${MENU_SELECTION} )
1607
+ string (REGEX REPLACE ${MENU_SELECTION} "" FILE_ENTRY ${FILE_ENTRY} )
1608
+ #else()
1609
+ #continue() #continue() isn't supported in CMake 2.8
1610
+ endif ()
1611
+ #endif()
1612
+ #
1613
+ # end menu handling code
1614
+ #
1549
1615
string (REGEX MATCH "^[^=]+" SETTING_NAME ${FILE_ENTRY} )
1550
1616
string (REGEX MATCH "[^=]+$" SETTING_VALUE ${FILE_ENTRY} )
1551
1617
string (REPLACE "." ";" ENTRY_NAME_TOKENS ${SETTING_NAME} )
@@ -1590,7 +1656,6 @@ function(LOAD_ARDUINO_STYLE_SETTINGS SETTINGS_LIST SETTINGS_PATH)
1590
1656
# Save setting value
1591
1657
set (${FULL_SETTING_NAME} ${SETTING_VALUE}
1592
1658
CACHE INTERNAL "Arduino ${ENTRY_NAME} Board setting" )
1593
-
1594
1659
1595
1660
endif ()
1596
1661
endforeach ()
@@ -2077,18 +2142,19 @@ endfunction()
2077
2142
#=============================================================================#
2078
2143
if (NOT DEFINED ARDUINO_C_FLAGS)
2079
2144
set (ARDUINO_C_FLAGS "-mcall-prologues -ffunction-sections -fdata-sections" )
2145
+ set (ARDUINO_C_FLAGS "${ARDUINO_C_FLAGS} -MMD -flto -Wall -Wextra -Wshadow -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums" )
2080
2146
endif (NOT DEFINED ARDUINO_C_FLAGS)
2081
- set (CMAKE_C_FLAGS "-g -Os ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2082
- set (CMAKE_C_FLAGS_DEBUG "-g ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2083
- set (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2084
- set (CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG -w ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2085
- set (CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -g -w ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2147
+ set (CMAKE_C_FLAGS "-g -Os -Wstrict-prototypes ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2148
+ set (CMAKE_C_FLAGS_DEBUG "-g -Wstrict-prototypes ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2149
+ set (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG -Wstrict-prototypes ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2150
+ set (CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG -Wstrict-prototypes ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2151
+ set (CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -g -Wstrict-prototypes ${ARDUINO_C_FLAGS} " CACHE STRING "" )
2086
2152
2087
2153
#=============================================================================#
2088
2154
# C++ Flags
2089
2155
#=============================================================================#
2090
2156
if (NOT DEFINED ARDUINO_CXX_FLAGS)
2091
- set (ARDUINO_CXX_FLAGS "${ARDUINO_C_FLAGS} -fno-exceptions" )
2157
+ set (ARDUINO_CXX_FLAGS "${ARDUINO_C_FLAGS} -std=gnu++11 - fno-exceptions" )
2092
2158
endif (NOT DEFINED ARDUINO_CXX_FLAGS)
2093
2159
set (CMAKE_CXX_FLAGS "-g -Os ${ARDUINO_CXX_FLAGS} " CACHE STRING "" )
2094
2160
set (CMAKE_CXX_FLAGS_DEBUG "-g ${ARDUINO_CXX_FLAGS} " CACHE STRING "" )
@@ -2108,7 +2174,7 @@ set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${ARDUINO_LINKER_FLAGS}" CACHE STRING
2108
2174
2109
2175
#=============================================================================#
2110
2176
#=============================================================================#
2111
- # Shared Lbrary Linker Flags #
2177
+ # Shared Library Linker Flags #
2112
2178
#=============================================================================#
2113
2179
set (CMAKE_SHARED_LINKER_FLAGS "${ARDUINO_LINKER_FLAGS} " CACHE STRING "" )
2114
2180
set (CMAKE_SHARED_LINKER_FLAGS_DEBUG "${ARDUINO_LINKER_FLAGS} " CACHE STRING "" )
@@ -2129,7 +2195,8 @@ set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "${ARDUINO_LINKER_FLAGS}" CACHE STR
2129
2195
set (ARDUINO_OBJCOPY_EEP_FLAGS -O ihex -j .eeprom --set-section-flags =.eeprom=alloc,load
2130
2196
--no -change-warnings --change-section-lma .eeprom=0 CACHE STRING "" )
2131
2197
set (ARDUINO_OBJCOPY_HEX_FLAGS -O ihex -R .eeprom CACHE STRING "" )
2132
- set (ARDUINO_AVRDUDE_FLAGS -V CACHE STRING "" )
2198
+ #set(ARDUINO_AVRDUDE_FLAGS -V CACHE STRING "")
2199
+ set (ARDUINO_AVRDUDE_FLAGS " " CACHE STRING "" ) #turn on verification of upload
2133
2200
2134
2201
#=============================================================================#
2135
2202
# Initialization
@@ -2141,6 +2208,8 @@ if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH)
2141
2208
NAMES libraries
2142
2209
PATHS ${ARDUINO_SDK_PATH}
2143
2210
DOC "Path to directory containing the Arduino libraries." )
2211
+ # Add architecture-specific libraries path to generic libraries path
2212
+ list (APPEND ARDUINO_LIBRARIES_PATH ${ARDUINO_ARCHITECTURE_LIBRARIES_PATH} )
2144
2213
2145
2214
find_file (ARDUINO_VERSION_PATH
2146
2215
NAMES lib/version .txt
0 commit comments