Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304
  1. #=============================================================================#
  2. # generate_arduino_firmware(name
  3. # [BOARD board_id]
  4. # [SKETCH sketch_path |
  5. # SRCS src1 src2 ... srcN]
  6. # [HDRS hdr1 hdr2 ... hdrN]
  7. # [LIBS lib1 lib2 ... libN]
  8. # [PORT port]
  9. # [SERIAL serial_cmd]
  10. # [PROGRAMMER programmer_id]
  11. # [AFLAGS flags]
  12. # [NO_AUTOLIBS]
  13. # [MANUAL])
  14. #
  15. #=============================================================================#
  16. #
  17. # generaters firmware and libraries for Arduino devices
  18. #
  19. # The arguments are as follows:
  20. #
  21. # name # The name of the firmware target [REQUIRED]
  22. # BOARD # Board name (such as uno, mega2560, ...) [REQUIRED]
  23. # SKETCH # Arduino sketch [must have SRCS or SKETCH]
  24. # SRCS # Sources [must have SRCS or SKETCH]
  25. # HDRS # Headers
  26. # LIBS # Libraries to link
  27. # ARDLIBS # Arduino libraries to link (Wire, Servo, SPI, etc)
  28. # PORT # Serial port (enables upload support)
  29. # SERIAL # Serial command for serial target
  30. # PROGRAMMER # Programmer id (enables programmer support)
  31. # AFLAGS # Avrdude flags for target
  32. # NO_AUTOLIBS # Disables Arduino library detection
  33. # MANUAL # (Advanced) Only use AVR Libc/Includes
  34. #
  35. # Here is a short example for a target named test:
  36. #
  37. # generate_arduino_firmware(
  38. # NAME test
  39. # SRCS test.cpp
  40. # test2.cpp
  41. # HDRS test.h test2.h
  42. # BOARD uno)
  43. #
  44. # Alternatively you can specify the option by variables:
  45. #
  46. # set(test_SRCS test.cpp test2.cpp)
  47. # set(test_HDRS test.h test2.h
  48. # set(test_BOARD uno)
  49. #
  50. # generate_arduino_firmware(test)
  51. #
  52. # All variables need to be prefixed with the target name (${TARGET_NAME}_${OPTION}).
  53. #
  54. #=============================================================================#
  55. # generate_avr_firmware(name
  56. # [BOARD board_id]
  57. # SRCS src1 src2 ... srcN]
  58. # [HDRS hdr1 hdr2 ... hdrN]
  59. # [LIBS lib1 lib2 ... libN]
  60. # [PORT port]
  61. # [SERIAL serial_cmd]
  62. # [PROGRAMMER programmer_id]
  63. # [AFLAGS flags])
  64. #=============================================================================#
  65. #
  66. # generaters firmware and libraries for AVR devices
  67. # it simply calls generate_arduino_firmware() with NO_AUTOLIBS and MANUAL
  68. #
  69. # The arguments are as follows:
  70. #
  71. # name # The name of the firmware target [REQUIRED]
  72. # BOARD # Board name (such as uno, mega2560, ...) [REQUIRED]
  73. # SRCS # Sources [REQUIRED]
  74. # HDRS # Headers
  75. # LIBS # Libraries to link
  76. # PORT # Serial port (enables upload support)
  77. # SERIAL # Serial command for serial target
  78. # PROGRAMMER # Programmer id (enables programmer support)
  79. # AFLAGS # Avrdude flags for target
  80. #
  81. # Here is a short example for a target named test:
  82. #
  83. # generate_avr_firmware(
  84. # NAME test
  85. # SRCS test.cpp
  86. # test2.cpp
  87. # HDRS test.h test2.h
  88. # BOARD uno)
  89. #
  90. # Alternatively you can specify the option by variables:
  91. #
  92. # set(test_SRCS test.cpp test2.cpp)
  93. # set(test_HDRS test.h test2.h
  94. # set(test_BOARD uno)
  95. #
  96. # generate_avr_firmware(test)
  97. #
  98. # All variables need to be prefixed with the target name (${TARGET_NAME}_${OPTION}).
  99. #
  100. #=============================================================================#
  101. # generate_arduino_library(name
  102. # [BOARD board_id]
  103. # [SRCS src1 src2 ... srcN]
  104. # [HDRS hdr1 hdr2 ... hdrN]
  105. # [LIBS lib1 lib2 ... libN]
  106. # [NO_AUTOLIBS]
  107. # [MANUAL])
  108. #=============================================================================#
  109. # generaters firmware and libraries for Arduino devices
  110. #
  111. # The arguments are as follows:
  112. #
  113. # name # The name of the firmware target [REQUIRED]
  114. # BOARD # Board name (such as uno, mega2560, ...) [REQUIRED]
  115. # SRCS # Sources [REQUIRED]
  116. # HDRS # Headers
  117. # LIBS # Libraries to link
  118. # NO_AUTOLIBS # Disables Arduino library detection
  119. # MANUAL # (Advanced) Only use AVR Libc/Includes
  120. #
  121. # Here is a short example for a target named test:
  122. #
  123. # generate_arduino_library(
  124. # NAME test
  125. # SRCS test.cpp
  126. # test2.cpp
  127. # HDRS test.h test2.h
  128. # BOARD uno)
  129. #
  130. # Alternatively you can specify the option by variables:
  131. #
  132. # set(test_SRCS test.cpp test2.cpp)
  133. # set(test_HDRS test.h test2.h
  134. # set(test_BOARD uno)
  135. #
  136. # generate_arduino_library(test)
  137. #
  138. # All variables need to be prefixed with the target name (${TARGET_NAME}_${OPTION}).
  139. #
  140. #=============================================================================#
  141. # generate_avr_library(name
  142. # [BOARD board_id]
  143. # [SRCS src1 src2 ... srcN]
  144. # [HDRS hdr1 hdr2 ... hdrN]
  145. # [LIBS lib1 lib2 ... libN])
  146. #=============================================================================#
  147. # generaters firmware and libraries for AVR devices
  148. # it simply calls generate_arduino_library() with NO_AUTOLIBS and MANUAL
  149. #
  150. # The arguments are as follows:
  151. #
  152. # name # The name of the firmware target [REQUIRED]
  153. # BOARD # Board name (such as uno, mega2560, ...) [REQUIRED]
  154. # SRCS # Sources [REQUIRED]
  155. # HDRS # Headers
  156. # LIBS # Libraries to link
  157. #
  158. # Here is a short example for a target named test:
  159. #
  160. # generate_avr_library(
  161. # NAME test
  162. # SRCS test.cpp
  163. # test2.cpp
  164. # HDRS test.h test2.h
  165. # BOARD uno)
  166. #
  167. # Alternatively you can specify the option by variables:
  168. #
  169. # set(test_SRCS test.cpp test2.cpp)
  170. # set(test_HDRS test.h test2.h
  171. # set(test_BOARD uno)
  172. #
  173. # generate_avr_library(test)
  174. #
  175. # All variables need to be prefixed with the target name (${TARGET_NAME}_${OPTION}).
  176. #
  177. #=============================================================================#
  178. # generate_arduino_example(name
  179. # LIBRARY library_name
  180. # EXAMPLE example_name
  181. # [BOARD board_id]
  182. # [PORT port]
  183. # [SERIAL serial command]
  184. # [PORGRAMMER programmer_id]
  185. # [AFLAGS avrdude_flags])
  186. #=============================================================================#
  187. #
  188. # name - The name of the library example [REQUIRED]
  189. # LIBRARY - Library name [REQUIRED]
  190. # EXAMPLE - Example name [REQUIRED]
  191. # BOARD - Board ID
  192. # PORT - Serial port [optional]
  193. # SERIAL - Serial command [optional]
  194. # PROGRAMMER - Programmer id (enables programmer support)
  195. # AFLAGS - Avrdude flags for target
  196. #
  197. # Creates a example from the specified library.
  198. #
  199. #
  200. #=============================================================================#
  201. # print_board_list()
  202. #=============================================================================#
  203. #
  204. # Print list of detected Arduino Boards.
  205. #
  206. #=============================================================================#
  207. # print_programmer_list()
  208. #=============================================================================#
  209. #
  210. # Print list of detected Programmers.
  211. #
  212. #=============================================================================#
  213. # print_programmer_settings(PROGRAMMER)
  214. #=============================================================================#
  215. #
  216. # PROGRAMMER - programmer id
  217. #
  218. # Print the detected Programmer settings.
  219. #
  220. #=============================================================================#
  221. # print_board_settings(ARDUINO_BOARD)
  222. #=============================================================================#
  223. #
  224. # ARDUINO_BOARD - Board id
  225. #
  226. # Print the detected Arduino board settings.
  227. #
  228. #=============================================================================#
  229. # register_hardware_platform(HARDWARE_PLATFORM_PATH)
  230. #=============================================================================#
  231. #
  232. # HARDWARE_PLATFORM_PATH - Hardware platform path
  233. #
  234. # Registers a Hardware Platform path.
  235. # See: http://code.google.com/p/arduino/wiki/Platforms
  236. #
  237. # This enables you to register new types of hardware platforms such as the
  238. # Sagnuino, without having to copy the files into your Arduion SDK.
  239. #
  240. # A Hardware Platform is a directory containing the following:
  241. #
  242. # HARDWARE_PLATFORM_PATH/
  243. # |-- bootloaders/
  244. # |-- cores/
  245. # |-- variants/
  246. # |-- boards.txt
  247. # `-- programmers.txt
  248. #
  249. # The board.txt describes the target boards and bootloaders. While
  250. # programmers.txt the programmer defintions.
  251. #
  252. # A good example of a Hardware Platform is in the Arduino SDK:
  253. #
  254. # ${ARDUINO_SDK_PATH}/hardware/arduino/
  255. #
  256. #=============================================================================#
  257. # Configuration Options
  258. #=============================================================================#
  259. #
  260. # ARDUINO_SDK_PATH - Arduino SDK Path
  261. # ARDUINO_AVRDUDE_PROGRAM - Full path to avrdude programmer
  262. # ARDUINO_AVRDUDE_CONFIG_PATH - Full path to avrdude configuration file
  263. #
  264. # ARDUINO_C_FLAGS - C compiler flags
  265. # ARDUINO_CXX_FLAGS - C++ compiler flags
  266. # ARDUINO_LINKER_FLAGS - Linker flags
  267. #
  268. # ARDUINO_DEFAULT_BOARD - Default Arduino Board ID when not specified.
  269. # ARDUINO_DEFAULT_PORT - Default Arduino port when not specified.
  270. # ARDUINO_DEFAULT_SERIAL - Default Arduino Serial command when not specified.
  271. # ARDUINO_DEFAULT_PROGRAMMER - Default Arduino Programmer ID when not specified.
  272. #
  273. #
  274. # ARDUINO_FOUND - Set to True when the Arduino SDK is detected and configured.
  275. # ARDUINO_SDK_VERSION - Set to the version of the detected Arduino SDK (ex: 1.0)
  276. #=============================================================================#
  277. # Author: Tomasz Bogdal (QueezyTheGreat)
  278. # Home: https://github.com/queezythegreat/arduino-cmake
  279. #
  280. # This Source Code Form is subject to the terms of the Mozilla Public
  281. # License, v. 2.0. If a copy of the MPL was not distributed with this file,
  282. # You can obtain one at http://mozilla.org/MPL/2.0/.
  283. #=============================================================================#
  284. cmake_minimum_required(VERSION 2.8.5)
  285. include(CMakeParseArguments)
  286. #=============================================================================#
  287. # User Functions
  288. #=============================================================================#
  289. #=============================================================================#
  290. # [PUBLIC/USER]
  291. #
  292. # print_board_list()
  293. #
  294. # see documentation at top
  295. #=============================================================================#
  296. function(PRINT_BOARD_LIST)
  297. foreach(PLATFORM ${ARDUINO_PLATFORMS})
  298. if(${PLATFORM}_BOARDS)
  299. message(STATUS "${PLATFORM} Boards:")
  300. print_list(${PLATFORM}_BOARDS)
  301. message(STATUS "")
  302. endif()
  303. endforeach()
  304. endfunction()
  305. #=============================================================================#
  306. # [PUBLIC/USER]
  307. #
  308. # print_programmer_list()
  309. #
  310. # see documentation at top
  311. #=============================================================================#
  312. function(PRINT_PROGRAMMER_LIST)
  313. foreach(PLATFORM ${ARDUINO_PLATFORMS})
  314. if(${PLATFORM}_PROGRAMMERS)
  315. message(STATUS "${PLATFORM} Programmers:")
  316. print_list(${PLATFORM}_PROGRAMMERS)
  317. endif()
  318. message(STATUS "")
  319. endforeach()
  320. endfunction()
  321. #=============================================================================#
  322. # [PUBLIC/USER]
  323. #
  324. # print_programmer_settings(PROGRAMMER)
  325. #
  326. # see documentation at top
  327. #=============================================================================#
  328. function(PRINT_PROGRAMMER_SETTINGS PROGRAMMER)
  329. if(${PROGRAMMER}.SETTINGS)
  330. message(STATUS "Programmer ${PROGRAMMER} Settings:")
  331. print_settings(${PROGRAMMER})
  332. endif()
  333. endfunction()
  334. # [PUBLIC/USER]
  335. #
  336. # print_board_settings(ARDUINO_BOARD)
  337. #
  338. # see documentation at top
  339. function(PRINT_BOARD_SETTINGS ARDUINO_BOARD)
  340. if(${ARDUINO_BOARD}.SETTINGS)
  341. message(STATUS "Arduino ${ARDUINO_BOARD} Board:")
  342. print_settings(${ARDUINO_BOARD})
  343. endif()
  344. endfunction()
  345. #=============================================================================#
  346. # [PUBLIC/USER]
  347. # see documentation at top
  348. #=============================================================================#
  349. function(GENERATE_ARDUINO_LIBRARY INPUT_NAME)
  350. message(STATUS "Generating ${INPUT_NAME}")
  351. parse_generator_arguments(${INPUT_NAME} INPUT
  352. "NO_AUTOLIBS;MANUAL" # Options
  353. "BOARD" # One Value Keywords
  354. "SRCS;HDRS;LIBS" # Multi Value Keywords
  355. ${ARGN})
  356. if(NOT INPUT_BOARD)
  357. set(INPUT_BOARD ${ARDUINO_DEFAULT_BOARD})
  358. endif()
  359. if(NOT INPUT_MANUAL)
  360. set(INPUT_MANUAL FALSE)
  361. endif()
  362. required_variables(VARS INPUT_SRCS INPUT_BOARD MSG "must define for target ${INPUT_NAME}")
  363. set(ALL_LIBS)
  364. set(ALL_SRCS ${INPUT_SRCS} ${INPUT_HDRS})
  365. if(NOT INPUT_MANUAL)
  366. setup_arduino_core(CORE_LIB ${INPUT_BOARD})
  367. endif()
  368. find_arduino_libraries(TARGET_LIBS "${ALL_SRCS}" "")
  369. set(LIB_DEP_INCLUDES)
  370. foreach(LIB_DEP ${TARGET_LIBS})
  371. set(LIB_DEP_INCLUDES "${LIB_DEP_INCLUDES} -I\"${LIB_DEP}\"")
  372. endforeach()
  373. if(NOT ${INPUT_NO_AUTOLIBS})
  374. setup_arduino_libraries(ALL_LIBS ${INPUT_BOARD} "${ALL_SRCS}" "" "${LIB_DEP_INCLUDES}" "")
  375. endif()
  376. list(APPEND ALL_LIBS ${CORE_LIB} ${INPUT_LIBS})
  377. add_library(${INPUT_NAME} ${ALL_SRCS})
  378. get_arduino_flags(ARDUINO_COMPILE_FLAGS ARDUINO_LINK_FLAGS ${INPUT_BOARD} ${INPUT_MANUAL})
  379. set_target_properties(${INPUT_NAME} PROPERTIES
  380. COMPILE_FLAGS "${ARDUINO_COMPILE_FLAGS} ${COMPILE_FLAGS} ${LIB_DEP_INCLUDES}"
  381. LINK_FLAGS "${ARDUINO_LINK_FLAGS} ${LINK_FLAGS}")
  382. target_link_libraries(${INPUT_NAME} ${ALL_LIBS} "-lc -lm")
  383. endfunction()
  384. #=============================================================================#
  385. # [PUBLIC/USER]
  386. # see documentation at top
  387. #=============================================================================#
  388. function(GENERATE_AVR_LIBRARY INPUT_NAME)
  389. message(STATUS "Generating ${INPUT_NAME}")
  390. parse_generator_arguments(${INPUT_NAME} INPUT
  391. "NO_AUTOLIBS;MANUAL" # Options
  392. "BOARD" # One Value Keywords
  393. "SRCS;HDRS;LIBS" # Multi Value Keywords
  394. ${ARGN})
  395. if(NOT INPUT_BOARD)
  396. set(INPUT_BOARD ${ARDUINO_DEFAULT_BOARD})
  397. endif()
  398. required_variables(VARS INPUT_SRCS INPUT_BOARD MSG "must define for target ${INPUT_NAME}")
  399. if(INPUT_HDRS)
  400. set( INPUT_HDRS "SRCS ${INPUT_HDRS}" )
  401. endif()
  402. if(INPUT_LIBS)
  403. set( INPUT_LIBS "LIBS ${INPUT_LIBS}" )
  404. endif()
  405. if(INPUT_HDRS)
  406. list(INSERT INPUT_HDRS 0 "HDRS")
  407. endif()
  408. if(INPUT_LIBS)
  409. list(INSERT INPUT_LIBS 0 "LIBS")
  410. endif()
  411. generate_arduino_library( ${INPUT_NAME}
  412. NO_AUTOLIBS
  413. MANUAL
  414. BOARD ${INPUT_BOARD}
  415. SRCS ${INPUT_SRCS}
  416. ${INPUT_HDRS}
  417. ${INPUT_LIBS} )
  418. endfunction()
  419. #=============================================================================#
  420. # [PUBLIC/USER]
  421. # see documentation at top
  422. #=============================================================================#
  423. function(GENERATE_ARDUINO_FIRMWARE INPUT_NAME)
  424. message(STATUS "Generating ${INPUT_NAME}")
  425. parse_generator_arguments(${INPUT_NAME} INPUT
  426. "NO_AUTOLIBS;MANUAL" # Options
  427. "BOARD;PORT;SKETCH;PROGRAMMER" # One Value Keywords
  428. "SERIAL;SRCS;HDRS;LIBS;ARDLIBS;AFLAGS" # Multi Value Keywords
  429. ${ARGN})
  430. if(NOT INPUT_BOARD)
  431. set(INPUT_BOARD ${ARDUINO_DEFAULT_BOARD})
  432. endif()
  433. if(NOT INPUT_PORT)
  434. set(INPUT_PORT ${ARDUINO_DEFAULT_PORT})
  435. endif()
  436. if(NOT INPUT_SERIAL)
  437. set(INPUT_SERIAL ${ARDUINO_DEFAULT_SERIAL})
  438. endif()
  439. if(NOT INPUT_PROGRAMMER)
  440. set(INPUT_PROGRAMMER ${ARDUINO_DEFAULT_PROGRAMMER})
  441. endif()
  442. if(NOT INPUT_MANUAL)
  443. set(INPUT_MANUAL FALSE)
  444. endif()
  445. required_variables(VARS INPUT_BOARD MSG "must define for target ${INPUT_NAME}")
  446. set(ALL_LIBS)
  447. set(ALL_SRCS ${INPUT_SRCS} ${INPUT_HDRS})
  448. set(LIB_DEP_INCLUDES)
  449. if(NOT INPUT_MANUAL)
  450. setup_arduino_core(CORE_LIB ${INPUT_BOARD})
  451. endif()
  452. if(NOT "${INPUT_SKETCH}" STREQUAL "")
  453. get_filename_component(INPUT_SKETCH "${INPUT_SKETCH}" ABSOLUTE)
  454. setup_arduino_sketch(${INPUT_NAME} ${INPUT_SKETCH} ALL_SRCS)
  455. if (IS_DIRECTORY "${INPUT_SKETCH}")
  456. set(LIB_DEP_INCLUDES "${LIB_DEP_INCLUDES} -I\"${INPUT_SKETCH}\"")
  457. else()
  458. get_filename_component(INPUT_SKETCH_PATH "${INPUT_SKETCH}" PATH)
  459. set(LIB_DEP_INCLUDES "${LIB_DEP_INCLUDES} -I\"${INPUT_SKETCH_PATH}\"")
  460. endif()
  461. endif()
  462. required_variables(VARS ALL_SRCS MSG "must define SRCS or SKETCH for target ${INPUT_NAME}")
  463. find_arduino_libraries(TARGET_LIBS "${ALL_SRCS}" "${INPUT_ARDLIBS}")
  464. foreach(LIB_DEP ${TARGET_LIBS})
  465. arduino_debug_msg("Arduino Library: ${LIB_DEP}")
  466. set(LIB_DEP_INCLUDES "${LIB_DEP_INCLUDES} -I\"${LIB_DEP}\" -I\"${LIB_DEP}/src\"")
  467. endforeach()
  468. if(NOT INPUT_NO_AUTOLIBS)
  469. setup_arduino_libraries(ALL_LIBS ${INPUT_BOARD} "${ALL_SRCS}" "${INPUT_ARDLIBS}" "${LIB_DEP_INCLUDES}" "")
  470. foreach(LIB_INCLUDES ${ALL_LIBS_INCLUDES})
  471. arduino_debug_msg("Arduino Library Includes: ${LIB_INCLUDES}")
  472. set(LIB_DEP_INCLUDES "${LIB_DEP_INCLUDES} ${LIB_INCLUDES}")
  473. endforeach()
  474. endif()
  475. list(APPEND ALL_LIBS ${CORE_LIB} ${INPUT_LIBS})
  476. setup_arduino_target(${INPUT_NAME} ${INPUT_BOARD} "${ALL_SRCS}" "${ALL_LIBS}" "${LIB_DEP_INCLUDES}" "" "${INPUT_MANUAL}")
  477. if(INPUT_PORT)
  478. setup_arduino_upload(${INPUT_BOARD} ${INPUT_NAME} ${INPUT_PORT} "${INPUT_PROGRAMMER}" "${INPUT_AFLAGS}")
  479. endif()
  480. if(INPUT_SERIAL)
  481. setup_serial_target(${INPUT_NAME} "${INPUT_SERIAL}" "${INPUT_PORT}")
  482. endif()
  483. endfunction()
  484. #=============================================================================#
  485. # [PUBLIC/USER]
  486. # see documentation at top
  487. #=============================================================================#
  488. function(GENERATE_AVR_FIRMWARE INPUT_NAME)
  489. # TODO: This is not optimal!!!!
  490. message(STATUS "Generating ${INPUT_NAME}")
  491. parse_generator_arguments(${INPUT_NAME} INPUT
  492. "NO_AUTOLIBS;MANUAL" # Options
  493. "BOARD;PORT;PROGRAMMER" # One Value Keywords
  494. "SERIAL;SRCS;HDRS;LIBS;AFLAGS" # Multi Value Keywords
  495. ${ARGN})
  496. if(NOT INPUT_BOARD)
  497. set(INPUT_BOARD ${ARDUINO_DEFAULT_BOARD})
  498. endif()
  499. if(NOT INPUT_PORT)
  500. set(INPUT_PORT ${ARDUINO_DEFAULT_PORT})
  501. endif()
  502. if(NOT INPUT_SERIAL)
  503. set(INPUT_SERIAL ${ARDUINO_DEFAULT_SERIAL})
  504. endif()
  505. if(NOT INPUT_PROGRAMMER)
  506. set(INPUT_PROGRAMMER ${ARDUINO_DEFAULT_PROGRAMMER})
  507. endif()
  508. required_variables(VARS INPUT_BOARD INPUT_SRCS MSG "must define for target ${INPUT_NAME}")
  509. if(INPUT_HDRS)
  510. list(INSERT INPUT_HDRS 0 "HDRS")
  511. endif()
  512. if(INPUT_LIBS)
  513. list(INSERT INPUT_LIBS 0 "LIBS")
  514. endif()
  515. if(INPUT_AFLAGS)
  516. list(INSERT INPUT_AFLAGS 0 "AFLAGS")
  517. endif()
  518. generate_arduino_firmware( ${INPUT_NAME}
  519. NO_AUTOLIBS
  520. MANUAL
  521. BOARD ${INPUT_BOARD}
  522. PORT ${INPUT_PORT}
  523. PROGRAMMER ${INPUT_PROGRAMMER}
  524. SERIAL ${INPUT_SERIAL}
  525. SRCS ${INPUT_SRCS}
  526. ${INPUT_HDRS}
  527. ${INPUT_LIBS}
  528. ${INPUT_AFLAGS} )
  529. endfunction()
  530. #=============================================================================#
  531. # [PUBLIC/USER]
  532. # see documentation at top
  533. #=============================================================================#
  534. function(GENERATE_ARDUINO_EXAMPLE INPUT_NAME)
  535. parse_generator_arguments(${INPUT_NAME} INPUT
  536. "" # Options
  537. "LIBRARY;EXAMPLE;BOARD;PORT;PROGRAMMER" # One Value Keywords
  538. "SERIAL;AFLAGS" # Multi Value Keywords
  539. ${ARGN})
  540. if(NOT INPUT_BOARD)
  541. set(INPUT_BOARD ${ARDUINO_DEFAULT_BOARD})
  542. endif()
  543. if(NOT INPUT_PORT)
  544. set(INPUT_PORT ${ARDUINO_DEFAULT_PORT})
  545. endif()
  546. if(NOT INPUT_SERIAL)
  547. set(INPUT_SERIAL ${ARDUINO_DEFAULT_SERIAL})
  548. endif()
  549. if(NOT INPUT_PROGRAMMER)
  550. set(INPUT_PROGRAMMER ${ARDUINO_DEFAULT_PROGRAMMER})
  551. endif()
  552. required_variables(VARS INPUT_LIBRARY INPUT_EXAMPLE INPUT_BOARD
  553. MSG "must define for target ${INPUT_NAME}")
  554. message(STATUS "Generating ${INPUT_NAME}")
  555. set(ALL_LIBS)
  556. set(ALL_SRCS)
  557. setup_arduino_core(CORE_LIB ${INPUT_BOARD})
  558. setup_arduino_example("${INPUT_NAME}" "${INPUT_LIBRARY}" "${INPUT_EXAMPLE}" ALL_SRCS)
  559. if(NOT ALL_SRCS)
  560. message(FATAL_ERROR "Missing sources for example, aborting!")
  561. endif()
  562. find_arduino_libraries(TARGET_LIBS "${ALL_SRCS}" "")
  563. set(LIB_DEP_INCLUDES)
  564. foreach(LIB_DEP ${TARGET_LIBS})
  565. set(LIB_DEP_INCLUDES "${LIB_DEP_INCLUDES} -I\"${LIB_DEP}\"")
  566. endforeach()
  567. setup_arduino_libraries(ALL_LIBS ${INPUT_BOARD} "${ALL_SRCS}" "" "${LIB_DEP_INCLUDES}" "")
  568. list(APPEND ALL_LIBS ${CORE_LIB} ${INPUT_LIBS})
  569. setup_arduino_target(${INPUT_NAME} ${INPUT_BOARD} "${ALL_SRCS}" "${ALL_LIBS}" "${LIB_DEP_INCLUDES}" "" FALSE)
  570. if(INPUT_PORT)
  571. setup_arduino_upload(${INPUT_BOARD} ${INPUT_NAME} ${INPUT_PORT} "${INPUT_PROGRAMMER}" "${INPUT_AFLAGS}")
  572. endif()
  573. if(INPUT_SERIAL)
  574. setup_serial_target(${INPUT_NAME} "${INPUT_SERIAL}" "${INPUT_PORT}")
  575. endif()
  576. endfunction()
  577. #=============================================================================#
  578. # [PUBLIC/USER]
  579. # see documentation at top
  580. #=============================================================================#
  581. function(REGISTER_HARDWARE_PLATFORM PLATFORM_PATH)
  582. string(REGEX REPLACE "/$" "" PLATFORM_PATH ${PLATFORM_PATH})
  583. GET_FILENAME_COMPONENT(PLATFORM ${PLATFORM_PATH} NAME)
  584. if(PLATFORM)
  585. string(TOUPPER ${PLATFORM} PLATFORM)
  586. list(FIND ARDUINO_PLATFORMS ${PLATFORM} platform_exists)
  587. if (platform_exists EQUAL -1)
  588. set(${PLATFORM}_PLATFORM_PATH ${PLATFORM_PATH} CACHE INTERNAL "The path to ${PLATFORM}")
  589. set(ARDUINO_PLATFORMS ${ARDUINO_PLATFORMS} ${PLATFORM} CACHE INTERNAL "A list of registered platforms")
  590. find_file(${PLATFORM}_CORES_PATH
  591. NAMES cores
  592. PATHS ${PLATFORM_PATH}
  593. DOC "Path to directory containing the Arduino core sources."
  594. NO_SYSTEM_ENVIRONMENT_PATH)
  595. find_file(${PLATFORM}_VARIANTS_PATH
  596. NAMES variants
  597. PATHS ${PLATFORM_PATH}
  598. DOC "Path to directory containing the Arduino variant sources."
  599. NO_SYSTEM_ENVIRONMENT_PATH)
  600. find_file(${PLATFORM}_BOOTLOADERS_PATH
  601. NAMES bootloaders
  602. PATHS ${PLATFORM_PATH}
  603. DOC "Path to directory containing the Arduino bootloader images and sources."
  604. NO_SYSTEM_ENVIRONMENT_PATH)
  605. find_file(${PLATFORM}_LIBRARIES_PATH
  606. NAMES libraries
  607. PATHS ${PLATFORM_PATH}
  608. DOC "Path to directory containing the Arduino hardware libraries sources."
  609. NO_SYSTEM_ENVIRONMENT_PATH)
  610. find_file(${PLATFORM}_PROGRAMMERS_PATH
  611. NAMES programmers.txt
  612. PATHS ${PLATFORM_PATH}
  613. DOC "Path to Arduino programmers definition file."
  614. NO_SYSTEM_ENVIRONMENT_PATH)
  615. find_file(${PLATFORM}_BOARDS_PATH
  616. NAMES boards.txt
  617. PATHS ${PLATFORM_PATH}
  618. DOC "Path to Arduino boards definition file."
  619. NO_SYSTEM_ENVIRONMENT_PATH)
  620. if(${PLATFORM}_BOARDS_PATH)
  621. load_arduino_style_settings(${PLATFORM}_BOARDS "${PLATFORM_PATH}/boards.txt")
  622. endif()
  623. if(${PLATFORM}_PROGRAMMERS_PATH)
  624. load_arduino_style_settings(${PLATFORM}_PROGRAMMERS "${ARDUINO_PROGRAMMERS_PATH}")
  625. endif()
  626. if(${PLATFORM}_VARIANTS_PATH)
  627. file(GLOB sub-dir ${${PLATFORM}_VARIANTS_PATH}/*)
  628. foreach(dir ${sub-dir})
  629. if(IS_DIRECTORY ${dir})
  630. get_filename_component(variant ${dir} NAME)
  631. set(VARIANTS ${VARIANTS} ${variant} CACHE INTERNAL "A list of registered variant boards")
  632. set(${variant}.path ${dir} CACHE INTERNAL "The path to the variant ${variant}")
  633. endif()
  634. endforeach()
  635. endif()
  636. if(${PLATFORM}_CORES_PATH)
  637. file(GLOB sub-dir ${${PLATFORM}_CORES_PATH}/*)
  638. foreach(dir ${sub-dir})
  639. if(IS_DIRECTORY ${dir})
  640. get_filename_component(core ${dir} NAME)
  641. set(CORES ${CORES} ${core} CACHE INTERNAL "A list of registered cores")
  642. set(${core}.path ${dir} CACHE INTERNAL "The path to the core ${core}")
  643. endif()
  644. endforeach()
  645. endif()
  646. endif()
  647. endif()
  648. endfunction()
  649. #=============================================================================#
  650. # Internal Functions
  651. #=============================================================================#
  652. #=============================================================================#
  653. # [PRIVATE/INTERNAL]
  654. #
  655. # parse_generator_arguments(TARGET_NAME PREFIX OPTIONS ARGS MULTI_ARGS [ARG1 ARG2 .. ARGN])
  656. #
  657. # PREFIX - Parsed options prefix
  658. # OPTIONS - List of options
  659. # ARGS - List of one value keyword arguments
  660. # MULTI_ARGS - List of multi value keyword arguments
  661. # [ARG1 ARG2 .. ARGN] - command arguments [optional]
  662. #
  663. # Parses generator options from either variables or command arguments
  664. #
  665. #=============================================================================#
  666. macro(PARSE_GENERATOR_ARGUMENTS TARGET_NAME PREFIX OPTIONS ARGS MULTI_ARGS)
  667. cmake_parse_arguments(${PREFIX} "${OPTIONS}" "${ARGS}" "${MULTI_ARGS}" ${ARGN})
  668. error_for_unparsed(${PREFIX})
  669. load_generator_settings(${TARGET_NAME} ${PREFIX} ${OPTIONS} ${ARGS} ${MULTI_ARGS})
  670. endmacro()
  671. #=============================================================================#
  672. # [PRIVATE/INTERNAL]
  673. #
  674. # load_generator_settings(TARGET_NAME PREFIX [SUFFIX_1 SUFFIX_2 .. SUFFIX_N])
  675. #
  676. # TARGET_NAME - The base name of the user settings
  677. # PREFIX - The prefix name used for generator settings
  678. # SUFFIX_XX - List of suffixes to load
  679. #
  680. # Loads a list of user settings into the generators scope. User settings have
  681. # the following syntax:
  682. #
  683. # ${BASE_NAME}${SUFFIX}
  684. #
  685. # The BASE_NAME is the target name and the suffix is a specific generator settings.
  686. #
  687. # For every user setting found a generator setting is created of the follwoing fromat:
  688. #
  689. # ${PREFIX}${SUFFIX}
  690. #
  691. # The purpose of loading the settings into the generator is to not modify user settings
  692. # and to have a generic naming of the settings within the generator.
  693. #
  694. #=============================================================================#
  695. function(LOAD_GENERATOR_SETTINGS TARGET_NAME PREFIX)
  696. foreach(GEN_SUFFIX ${ARGN})
  697. if(${TARGET_NAME}_${GEN_SUFFIX} AND NOT ${PREFIX}_${GEN_SUFFIX})
  698. set(${PREFIX}_${GEN_SUFFIX} ${${TARGET_NAME}_${GEN_SUFFIX}} PARENT_SCOPE)
  699. endif()
  700. endforeach()
  701. endfunction()
  702. #=============================================================================#
  703. # [PRIVATE/INTERNAL]
  704. #
  705. # get_arduino_flags(COMPILE_FLAGS LINK_FLAGS BOARD_ID MANUAL)
  706. #
  707. # COMPILE_FLAGS_VAR -Variable holding compiler flags
  708. # LINK_FLAGS_VAR - Variable holding linker flags
  709. # BOARD_ID - The board id name
  710. # MANUAL - (Advanced) Only use AVR Libc/Includes
  711. #
  712. # Configures the the build settings for the specified Arduino Board.
  713. #
  714. #=============================================================================#
  715. function(get_arduino_flags COMPILE_FLAGS_VAR LINK_FLAGS_VAR BOARD_ID MANUAL)
  716. set(BOARD_CORE ${${BOARD_ID}.build.core})
  717. if(BOARD_CORE)
  718. if(ARDUINO_SDK_VERSION MATCHES "([0-9]+)[.]([0-9]+)[.]([0-9]+)")
  719. string(REPLACE "." "" ARDUINO_VERSION_DEFINE "${ARDUINO_SDK_VERSION}") # Normalize version (remove all periods)
  720. set(ARDUINO_VERSION_DEFINE "")
  721. if(CMAKE_MATCH_1 GREATER 0)
  722. set(ARDUINO_VERSION_DEFINE "${CMAKE_MATCH_1}")
  723. endif()
  724. if(CMAKE_MATCH_2 GREATER 10)
  725. set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}${CMAKE_MATCH_2}")
  726. else()
  727. set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}0${CMAKE_MATCH_2}")
  728. endif()
  729. if(CMAKE_MATCH_3 GREATER 10)
  730. set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}${CMAKE_MATCH_3}")
  731. else()
  732. set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}0${CMAKE_MATCH_3}")
  733. endif()
  734. else()
  735. message("Invalid Arduino SDK Version (${ARDUINO_SDK_VERSION})")
  736. endif()
  737. # output
  738. set(COMPILE_FLAGS "-DF_CPU=${${BOARD_ID}${ARDUINO_CPUMENU}.build.f_cpu} -DARDUINO=${ARDUINO_VERSION_DEFINE} -DARDUINO_${${BOARD_ID}.build.board} -DARDUINO_ARCH_AVR -mmcu=${${BOARD_ID}${ARDUINO_CPUMENU}.build.mcu}")
  739. if(DEFINED ${BOARD_ID}.build.vid)
  740. set(COMPILE_FLAGS "${COMPILE_FLAGS} -DUSB_VID=${${BOARD_ID}.build.vid}")
  741. endif()
  742. if(DEFINED ${BOARD_ID}.build.pid)
  743. set(COMPILE_FLAGS "${COMPILE_FLAGS} -DUSB_PID=${${BOARD_ID}.build.pid}")
  744. endif()
  745. if(NOT MANUAL)
  746. set(COMPILE_FLAGS "${COMPILE_FLAGS} -I\"${${BOARD_CORE}.path}\" -I\"${ARDUINO_LIBRARIES_PATH}\"")
  747. endif()
  748. set(LINK_FLAGS "-mmcu=${${BOARD_ID}${ARDUINO_CPUMENU}.build.mcu}")
  749. if(ARDUINO_SDK_VERSION VERSION_GREATER 1.0 OR ARDUINO_SDK_VERSION VERSION_EQUAL 1.0)
  750. if(NOT MANUAL)
  751. set(PIN_HEADER ${${${BOARD_ID}.build.variant}.path})
  752. if(PIN_HEADER)
  753. set(COMPILE_FLAGS "${COMPILE_FLAGS} -I\"${PIN_HEADER}\"")
  754. endif()
  755. endif()
  756. endif()
  757. # output
  758. set(${COMPILE_FLAGS_VAR} "${COMPILE_FLAGS}" PARENT_SCOPE)
  759. set(${LINK_FLAGS_VAR} "${LINK_FLAGS}" PARENT_SCOPE)
  760. else()
  761. message(FATAL_ERROR "Invalid Arduino board ID (${BOARD_ID}), aborting.")
  762. endif()
  763. endfunction()
  764. #=============================================================================#
  765. # [PRIVATE/INTERNAL]
  766. #
  767. # setup_arduino_core(VAR_NAME BOARD_ID)
  768. #
  769. # VAR_NAME - Variable name that will hold the generated library name
  770. # BOARD_ID - Arduino board id
  771. #
  772. # Creates the Arduino Core library for the specified board,
  773. # each board gets it's own version of the library.
  774. #
  775. #=============================================================================#
  776. function(setup_arduino_core VAR_NAME BOARD_ID)
  777. set(CORE_LIB_NAME ${BOARD_ID}_CORE)
  778. set(BOARD_CORE ${${BOARD_ID}.build.core})
  779. if(BOARD_CORE)
  780. if(NOT TARGET ${CORE_LIB_NAME})
  781. set(BOARD_CORE_PATH ${${BOARD_CORE}.path})
  782. find_sources(CORE_SRCS ${BOARD_CORE_PATH} True)
  783. # Debian/Ubuntu fix
  784. list(REMOVE_ITEM CORE_SRCS "${BOARD_CORE_PATH}/main.cxx")
  785. add_library(${CORE_LIB_NAME} ${CORE_SRCS})
  786. get_arduino_flags(ARDUINO_COMPILE_FLAGS ARDUINO_LINK_FLAGS ${BOARD_ID} FALSE)
  787. set_target_properties(${CORE_LIB_NAME} PROPERTIES
  788. COMPILE_FLAGS "${ARDUINO_COMPILE_FLAGS}"
  789. LINK_FLAGS "${ARDUINO_LINK_FLAGS}")
  790. endif()
  791. set(${VAR_NAME} ${CORE_LIB_NAME} PARENT_SCOPE)
  792. endif()
  793. endfunction()
  794. #=============================================================================#
  795. # [PRIVATE/INTERNAL]
  796. #
  797. # find_arduino_libraries(VAR_NAME SRCS ARDLIBS)
  798. #
  799. # VAR_NAME - Variable name which will hold the results
  800. # SRCS - Sources that will be analized
  801. # ARDLIBS - Arduino libraries identified by name (e.g., Wire, SPI, Servo)
  802. #
  803. # returns a list of paths to libraries found.
  804. #
  805. # Finds all Arduino type libraries included in sources. Available libraries
  806. # are ${ARDUINO_SDK_PATH}/libraries and ${CMAKE_CURRENT_SOURCE_DIR}.
  807. #
  808. # Also adds Arduino libraries specifically names in ALIBS. We add ".h" to the
  809. # names and then process them just like the Arduino libraries found in the sources.
  810. #
  811. # A Arduino library is a folder that has the same name as the include header.
  812. # For example, if we have a include "#include <LibraryName.h>" then the following
  813. # directory structure is considered a Arduino library:
  814. #
  815. # LibraryName/
  816. # |- LibraryName.h
  817. # `- LibraryName.c
  818. #
  819. # If such a directory is found then all sources within that directory are considred
  820. # to be part of that Arduino library.
  821. #
  822. #=============================================================================#
  823. function(find_arduino_libraries VAR_NAME SRCS ARDLIBS)
  824. set(ARDUINO_LIBS )
  825. foreach(SRC ${SRCS})
  826. # Skipping generated files. They are, probably, not exist yet.
  827. # TODO: Maybe it's possible to skip only really nonexisting files,
  828. # but then it wiil be less deterministic.
  829. get_source_file_property(_srcfile_generated ${SRC} GENERATED)
  830. # Workaround for sketches, which are marked as generated
  831. get_source_file_property(_sketch_generated ${SRC} GENERATED_SKETCH)
  832. if(NOT ${_srcfile_generated} OR ${_sketch_generated})
  833. if(NOT (EXISTS ${SRC} OR
  834. EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${SRC} OR
  835. EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${SRC}))
  836. message(FATAL_ERROR "Invalid source file: ${SRC}")
  837. endif()
  838. file(STRINGS ${SRC} SRC_CONTENTS)
  839. foreach(LIBNAME ${ARDLIBS})
  840. list(APPEND SRC_CONTENTS "#include <${LIBNAME}.h>")
  841. endforeach()
  842. foreach(SRC_LINE ${SRC_CONTENTS})
  843. if("${SRC_LINE}" MATCHES "^[ \t]*#[ \t]*include[ \t]*[<\"]([^>\"]*)[>\"]")
  844. get_filename_component(INCLUDE_NAME ${CMAKE_MATCH_1} NAME_WE)
  845. get_property(LIBRARY_SEARCH_PATH
  846. DIRECTORY # Property Scope
  847. PROPERTY LINK_DIRECTORIES)
  848. foreach(LIB_SEARCH_PATH ${LIBRARY_SEARCH_PATH} ${ARDUINO_LIBRARIES_PATH} ${${ARDUINO_PLATFORM}_LIBRARIES_PATH} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libraries ${ARDUINO_EXTRA_LIBRARIES_PATH})
  849. if(EXISTS ${LIB_SEARCH_PATH}/${INCLUDE_NAME}/${CMAKE_MATCH_1})
  850. list(APPEND ARDUINO_LIBS ${LIB_SEARCH_PATH}/${INCLUDE_NAME})
  851. break()
  852. endif()
  853. if(EXISTS ${LIB_SEARCH_PATH}/${INCLUDE_NAME}/src/${CMAKE_MATCH_1})
  854. list(APPEND ARDUINO_LIBS ${LIB_SEARCH_PATH}/${INCLUDE_NAME})
  855. break()
  856. endif()
  857. if(EXISTS ${LIB_SEARCH_PATH}/${CMAKE_MATCH_1})
  858. list(APPEND ARDUINO_LIBS ${LIB_SEARCH_PATH})
  859. break()
  860. endif()
  861. endforeach()
  862. endif()
  863. endforeach()
  864. endif()
  865. endforeach()
  866. if(ARDUINO_LIBS)
  867. list(REMOVE_DUPLICATES ARDUINO_LIBS)
  868. endif()
  869. set(${VAR_NAME} ${ARDUINO_LIBS} PARENT_SCOPE)
  870. endfunction()
  871. #=============================================================================#
  872. # [PRIVATE/INTERNAL]
  873. #
  874. # setup_arduino_library(VAR_NAME BOARD_ID LIB_PATH COMPILE_FLAGS LINK_FLAGS)
  875. #
  876. # VAR_NAME - Vairable wich will hold the generated library names
  877. # BOARD_ID - Board ID
  878. # LIB_PATH - Path of the library
  879. # COMPILE_FLAGS - Compile flags
  880. # LINK_FLAGS - Link flags
  881. #
  882. # Creates an Arduino library, with all it's library dependencies.
  883. #
  884. # ${LIB_NAME}_RECURSE controls if the library will recurse
  885. # when looking for source files.
  886. #
  887. #=============================================================================#
  888. # For known libraries can list recurse here
  889. set(Wire_RECURSE True)
  890. set(Ethernet_RECURSE True)
  891. set(SD_RECURSE True)
  892. set(SPI_RECURSE True)
  893. set(SoftwareSerial_RECURSE True)
  894. set(EEPROM_RECURSE True)
  895. set(LiquidCrystal_RECURSE True)
  896. function(setup_arduino_library VAR_NAME BOARD_ID LIB_PATH COMPILE_FLAGS LINK_FLAGS)
  897. set(LIB_TARGETS)
  898. set(LIB_INCLUDES)
  899. get_filename_component(LIB_NAME ${LIB_PATH} NAME)
  900. set(TARGET_LIB_NAME ${BOARD_ID}_${LIB_NAME})
  901. if(NOT TARGET ${TARGET_LIB_NAME})
  902. string(REGEX REPLACE ".*/" "" LIB_SHORT_NAME ${LIB_NAME})
  903. # Detect if recursion is needed
  904. if (NOT DEFINED ${LIB_SHORT_NAME}_RECURSE)
  905. set(${LIB_SHORT_NAME}_RECURSE False)
  906. endif()
  907. find_sources(LIB_SRCS ${LIB_PATH} ${${LIB_SHORT_NAME}_RECURSE})
  908. if(LIB_SRCS)
  909. message(STATUS "Generating ${TARGET_LIB_NAME} for library ${LIB_NAME}")
  910. arduino_debug_msg("Generating Arduino ${LIB_NAME} library")
  911. add_library(${TARGET_LIB_NAME} STATIC ${LIB_SRCS})
  912. get_arduino_flags(ARDUINO_COMPILE_FLAGS ARDUINO_LINK_FLAGS ${BOARD_ID} FALSE)
  913. find_arduino_libraries(LIB_DEPS "${LIB_SRCS}" "")
  914. foreach(LIB_DEP ${LIB_DEPS})
  915. if(NOT DEP_LIB_SRCS STREQUAL TARGET_LIB_NAME AND DEP_LIB_SRCS)
  916. message(STATUS "Found library ${LIB_NAME} needs ${DEP_LIB_SRCS}")
  917. endif()
  918. setup_arduino_library(DEP_LIB_SRCS ${BOARD_ID} ${LIB_DEP} "${COMPILE_FLAGS}" "${LINK_FLAGS}")
  919. # Do not link to this library. DEP_LIB_SRCS will always be only one entry
  920. # if we are looking at the same library.
  921. if(NOT DEP_LIB_SRCS STREQUAL TARGET_LIB_NAME)
  922. list(APPEND LIB_TARGETS ${DEP_LIB_SRCS})
  923. list(APPEND LIB_INCLUDES ${DEP_LIB_SRCS_INCLUDES})
  924. endif()
  925. endforeach()
  926. if (LIB_INCLUDES)
  927. string(REPLACE ";" " " LIB_INCLUDES "${LIB_INCLUDES}")
  928. endif()
  929. set_target_properties(${TARGET_LIB_NAME} PROPERTIES
  930. COMPILE_FLAGS "${ARDUINO_COMPILE_FLAGS} ${LIB_INCLUDES} -I\"${LIB_PATH}\" -I\"${LIB_PATH}/src\" -I\"${LIB_PATH}/utility\" ${COMPILE_FLAGS}"
  931. LINK_FLAGS "${ARDUINO_LINK_FLAGS} ${LINK_FLAGS}")
  932. list(APPEND LIB_INCLUDES "-I\"${LIB_PATH}\" -I\"${LIB_PATH}/src\" -I\"${LIB_PATH}/utility\"")
  933. target_link_libraries(${TARGET_LIB_NAME} ${BOARD_ID}_CORE ${LIB_TARGETS})
  934. list(APPEND LIB_TARGETS ${TARGET_LIB_NAME})
  935. endif()
  936. else()
  937. # Target already exists, skiping creating
  938. list(APPEND LIB_TARGETS ${TARGET_LIB_NAME})
  939. endif()
  940. if(LIB_TARGETS)
  941. list(REMOVE_DUPLICATES LIB_TARGETS)
  942. endif()
  943. set(${VAR_NAME} ${LIB_TARGETS} PARENT_SCOPE)
  944. set(${VAR_NAME}_INCLUDES ${LIB_INCLUDES} PARENT_SCOPE)
  945. endfunction()
  946. #=============================================================================#
  947. # [PRIVATE/INTERNAL]
  948. #
  949. # setup_arduino_libraries(VAR_NAME BOARD_ID SRCS COMPILE_FLAGS LINK_FLAGS)
  950. #
  951. # VAR_NAME - Vairable wich will hold the generated library names
  952. # BOARD_ID - Board ID
  953. # SRCS - source files
  954. # COMPILE_FLAGS - Compile flags
  955. # LINK_FLAGS - Linker flags
  956. #
  957. # Finds and creates all dependency libraries based on sources.
  958. #
  959. #=============================================================================#
  960. function(setup_arduino_libraries VAR_NAME BOARD_ID SRCS ARDLIBS COMPILE_FLAGS LINK_FLAGS)
  961. set(LIB_TARGETS)
  962. set(LIB_INCLUDES)
  963. find_arduino_libraries(TARGET_LIBS "${SRCS}" ARDLIBS)
  964. foreach(TARGET_LIB ${TARGET_LIBS})
  965. # Create static library instead of returning sources
  966. setup_arduino_library(LIB_DEPS ${BOARD_ID} ${TARGET_LIB} "${COMPILE_FLAGS}" "${LINK_FLAGS}")
  967. list(APPEND LIB_TARGETS ${LIB_DEPS})
  968. list(APPEND LIB_INCLUDES ${LIB_DEPS_INCLUDES})
  969. endforeach()
  970. set(${VAR_NAME} ${LIB_TARGETS} PARENT_SCOPE)
  971. set(${VAR_NAME}_INCLUDES ${LIB_INCLUDES} PARENT_SCOPE)
  972. endfunction()
  973. #=============================================================================#
  974. # [PRIVATE/INTERNAL]
  975. #
  976. # setup_arduino_target(TARGET_NAME ALL_SRCS ALL_LIBS COMPILE_FLAGS LINK_FLAGS MANUAL)
  977. #
  978. # TARGET_NAME - Target name
  979. # BOARD_ID - Arduino board ID
  980. # ALL_SRCS - All sources
  981. # ALL_LIBS - All libraries
  982. # COMPILE_FLAGS - Compile flags
  983. # LINK_FLAGS - Linker flags
  984. # MANUAL - (Advanced) Only use AVR Libc/Includes
  985. #
  986. # Creates an Arduino firmware target.
  987. #
  988. #=============================================================================#
  989. function(setup_arduino_target TARGET_NAME BOARD_ID ALL_SRCS ALL_LIBS COMPILE_FLAGS LINK_FLAGS MANUAL)
  990. add_executable(${TARGET_NAME} ${ALL_SRCS})
  991. set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".elf")
  992. get_arduino_flags(ARDUINO_COMPILE_FLAGS ARDUINO_LINK_FLAGS ${BOARD_ID} ${MANUAL})
  993. set_target_properties(${TARGET_NAME} PROPERTIES
  994. COMPILE_FLAGS "${ARDUINO_COMPILE_FLAGS} ${COMPILE_FLAGS}"
  995. LINK_FLAGS "${ARDUINO_LINK_FLAGS} ${LINK_FLAGS}")
  996. target_link_libraries(${TARGET_NAME} ${ALL_LIBS} "-lc -lm")
  997. if(NOT EXECUTABLE_OUTPUT_PATH)
  998. set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
  999. endif()
  1000. set(TARGET_PATH ${EXECUTABLE_OUTPUT_PATH}/${TARGET_NAME})
  1001. message(STATUS "Using ${CMAKE_OBJCOPY} for converting firmware image to hex")
  1002. add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
  1003. COMMAND ${CMAKE_OBJCOPY}
  1004. ARGS ${ARDUINO_OBJCOPY_EEP_FLAGS}
  1005. ${TARGET_PATH}.elf
  1006. ${TARGET_PATH}.eep
  1007. COMMENT "Generating EEP image"
  1008. VERBATIM)
  1009. # Convert firmware image to ASCII HEX format
  1010. add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
  1011. COMMAND ${CMAKE_OBJCOPY}
  1012. ARGS ${ARDUINO_OBJCOPY_HEX_FLAGS}
  1013. ${TARGET_PATH}.elf
  1014. ${TARGET_PATH}.hex
  1015. COMMENT "Generating HEX image"
  1016. VERBATIM)
  1017. # Display target size
  1018. add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
  1019. COMMAND ${CMAKE_COMMAND}
  1020. ARGS -DFIRMWARE_IMAGE=${TARGET_PATH}.elf
  1021. -DMCU=${${BOARD_ID}${ARDUINO_CPUMENU}.build.mcu}
  1022. -DEEPROM_IMAGE=${TARGET_PATH}.eep
  1023. -P ${ARDUINO_SIZE_SCRIPT}
  1024. COMMENT "Calculating image size"
  1025. VERBATIM)
  1026. # Create ${TARGET_NAME}-size target
  1027. add_custom_target(${TARGET_NAME}-size
  1028. COMMAND ${CMAKE_COMMAND}
  1029. -DFIRMWARE_IMAGE=${TARGET_PATH}.elf
  1030. -DMCU=${${BOARD_ID}${ARDUINO_CPUMENU}.build.mcu}
  1031. -DEEPROM_IMAGE=${TARGET_PATH}.eep
  1032. -P ${ARDUINO_SIZE_SCRIPT}
  1033. DEPENDS ${TARGET_NAME}
  1034. COMMENT "Calculating ${TARGET_NAME} image size")
  1035. endfunction()
  1036. #=============================================================================#
  1037. # [PRIVATE/INTERNAL]
  1038. #
  1039. # setup_arduino_upload(BOARD_ID TARGET_NAME PORT)
  1040. #
  1041. # BOARD_ID - Arduino board id
  1042. # TARGET_NAME - Target name
  1043. # PORT - Serial port for upload
  1044. # PROGRAMMER_ID - Programmer ID
  1045. # AVRDUDE_FLAGS - avrdude flags
  1046. #
  1047. # Create an upload target (${TARGET_NAME}-upload) for the specified Arduino target.
  1048. #
  1049. #=============================================================================#
  1050. function(setup_arduino_upload BOARD_ID TARGET_NAME PORT PROGRAMMER_ID AVRDUDE_FLAGS)
  1051. setup_arduino_bootloader_upload(${TARGET_NAME} ${BOARD_ID} ${PORT} "${AVRDUDE_FLAGS}")
  1052. # Add programmer support if defined
  1053. if(PROGRAMMER_ID AND ${PROGRAMMER_ID}.protocol)
  1054. setup_arduino_programmer_burn(${TARGET_NAME} ${BOARD_ID} ${PROGRAMMER_ID} ${PORT} "${AVRDUDE_FLAGS}")
  1055. setup_arduino_bootloader_burn(${TARGET_NAME} ${BOARD_ID} ${PROGRAMMER_ID} ${PORT} "${AVRDUDE_FLAGS}")
  1056. endif()
  1057. endfunction()
  1058. #=============================================================================#
  1059. # [PRIVATE/INTERNAL]
  1060. #
  1061. # setup_arduino_bootloader_upload(TARGET_NAME BOARD_ID PORT)
  1062. #
  1063. # TARGET_NAME - target name
  1064. # BOARD_ID - board id
  1065. # PORT - serial port
  1066. # AVRDUDE_FLAGS - avrdude flags (override)
  1067. #
  1068. # Set up target for upload firmware via the bootloader.
  1069. #
  1070. # The target for uploading the firmware is ${TARGET_NAME}-upload .
  1071. #
  1072. #=============================================================================#
  1073. function(setup_arduino_bootloader_upload TARGET_NAME BOARD_ID PORT AVRDUDE_FLAGS)
  1074. set(UPLOAD_TARGET ${TARGET_NAME}-upload)
  1075. set(AVRDUDE_ARGS)
  1076. setup_arduino_bootloader_args(${BOARD_ID} ${TARGET_NAME} ${PORT} "${AVRDUDE_FLAGS}" AVRDUDE_ARGS)
  1077. if(NOT AVRDUDE_ARGS)
  1078. message("Could not generate default avrdude bootloader args, aborting!")
  1079. return()
  1080. endif()
  1081. if(NOT EXECUTABLE_OUTPUT_PATH)
  1082. set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
  1083. endif()
  1084. set(TARGET_PATH ${EXECUTABLE_OUTPUT_PATH}/${TARGET_NAME})
  1085. list(APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_PATH}.hex:i")
  1086. list(APPEND AVRDUDE_ARGS "-Ueeprom:w:${TARGET_PATH}.eep:i")
  1087. add_custom_target(${UPLOAD_TARGET}
  1088. ${ARDUINO_AVRDUDE_PROGRAM}
  1089. ${AVRDUDE_ARGS}
  1090. DEPENDS ${TARGET_NAME})
  1091. # Global upload target
  1092. if(NOT TARGET upload)
  1093. add_custom_target(upload)
  1094. endif()
  1095. add_dependencies(upload ${UPLOAD_TARGET})
  1096. endfunction()
  1097. #=============================================================================#
  1098. # [PRIVATE/INTERNAL]
  1099. #
  1100. # setup_arduino_programmer_burn(TARGET_NAME BOARD_ID PROGRAMMER PORT AVRDUDE_FLAGS)
  1101. #
  1102. # TARGET_NAME - name of target to burn
  1103. # BOARD_ID - board id
  1104. # PROGRAMMER - programmer id
  1105. # PORT - serial port
  1106. # AVRDUDE_FLAGS - avrdude flags (override)
  1107. #
  1108. # Sets up target for burning firmware via a programmer.
  1109. #
  1110. # The target for burning the firmware is ${TARGET_NAME}-burn .
  1111. #
  1112. #=============================================================================#
  1113. function(setup_arduino_programmer_burn TARGET_NAME BOARD_ID PROGRAMMER PORT AVRDUDE_FLAGS)
  1114. set(PROGRAMMER_TARGET ${TARGET_NAME}-burn)
  1115. set(AVRDUDE_ARGS)
  1116. setup_arduino_programmer_args(${BOARD_ID} ${PROGRAMMER} ${TARGET_NAME} ${PORT} "${AVRDUDE_FLAGS}" AVRDUDE_ARGS)
  1117. if(NOT AVRDUDE_ARGS)
  1118. message("Could not generate default avrdude programmer args, aborting!")
  1119. return()
  1120. endif()
  1121. if(NOT EXECUTABLE_OUTPUT_PATH)
  1122. set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR})
  1123. endif()
  1124. set(TARGET_PATH ${EXECUTABLE_OUTPUT_PATH}/${TARGET_NAME})
  1125. list(APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_PATH}.hex")
  1126. add_custom_target(${PROGRAMMER_TARGET}
  1127. ${ARDUINO_AVRDUDE_PROGRAM}
  1128. ${AVRDUDE_ARGS}
  1129. DEPENDS ${TARGET_NAME})
  1130. endfunction()
  1131. #=============================================================================#
  1132. # [PRIVATE/INTERNAL]
  1133. #
  1134. # setup_arduino_bootloader_burn(TARGET_NAME BOARD_ID PROGRAMMER PORT AVRDUDE_FLAGS)
  1135. #
  1136. # TARGET_NAME - name of target to burn
  1137. # BOARD_ID - board id
  1138. # PROGRAMMER - programmer id
  1139. # PORT - serial port
  1140. # AVRDUDE_FLAGS - avrdude flags (override)
  1141. #
  1142. # Create a target for burning a bootloader via a programmer.
  1143. #
  1144. # The target for burning the bootloader is ${TARGET_NAME}-burn-bootloader
  1145. #
  1146. #=============================================================================#
  1147. function(setup_arduino_bootloader_burn TARGET_NAME BOARD_ID PROGRAMMER PORT AVRDUDE_FLAGS)
  1148. set(BOOTLOADER_TARGET ${TARGET_NAME}-burn-bootloader)
  1149. set(AVRDUDE_ARGS)
  1150. setup_arduino_programmer_args(${BOARD_ID} ${PROGRAMMER} ${TARGET_NAME} ${PORT} "${AVRDUDE_FLAGS}" AVRDUDE_ARGS)
  1151. if(NOT AVRDUDE_ARGS)
  1152. message("Could not generate default avrdude programmer args, aborting!")
  1153. return()
  1154. endif()
  1155. foreach( ITEM unlock_bits high_fuses low_fuses path file)
  1156. if(NOT ${BOARD_ID}.bootloader.${ITEM})
  1157. message("Missing ${BOARD_ID}.bootloader.${ITEM}, not creating bootloader burn target ${BOOTLOADER_TARGET}.")
  1158. return()
  1159. endif()
  1160. endforeach()
  1161. if(NOT EXISTS "${ARDUINO_BOOTLOADERS_PATH}/${${BOARD_ID}.bootloader.path}/${${BOARD_ID}${ARDUINO_CPUMENU}.bootloader.file}")
  1162. message("${ARDUINO_BOOTLOADERS_PATH}/${${BOARD_ID}.bootloader.path}/${${BOARD_ID}${ARDUINO_CPUMENU}.bootloader.file}")
  1163. message("Missing bootloader image, not creating bootloader burn target ${BOOTLOADER_TARGET}.")
  1164. return()
  1165. endif()
  1166. # Erase the chip
  1167. list(APPEND AVRDUDE_ARGS "-e")
  1168. # Set unlock bits and fuses (because chip is going to be erased)
  1169. list(APPEND AVRDUDE_ARGS "-Ulock:w:${${BOARD_ID}.bootloader.unlock_bits}:m")
  1170. if(${BOARD_ID}.bootloader.extended_fuses)
  1171. list(APPEND AVRDUDE_ARGS "-Uefuse:w:${${BOARD_ID}${ARDUINO_CPUMENU}.bootloader.extended_fuses}:m")
  1172. endif()
  1173. list(APPEND AVRDUDE_ARGS
  1174. "-Uhfuse:w:${${BOARD_ID}${ARDUINO_CPUMENU}.bootloader.high_fuses}:m"
  1175. "-Ulfuse:w:${${BOARD_ID}.bootloader.low_fuses}:m")
  1176. # Set bootloader image
  1177. list(APPEND AVRDUDE_ARGS "-Uflash:w:${${BOARD_ID}${ARDUINO_CPUMENU}.bootloader.file}:i")
  1178. # Set lockbits
  1179. list(APPEND AVRDUDE_ARGS "-Ulock:w:${${BOARD_ID}.bootloader.lock_bits}:m")
  1180. # Create burn bootloader target
  1181. add_custom_target(${BOOTLOADER_TARGET}
  1182. ${ARDUINO_AVRDUDE_PROGRAM}
  1183. ${AVRDUDE_ARGS}
  1184. WORKING_DIRECTORY ${ARDUINO_BOOTLOADERS_PATH}/${${BOARD_ID}.bootloader.path}
  1185. DEPENDS ${TARGET_NAME})
  1186. endfunction()
  1187. #=============================================================================#
  1188. # [PRIVATE/INTERNAL]
  1189. #
  1190. # setup_arduino_programmer_args(BOARD_ID PROGRAMMER TARGET_NAME PORT AVRDUDE_FLAGS OUTPUT_VAR)
  1191. #
  1192. # BOARD_ID - board id
  1193. # PROGRAMMER - programmer id
  1194. # TARGET_NAME - target name
  1195. # PORT - serial port
  1196. # AVRDUDE_FLAGS - avrdude flags (override)
  1197. # OUTPUT_VAR - name of output variable for result
  1198. #
  1199. # Sets up default avrdude settings for burning firmware via a programmer.
  1200. #=============================================================================#
  1201. function(setup_arduino_programmer_args BOARD_ID PROGRAMMER TARGET_NAME PORT AVRDUDE_FLAGS OUTPUT_VAR)
  1202. set(AVRDUDE_ARGS ${${OUTPUT_VAR}})
  1203. if(NOT AVRDUDE_FLAGS)
  1204. set(AVRDUDE_FLAGS ${ARDUINO_AVRDUDE_FLAGS})
  1205. endif()
  1206. list(APPEND AVRDUDE_ARGS "-C${ARDUINO_AVRDUDE_CONFIG_PATH}")
  1207. #TODO: Check mandatory settings before continuing
  1208. if(NOT ${PROGRAMMER}.protocol)
  1209. message(FATAL_ERROR "Missing ${PROGRAMMER}.protocol, aborting!")
  1210. endif()
  1211. list(APPEND AVRDUDE_ARGS "-c${${PROGRAMMER}.protocol}") # Set programmer
  1212. if(${PROGRAMMER}.communication STREQUAL "usb")
  1213. list(APPEND AVRDUDE_ARGS "-Pusb") # Set USB as port
  1214. elseif(${PROGRAMMER}.communication STREQUAL "serial")
  1215. list(APPEND AVRDUDE_ARGS "-P${PORT}") # Set port
  1216. if(${PROGRAMMER}.speed)
  1217. list(APPEND AVRDUDE_ARGS "-b${${PROGRAMMER}.speed}") # Set baud rate
  1218. endif()
  1219. endif()
  1220. if(${PROGRAMMER}.force)
  1221. list(APPEND AVRDUDE_ARGS "-F") # Set force
  1222. endif()
  1223. if(${PROGRAMMER}.delay)
  1224. list(APPEND AVRDUDE_ARGS "-i${${PROGRAMMER}.delay}") # Set delay
  1225. endif()
  1226. list(APPEND AVRDUDE_ARGS "-p${${BOARD_ID}${ARDUINO_CPUMENU}.build.mcu}") # MCU Type
  1227. list(APPEND AVRDUDE_ARGS ${AVRDUDE_FLAGS})
  1228. set(${OUTPUT_VAR} ${AVRDUDE_ARGS} PARENT_SCOPE)
  1229. endfunction()
  1230. #=============================================================================#
  1231. # [PRIVATE/INTERNAL]
  1232. #
  1233. # setup_arduino_bootloader_args(BOARD_ID TARGET_NAME PORT AVRDUDE_FLAGS OUTPUT_VAR)
  1234. #
  1235. # BOARD_ID - board id
  1236. # TARGET_NAME - target name
  1237. # PORT - serial port
  1238. # AVRDUDE_FLAGS - avrdude flags (override)
  1239. # OUTPUT_VAR - name of output variable for result
  1240. #
  1241. # Sets up default avrdude settings for uploading firmware via the bootloader.
  1242. #=============================================================================#
  1243. function(setup_arduino_bootloader_args BOARD_ID TARGET_NAME PORT AVRDUDE_FLAGS OUTPUT_VAR)
  1244. set(AVRDUDE_ARGS ${${OUTPUT_VAR}})
  1245. if(NOT AVRDUDE_FLAGS)
  1246. set(AVRDUDE_FLAGS ${ARDUINO_AVRDUDE_FLAGS})
  1247. endif()
  1248. list(APPEND AVRDUDE_ARGS
  1249. "-C${ARDUINO_AVRDUDE_CONFIG_PATH}" # avrdude config
  1250. "-p${${BOARD_ID}${ARDUINO_CPUMENU}.build.mcu}" # MCU Type
  1251. )
  1252. # Programmer
  1253. if(NOT ${BOARD_ID}${ARDUINO_CPUMENU}.upload.protocol OR ${BOARD_ID}${ARDUINO_CPUMENU}.upload.protocol STREQUAL "stk500")
  1254. if(NOT ${BOARD_ID}.upload.protocol OR ${BOARD_ID}.upload.protocol STREQUAL "stk500")
  1255. list(APPEND AVRDUDE_ARGS "-cstk500v1")
  1256. else()
  1257. list(APPEND AVRDUDE_ARGS "-c${${BOARD_ID}.upload.protocol}")
  1258. endif()
  1259. else()
  1260. list(APPEND AVRDUDE_ARGS "-c${${BOARD_ID}${ARDUINO_CPUMENU}.upload.protocol}")
  1261. endif()
  1262. set(UPLOAD_SPEED "19200")
  1263. if(${BOARD_ID}${ARDUINO_CPUMENU}.upload.speed)
  1264. set(UPLOAD_SPEED ${${BOARD_ID}${ARDUINO_CPUMENU}.upload.speed})
  1265. endif()
  1266. list(APPEND AVRDUDE_ARGS
  1267. "-b${UPLOAD_SPEED}" # Baud rate
  1268. "-P${PORT}" # Serial port
  1269. "-D" # Dont erase
  1270. )
  1271. list(APPEND AVRDUDE_ARGS ${AVRDUDE_FLAGS})
  1272. set(${OUTPUT_VAR} ${AVRDUDE_ARGS} PARENT_SCOPE)
  1273. endfunction()
  1274. #=============================================================================#
  1275. # [PRIVATE/INTERNAL]
  1276. #
  1277. # find_sources(VAR_NAME LIB_PATH RECURSE)
  1278. #
  1279. # VAR_NAME - Variable name that will hold the detected sources
  1280. # LIB_PATH - The base path
  1281. # RECURSE - Whether or not to recurse
  1282. #
  1283. # Finds all C/C++ sources located at the specified path.
  1284. #
  1285. #=============================================================================#
  1286. function(find_sources VAR_NAME LIB_PATH RECURSE)
  1287. set(FILE_SEARCH_LIST
  1288. ${LIB_PATH}/*.S
  1289. ${LIB_PATH}/*.inc
  1290. ${LIB_PATH}/*.cpp
  1291. ${LIB_PATH}/*.c
  1292. ${LIB_PATH}/*.cc
  1293. ${LIB_PATH}/*.cxx
  1294. ${LIB_PATH}/*.h
  1295. ${LIB_PATH}/*.hh
  1296. ${LIB_PATH}/*.hxx)
  1297. if(RECURSE)
  1298. file(GLOB_RECURSE LIB_FILES ${FILE_SEARCH_LIST})
  1299. else()
  1300. file(GLOB LIB_FILES ${FILE_SEARCH_LIST})
  1301. endif()
  1302. if(LIB_FILES)
  1303. set(${VAR_NAME} ${LIB_FILES} PARENT_SCOPE)
  1304. endif()
  1305. endfunction()
  1306. #=============================================================================#
  1307. # [PRIVATE/INTERNAL]
  1308. #
  1309. # setup_serial_target(TARGET_NAME CMD)
  1310. #
  1311. # TARGET_NAME - Target name
  1312. # CMD - Serial terminal command
  1313. #
  1314. # Creates a target (${TARGET_NAME}-serial) for launching the serial termnial.
  1315. #
  1316. #=============================================================================#
  1317. function(setup_serial_target TARGET_NAME CMD SERIAL_PORT)
  1318. string(CONFIGURE "${CMD}" FULL_CMD @ONLY)
  1319. add_custom_target(${TARGET_NAME}-serial
  1320. COMMAND ${FULL_CMD})
  1321. endfunction()
  1322. #=============================================================================#
  1323. # [PRIVATE/INTERNAL]
  1324. #
  1325. # detect_arduino_version(VAR_NAME)
  1326. #
  1327. # VAR_NAME - Variable name where the detected version will be saved
  1328. #
  1329. # Detects the Arduino SDK Version based on the revisions.txt file. The
  1330. # following variables will be generated:
  1331. #
  1332. # ${VAR_NAME} -> the full version (major.minor.patch)
  1333. # ${VAR_NAME}_MAJOR -> the major version
  1334. # ${VAR_NAME}_MINOR -> the minor version
  1335. # ${VAR_NAME}_PATCH -> the patch version
  1336. #
  1337. #=============================================================================#
  1338. function(detect_arduino_version VAR_NAME)
  1339. if(ARDUINO_VERSION_PATH)
  1340. file(READ ${ARDUINO_VERSION_PATH} RAW_VERSION)
  1341. if("${RAW_VERSION}" MATCHES " *[0]+([0-9]+)")
  1342. set(PARSED_VERSION 0.${CMAKE_MATCH_1}.0)
  1343. elseif("${RAW_VERSION}" MATCHES "[ ]*([0-9]+[.][0-9]+[.][0-9]+)")
  1344. set(PARSED_VERSION ${CMAKE_MATCH_1})
  1345. elseif("${RAW_VERSION}" MATCHES "[ ]*([0-9]+[.][0-9]+)")
  1346. set(PARSED_VERSION ${CMAKE_MATCH_1}.0)
  1347. endif()
  1348. if(NOT PARSED_VERSION STREQUAL "")
  1349. string(REPLACE "." ";" SPLIT_VERSION ${PARSED_VERSION})
  1350. list(GET SPLIT_VERSION 0 SPLIT_VERSION_MAJOR)
  1351. list(GET SPLIT_VERSION 1 SPLIT_VERSION_MINOR)
  1352. list(GET SPLIT_VERSION 2 SPLIT_VERSION_PATCH)
  1353. set(${VAR_NAME} "${PARSED_VERSION}" PARENT_SCOPE)
  1354. set(${VAR_NAME}_MAJOR "${SPLIT_VERSION_MAJOR}" PARENT_SCOPE)
  1355. set(${VAR_NAME}_MINOR "${SPLIT_VERSION_MINOR}" PARENT_SCOPE)
  1356. set(${VAR_NAME}_PATCH "${SPLIT_VERSION_PATCH}" PARENT_SCOPE)
  1357. endif()
  1358. endif()
  1359. endfunction()
  1360. #=============================================================================#
  1361. # [PRIVATE/INTERNAL]
  1362. #
  1363. # load_arduino_style_settings(SETTINGS_LIST SETTINGS_PATH)
  1364. #
  1365. # SETTINGS_LIST - Variable name of settings list
  1366. # SETTINGS_PATH - File path of settings file to load.
  1367. #
  1368. # Load a Arduino style settings file into the cache.
  1369. #
  1370. # Examples of this type of settings file is the boards.txt and
  1371. # programmers.txt files located in ${ARDUINO_SDK}/hardware/arduino.
  1372. #
  1373. # Settings have to following format:
  1374. #
  1375. # entry.setting[.subsetting] = value
  1376. #
  1377. # where [.subsetting] is optional
  1378. #
  1379. # For example, the following settings:
  1380. #
  1381. # uno.name=Arduino Uno
  1382. # uno.upload.protocol=stk500
  1383. # uno.upload.maximum_size=32256
  1384. # uno.build.mcu=atmega328p
  1385. # uno.build.core=arduino
  1386. #
  1387. # will generate the follwoing equivalent CMake variables:
  1388. #
  1389. # set(uno.name "Arduino Uno")
  1390. # set(uno.upload.protocol "stk500")
  1391. # set(uno.upload.maximum_size "32256")
  1392. # set(uno.build.mcu "atmega328p")
  1393. # set(uno.build.core "arduino")
  1394. #
  1395. # set(uno.SETTINGS name upload build) # List of settings for uno
  1396. # set(uno.upload.SUBSETTINGS protocol maximum_size) # List of sub-settings for uno.upload
  1397. # set(uno.build.SUBSETTINGS mcu core) # List of sub-settings for uno.build
  1398. #
  1399. # The ${ENTRY_NAME}.SETTINGS variable lists all settings for the entry, while
  1400. # ${ENTRY_NAME}.SUBSETTINGS variables lists all settings for a sub-setting of
  1401. # a entry setting pair.
  1402. #
  1403. # These variables are generated in order to be able to programatically traverse
  1404. # all settings (for a example see print_board_settings() function).
  1405. #
  1406. #=============================================================================#
  1407. function(LOAD_ARDUINO_STYLE_SETTINGS SETTINGS_LIST SETTINGS_PATH)
  1408. if(NOT ${SETTINGS_LIST} AND EXISTS ${SETTINGS_PATH})
  1409. file(STRINGS ${SETTINGS_PATH} FILE_ENTRIES) # Settings file split into lines
  1410. foreach(FILE_ENTRY ${FILE_ENTRIES})
  1411. if("${FILE_ENTRY}" MATCHES "^[^#]+=.*")
  1412. string(REGEX MATCH "^[^=]+" SETTING_NAME ${FILE_ENTRY})
  1413. string(REGEX MATCH "[^=]+$" SETTING_VALUE ${FILE_ENTRY})
  1414. string(REPLACE "." ";" ENTRY_NAME_TOKENS ${SETTING_NAME})
  1415. string(STRIP "${SETTING_VALUE}" SETTING_VALUE)
  1416. list(LENGTH ENTRY_NAME_TOKENS ENTRY_NAME_TOKENS_LEN)
  1417. # Add entry to settings list if it does not exist
  1418. list(GET ENTRY_NAME_TOKENS 0 ENTRY_NAME)
  1419. list(FIND ${SETTINGS_LIST} ${ENTRY_NAME} ENTRY_NAME_INDEX)
  1420. if(ENTRY_NAME_INDEX LESS 0)
  1421. # Add entry to main list
  1422. list(APPEND ${SETTINGS_LIST} ${ENTRY_NAME})
  1423. endif()
  1424. # Add entry setting to entry settings list if it does not exist
  1425. set(ENTRY_SETTING_LIST ${ENTRY_NAME}.SETTINGS)
  1426. list(GET ENTRY_NAME_TOKENS 1 ENTRY_SETTING)
  1427. set(PARAMETERS 2)
  1428. if(ENTRY_SETTING STREQUAL "menu")
  1429. list(GET ENTRY_NAME_TOKENS 3 CPUNAME)
  1430. if(ENTRY_NAME_TOKENS_LEN GREATER 4)
  1431. list(GET ENTRY_NAME_TOKENS 4 PROPERTYNAME)
  1432. set(ENTRY_SETTING "menu.cpu.${CPUNAME}.${PROPERTYNAME}")
  1433. set(PARAMETERS 5)
  1434. else()
  1435. set(ENTRY_SETTING "menu.cpu.${CPUNAME}")
  1436. set(PARAMETERS 4)
  1437. endif()
  1438. list(APPEND ${ENTRY_SETTING_LIST} "${ENTRY_SETTING}")
  1439. else()
  1440. list(FIND ${ENTRY_SETTING_LIST} ${ENTRY_SETTING} ENTRY_SETTING_INDEX)
  1441. if(ENTRY_SETTING_INDEX LESS 0)
  1442. # Add setting to entry
  1443. list(APPEND ${ENTRY_SETTING_LIST} ${ENTRY_SETTING})
  1444. set(${ENTRY_SETTING_LIST} ${${ENTRY_SETTING_LIST}}
  1445. CACHE INTERNAL "Arduino ${ENTRY_NAME} Board settings list")
  1446. endif()
  1447. endif()
  1448. set(FULL_SETTING_NAME ${ENTRY_NAME}.${ENTRY_SETTING})
  1449. # Add entry sub-setting to entry sub-settings list if it does not exists
  1450. if(ENTRY_NAME_TOKENS_LEN GREATER ${PARAMETERS})
  1451. set(ENTRY_SUBSETTING_LIST ${ENTRY_NAME}.${ENTRY_SETTING}.SUBSETTINGS)
  1452. list(GET ENTRY_NAME_TOKENS ${PARAMETERS} ENTRY_SUBSETTING)
  1453. list(FIND ${ENTRY_SUBSETTING_LIST} ${ENTRY_SUBSETTING} ENTRY_SUBSETTING_INDEX)
  1454. if(ENTRY_SUBSETTING_INDEX LESS 0)
  1455. list(APPEND ${ENTRY_SUBSETTING_LIST} ${ENTRY_SUBSETTING})
  1456. set(${ENTRY_SUBSETTING_LIST} ${${ENTRY_SUBSETTING_LIST}}
  1457. CACHE INTERNAL "Arduino ${ENTRY_NAME} Board sub-settings list")
  1458. endif()
  1459. set(FULL_SETTING_NAME ${FULL_SETTING_NAME}.${ENTRY_SUBSETTING})
  1460. endif()
  1461. # Save setting value
  1462. set(${FULL_SETTING_NAME} ${SETTING_VALUE}
  1463. CACHE INTERNAL "Arduino ${ENTRY_NAME} Board setting")
  1464. endif()
  1465. endforeach()
  1466. set(${SETTINGS_LIST} ${${SETTINGS_LIST}}
  1467. CACHE STRING "List of detected Arduino Board configurations")
  1468. mark_as_advanced(${SETTINGS_LIST})
  1469. endif()
  1470. endfunction()
  1471. #=============================================================================#
  1472. # print_settings(ENTRY_NAME)
  1473. #
  1474. # ENTRY_NAME - name of entry
  1475. #
  1476. # Print the entry settings (see load_arduino_syle_settings()).
  1477. #
  1478. #=============================================================================#
  1479. function(PRINT_SETTINGS ENTRY_NAME)
  1480. if(${ENTRY_NAME}.SETTINGS)
  1481. foreach(ENTRY_SETTING ${${ENTRY_NAME}.SETTINGS})
  1482. if(${ENTRY_NAME}.${ENTRY_SETTING})
  1483. message(STATUS " ${ENTRY_NAME}.${ENTRY_SETTING}=${${ENTRY_NAME}.${ENTRY_SETTING}}")
  1484. endif()
  1485. if(${ENTRY_NAME}.${ENTRY_SETTING}.SUBSETTINGS)
  1486. foreach(ENTRY_SUBSETTING ${${ENTRY_NAME}.${ENTRY_SETTING}.SUBSETTINGS})
  1487. if(${ENTRY_NAME}.${ENTRY_SETTING}.${ENTRY_SUBSETTING})
  1488. message(STATUS " ${ENTRY_NAME}.${ENTRY_SETTING}.${ENTRY_SUBSETTING}=${${ENTRY_NAME}.${ENTRY_SETTING}.${ENTRY_SUBSETTING}}")
  1489. endif()
  1490. endforeach()
  1491. endif()
  1492. message(STATUS "")
  1493. endforeach()
  1494. endif()
  1495. endfunction()
  1496. #=============================================================================#
  1497. # [PRIVATE/INTERNAL]
  1498. #
  1499. # print_list(SETTINGS_LIST)
  1500. #
  1501. # SETTINGS_LIST - Variables name of settings list
  1502. #
  1503. # Print list settings and names (see load_arduino_syle_settings()).
  1504. #=============================================================================#
  1505. function(PRINT_LIST SETTINGS_LIST)
  1506. if(${SETTINGS_LIST})
  1507. set(MAX_LENGTH 0)
  1508. foreach(ENTRY_NAME ${${SETTINGS_LIST}})
  1509. string(LENGTH "${ENTRY_NAME}" CURRENT_LENGTH)
  1510. if(CURRENT_LENGTH GREATER MAX_LENGTH)
  1511. set(MAX_LENGTH ${CURRENT_LENGTH})
  1512. endif()
  1513. endforeach()
  1514. foreach(ENTRY_NAME ${${SETTINGS_LIST}})
  1515. string(LENGTH "${ENTRY_NAME}" CURRENT_LENGTH)
  1516. math(EXPR PADDING_LENGTH "${MAX_LENGTH}-${CURRENT_LENGTH}")
  1517. set(PADDING "")
  1518. foreach(X RANGE ${PADDING_LENGTH})
  1519. set(PADDING "${PADDING} ")
  1520. endforeach()
  1521. message(STATUS " ${PADDING}${ENTRY_NAME}: ${${ENTRY_NAME}.name}")
  1522. endforeach()
  1523. endif()
  1524. endfunction()
  1525. #=============================================================================#
  1526. # [PRIVATE/INTERNAL]
  1527. #
  1528. # setup_arduino_example(TARGET_NAME LIBRARY_NAME EXAMPLE_NAME OUTPUT_VAR)
  1529. #
  1530. # TARGET_NAME - Target name
  1531. # LIBRARY_NAME - Library name
  1532. # EXAMPLE_NAME - Example name
  1533. # OUTPUT_VAR - Variable name to save sketch path.
  1534. #
  1535. # Creates a Arduino example from a the specified library.
  1536. #=============================================================================#
  1537. function(SETUP_ARDUINO_EXAMPLE TARGET_NAME LIBRARY_NAME EXAMPLE_NAME OUTPUT_VAR)
  1538. set(EXAMPLE_SKETCH_PATH )
  1539. get_property(LIBRARY_SEARCH_PATH
  1540. DIRECTORY # Property Scope
  1541. PROPERTY LINK_DIRECTORIES)
  1542. foreach(LIB_SEARCH_PATH ${LIBRARY_SEARCH_PATH} ${ARDUINO_LIBRARIES_PATH} ${${ARDUINO_PLATFORM}_LIBRARIES_PATH} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libraries)
  1543. message(STATUS "Search ${LIBRARY_NAME} example directory in ${LIB_SEARCH_PATH}")
  1544. if(EXISTS "${LIB_SEARCH_PATH}/${LIBRARY_NAME}/examples/${EXAMPLE_NAME}")
  1545. set(EXAMPLE_SKETCH_PATH "${LIB_SEARCH_PATH}/${LIBRARY_NAME}/examples/${EXAMPLE_NAME}")
  1546. break()
  1547. endif()
  1548. endforeach()
  1549. if(EXAMPLE_SKETCH_PATH)
  1550. setup_arduino_sketch(${TARGET_NAME} ${EXAMPLE_SKETCH_PATH} SKETCH_CPP)
  1551. set("${OUTPUT_VAR}" ${${OUTPUT_VAR}} ${SKETCH_CPP} PARENT_SCOPE)
  1552. else()
  1553. message(FATAL_ERROR "Could not find example ${EXAMPLE_NAME} from library ${LIBRARY_NAME}")
  1554. endif()
  1555. endfunction()
  1556. #=============================================================================#
  1557. # [PRIVATE/INTERNAL]
  1558. #
  1559. # setup_arduino_sketch(TARGET_NAME SKETCH_PATH OUTPUT_VAR)
  1560. #
  1561. # TARGET_NAME - Target name
  1562. # SKETCH_PATH - Path to sketch directory
  1563. # OUTPUT_VAR - Variable name where to save generated sketch source
  1564. #
  1565. # Generates C++ sources from Arduino Sketch.
  1566. #=============================================================================#
  1567. function(SETUP_ARDUINO_SKETCH TARGET_NAME SKETCH_PATH OUTPUT_VAR)
  1568. get_filename_component(SKETCH_NAME "${SKETCH_PATH}" NAME)
  1569. get_filename_component(SKETCH_PATH "${SKETCH_PATH}" ABSOLUTE)
  1570. if(EXISTS "${SKETCH_PATH}")
  1571. set(SKETCH_CPP ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_${SKETCH_NAME}.cpp)
  1572. if (IS_DIRECTORY "${SKETCH_PATH}")
  1573. # Sketch directory specified, try to find main sketch...
  1574. set(MAIN_SKETCH ${SKETCH_PATH}/${SKETCH_NAME})
  1575. if(EXISTS "${MAIN_SKETCH}.pde")
  1576. set(MAIN_SKETCH "${MAIN_SKETCH}.pde")
  1577. elseif(EXISTS "${MAIN_SKETCH}.ino")
  1578. set(MAIN_SKETCH "${MAIN_SKETCH}.ino")
  1579. else()
  1580. message(FATAL_ERROR "Could not find main sketch (${SKETCH_NAME}.pde or ${SKETCH_NAME}.ino) at ${SKETCH_PATH}! Please specify the main sketch file path instead of directory.")
  1581. endif()
  1582. else()
  1583. # Sektch file specified, assuming parent directory as sketch directory
  1584. set(MAIN_SKETCH ${SKETCH_PATH})
  1585. get_filename_component(SKETCH_PATH "${SKETCH_PATH}" PATH)
  1586. endif()
  1587. arduino_debug_msg("sketch: ${MAIN_SKETCH}")
  1588. # Find all sketch files
  1589. file(GLOB SKETCH_SOURCES ${SKETCH_PATH}/*.pde ${SKETCH_PATH}/*.ino)
  1590. list(REMOVE_ITEM SKETCH_SOURCES ${MAIN_SKETCH})
  1591. list(SORT SKETCH_SOURCES)
  1592. generate_cpp_from_sketch("${MAIN_SKETCH}" "${SKETCH_SOURCES}" "${SKETCH_CPP}")
  1593. # Regenerate build system if sketch changes
  1594. add_custom_command(OUTPUT ${SKETCH_CPP}
  1595. COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}
  1596. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  1597. DEPENDS ${MAIN_SKETCH} ${SKETCH_SOURCES}
  1598. COMMENT "Regnerating ${SKETCH_NAME} Sketch")
  1599. set_source_files_properties(${SKETCH_CPP} PROPERTIES GENERATED TRUE)
  1600. # Mark file that it exists for find_file
  1601. set_source_files_properties(${SKETCH_CPP} PROPERTIES GENERATED_SKETCH TRUE)
  1602. set("${OUTPUT_VAR}" ${${OUTPUT_VAR}} ${SKETCH_CPP} PARENT_SCOPE)
  1603. else()
  1604. message(FATAL_ERROR "Sketch does not exist: ${SKETCH_PATH}")
  1605. endif()
  1606. endfunction()
  1607. #=============================================================================#
  1608. # [PRIVATE/INTERNAL]
  1609. #
  1610. # generate_cpp_from_sketch(MAIN_SKETCH_PATH SKETCH_SOURCES SKETCH_CPP)
  1611. #
  1612. # MAIN_SKETCH_PATH - Main sketch file path
  1613. # SKETCH_SOURCES - Setch source paths
  1614. # SKETCH_CPP - Name of file to generate
  1615. #
  1616. # Generate C++ source file from Arduino sketch files.
  1617. #=============================================================================#
  1618. function(GENERATE_CPP_FROM_SKETCH MAIN_SKETCH_PATH SKETCH_SOURCES SKETCH_CPP)
  1619. file(WRITE ${SKETCH_CPP} "// automatically generated by arduino-cmake\n")
  1620. file(READ ${MAIN_SKETCH_PATH} MAIN_SKETCH)
  1621. # remove comments
  1622. remove_comments(MAIN_SKETCH MAIN_SKETCH_NO_COMMENTS)
  1623. # find first statement
  1624. string(REGEX MATCH "[\n][_a-zA-Z0-9]+[^\n]*" FIRST_STATEMENT "${MAIN_SKETCH_NO_COMMENTS}")
  1625. string(FIND "${MAIN_SKETCH}" "${FIRST_STATEMENT}" HEAD_LENGTH)
  1626. if ("${HEAD_LENGTH}" STREQUAL "-1")
  1627. set(HEAD_LENGTH 0)
  1628. endif()
  1629. #message(STATUS "FIRST STATEMENT: ${FIRST_STATEMENT}")
  1630. #message(STATUS "FIRST STATEMENT POSITION: ${HEAD_LENGTH}")
  1631. string(LENGTH "${MAIN_SKETCH}" MAIN_SKETCH_LENGTH)
  1632. string(SUBSTRING "${MAIN_SKETCH}" 0 ${HEAD_LENGTH} SKETCH_HEAD)
  1633. #arduino_debug_msg("SKETCH_HEAD:\n${SKETCH_HEAD}")
  1634. # find the body of the main pde
  1635. math(EXPR BODY_LENGTH "${MAIN_SKETCH_LENGTH}-${HEAD_LENGTH}")
  1636. string(SUBSTRING "${MAIN_SKETCH}" "${HEAD_LENGTH}+1" "${BODY_LENGTH}-1" SKETCH_BODY)
  1637. #arduino_debug_msg("BODY:\n${SKETCH_BODY}")
  1638. # write the file head
  1639. file(APPEND ${SKETCH_CPP} "#line 1 \"${MAIN_SKETCH_PATH}\"\n${SKETCH_HEAD}")
  1640. # Count head line offset (for GCC error reporting)
  1641. file(STRINGS ${SKETCH_CPP} SKETCH_HEAD_LINES)
  1642. list(LENGTH SKETCH_HEAD_LINES SKETCH_HEAD_LINES_COUNT)
  1643. math(EXPR SKETCH_HEAD_OFFSET "${SKETCH_HEAD_LINES_COUNT}+2")
  1644. # add arduino include header
  1645. #file(APPEND ${SKETCH_CPP} "\n#line 1 \"autogenerated\"\n")
  1646. file(APPEND ${SKETCH_CPP} "\n#line ${SKETCH_HEAD_OFFSET} \"${SKETCH_CPP}\"\n")
  1647. if(ARDUINO_SDK_VERSION VERSION_LESS 1.0)
  1648. file(APPEND ${SKETCH_CPP} "#include \"WProgram.h\"\n")
  1649. else()
  1650. file(APPEND ${SKETCH_CPP} "#include \"Arduino.h\"\n")
  1651. endif()
  1652. # add function prototypes
  1653. foreach(SKETCH_SOURCE_PATH ${SKETCH_SOURCES} ${MAIN_SKETCH_PATH})
  1654. arduino_debug_msg("Sketch: ${SKETCH_SOURCE_PATH}")
  1655. file(READ ${SKETCH_SOURCE_PATH} SKETCH_SOURCE)
  1656. remove_comments(SKETCH_SOURCE SKETCH_SOURCE)
  1657. set(ALPHA "a-zA-Z")
  1658. set(NUM "0-9")
  1659. set(ALPHANUM "${ALPHA}${NUM}")
  1660. set(WORD "_${ALPHANUM}")
  1661. set(LINE_START "(^|[\n])")
  1662. set(QUALIFIERS "[ \t]*([${ALPHA}]+[ ])*")
  1663. set(TYPE "[${WORD}]+([ ]*[\n][\t]*|[ ])+")
  1664. set(FNAME "[${WORD}]+[ ]?[\n]?[\t]*[ ]*")
  1665. set(FARGS "[(]([\t]*[ ]*[*&]?[ ]?[${WORD}](\\[([${NUM}]+)?\\])*[,]?[ ]*[\n]?)*([,]?[ ]*[\n]?)?[)]")
  1666. set(BODY_START "([ ]*[\n][\t]*|[ ]|[\n])*{")
  1667. set(PROTOTYPE_PATTERN "${LINE_START}${QUALIFIERS}${TYPE}${FNAME}${FARGS}${BODY_START}")
  1668. string(REGEX MATCHALL "${PROTOTYPE_PATTERN}" SKETCH_PROTOTYPES "${SKETCH_SOURCE}")
  1669. # Write function prototypes
  1670. file(APPEND ${SKETCH_CPP} "\n//=== START Forward: ${SKETCH_SOURCE_PATH}\n")
  1671. foreach(SKETCH_PROTOTYPE ${SKETCH_PROTOTYPES})
  1672. string(REPLACE "\n" " " SKETCH_PROTOTYPE "${SKETCH_PROTOTYPE}")
  1673. string(REPLACE "{" "" SKETCH_PROTOTYPE "${SKETCH_PROTOTYPE}")
  1674. arduino_debug_msg("\tprototype: ${SKETCH_PROTOTYPE};")
  1675. # " else if(var == other) {" shoudn't be listed as prototype
  1676. if(NOT SKETCH_PROTOTYPE MATCHES "(if[ ]?[\n]?[\t]*[ ]*[)])")
  1677. file(APPEND ${SKETCH_CPP} "${SKETCH_PROTOTYPE};\n")
  1678. else()
  1679. arduino_debug_msg("\trejected prototype: ${SKETCH_PROTOTYPE};")
  1680. endif()
  1681. file(APPEND ${SKETCH_CPP} "${SKETCH_PROTOTYPE};\n")
  1682. endforeach()
  1683. file(APPEND ${SKETCH_CPP} "//=== END Forward: ${SKETCH_SOURCE_PATH}\n")
  1684. endforeach()
  1685. # Write Sketch CPP source
  1686. get_num_lines("${SKETCH_HEAD}" HEAD_NUM_LINES)
  1687. file(APPEND ${SKETCH_CPP} "#line ${HEAD_NUM_LINES} \"${MAIN_SKETCH_PATH}\"\n")
  1688. file(APPEND ${SKETCH_CPP} "\n${SKETCH_BODY}")
  1689. foreach (SKETCH_SOURCE_PATH ${SKETCH_SOURCES})
  1690. file(READ ${SKETCH_SOURCE_PATH} SKETCH_SOURCE)
  1691. file(APPEND ${SKETCH_CPP} "\n//=== START : ${SKETCH_SOURCE_PATH}\n")
  1692. file(APPEND ${SKETCH_CPP} "#line 1 \"${SKETCH_SOURCE_PATH}\"\n")
  1693. file(APPEND ${SKETCH_CPP} "${SKETCH_SOURCE}")
  1694. file(APPEND ${SKETCH_CPP} "\n//=== END : ${SKETCH_SOURCE_PATH}\n")
  1695. endforeach()
  1696. endfunction()
  1697. #=============================================================================#
  1698. # [PRIVATE/INTERNAL]
  1699. #
  1700. # setup_arduino_size_script(OUTPUT_VAR)
  1701. #
  1702. # OUTPUT_VAR - Output variable that will contain the script path
  1703. #
  1704. # Generates script used to display the firmware size.
  1705. #=============================================================================#
  1706. function(SETUP_ARDUINO_SIZE_SCRIPT OUTPUT_VAR)
  1707. set(ARDUINO_SIZE_SCRIPT_PATH ${CMAKE_BINARY_DIR}/CMakeFiles/FirmwareSize.cmake)
  1708. file(WRITE ${ARDUINO_SIZE_SCRIPT_PATH} "
  1709. set(AVRSIZE_PROGRAM \"${AVRSIZE_PROGRAM}\")
  1710. set(AVRSIZE_FLAGS -C --mcu=\${MCU})
  1711. execute_process(COMMAND \${AVRSIZE_PROGRAM} \${AVRSIZE_FLAGS} \${FIRMWARE_IMAGE} \${EEPROM_IMAGE}
  1712. OUTPUT_VARIABLE SIZE_OUTPUT)
  1713. string(STRIP \"\${SIZE_OUTPUT}\" RAW_SIZE_OUTPUT)
  1714. # Convert lines into a list
  1715. string(REPLACE \"\\n\" \";\" SIZE_OUTPUT_LIST \"\${SIZE_OUTPUT}\")
  1716. set(SIZE_OUTPUT_LINES)
  1717. foreach(LINE \${SIZE_OUTPUT_LIST})
  1718. if(NOT \"\${LINE}\" STREQUAL \"\")
  1719. list(APPEND SIZE_OUTPUT_LINES \"\${LINE}\")
  1720. endif()
  1721. endforeach()
  1722. function(EXTRACT LIST_NAME INDEX VARIABLE)
  1723. list(GET \"\${LIST_NAME}\" \${INDEX} RAW_VALUE)
  1724. string(STRIP \"\${RAW_VALUE}\" VALUE)
  1725. set(\${VARIABLE} \"\${VALUE}\" PARENT_SCOPE)
  1726. endfunction()
  1727. function(PARSE INPUT VARIABLE_PREFIX)
  1728. if(\${INPUT} MATCHES \"([^:]+):[ \\t]*([0-9]+)[ \\t]*([^ \\t]+)[ \\t]*[(]([0-9.]+)%.*\")
  1729. set(ENTRY_NAME \${CMAKE_MATCH_1})
  1730. set(ENTRY_SIZE \${CMAKE_MATCH_2})
  1731. set(ENTRY_SIZE_TYPE \${CMAKE_MATCH_3})
  1732. set(ENTRY_PERCENT \${CMAKE_MATCH_4})
  1733. endif()
  1734. set(\${VARIABLE_PREFIX}_NAME \${ENTRY_NAME} PARENT_SCOPE)
  1735. set(\${VARIABLE_PREFIX}_SIZE \${ENTRY_SIZE} PARENT_SCOPE)
  1736. set(\${VARIABLE_PREFIX}_SIZE_TYPE \${ENTRY_SIZE_TYPE} PARENT_SCOPE)
  1737. set(\${VARIABLE_PREFIX}_PERCENT \${ENTRY_PERCENT} PARENT_SCOPE)
  1738. endfunction()
  1739. list(LENGTH SIZE_OUTPUT_LINES SIZE_OUTPUT_LENGTH)
  1740. #message(\"\${SIZE_OUTPUT_LINES}\")
  1741. #message(\"\${SIZE_OUTPUT_LENGTH}\")
  1742. if (\${SIZE_OUTPUT_LENGTH} STREQUAL 14)
  1743. EXTRACT(SIZE_OUTPUT_LINES 3 FIRMWARE_PROGRAM_SIZE_ROW)
  1744. EXTRACT(SIZE_OUTPUT_LINES 5 FIRMWARE_DATA_SIZE_ROW)
  1745. PARSE(FIRMWARE_PROGRAM_SIZE_ROW FIRMWARE_PROGRAM)
  1746. PARSE(FIRMWARE_DATA_SIZE_ROW FIRMWARE_DATA)
  1747. set(FIRMWARE_STATUS \"Firmware Size: \")
  1748. set(FIRMWARE_STATUS \"\${FIRMWARE_STATUS} [\${FIRMWARE_PROGRAM_NAME}: \${FIRMWARE_PROGRAM_SIZE} \${FIRMWARE_PROGRAM_SIZE_TYPE} (\${FIRMWARE_PROGRAM_PERCENT}%)] \")
  1749. set(FIRMWARE_STATUS \"\${FIRMWARE_STATUS} [\${FIRMWARE_DATA_NAME}: \${FIRMWARE_DATA_SIZE} \${FIRMWARE_DATA_SIZE_TYPE} (\${FIRMWARE_DATA_PERCENT}%)]\")
  1750. set(FIRMWARE_STATUS \"\${FIRMWARE_STATUS} on \${MCU}\")
  1751. EXTRACT(SIZE_OUTPUT_LINES 10 EEPROM_PROGRAM_SIZE_ROW)
  1752. EXTRACT(SIZE_OUTPUT_LINES 12 EEPROM_DATA_SIZE_ROW)
  1753. PARSE(EEPROM_PROGRAM_SIZE_ROW EEPROM_PROGRAM)
  1754. PARSE(EEPROM_DATA_SIZE_ROW EEPROM_DATA)
  1755. set(EEPROM_STATUS \"EEPROM Size: \")
  1756. set(EEPROM_STATUS \"\${EEPROM_STATUS} [\${EEPROM_PROGRAM_NAME}: \${EEPROM_PROGRAM_SIZE} \${EEPROM_PROGRAM_SIZE_TYPE} (\${EEPROM_PROGRAM_PERCENT}%)] \")
  1757. set(EEPROM_STATUS \"\${EEPROM_STATUS} [\${EEPROM_DATA_NAME}: \${EEPROM_DATA_SIZE} \${EEPROM_DATA_SIZE_TYPE} (\${EEPROM_DATA_PERCENT}%)]\")
  1758. set(EEPROM_STATUS \"\${EEPROM_STATUS} on \${MCU}\")
  1759. message(\"\${FIRMWARE_STATUS}\")
  1760. message(\"\${EEPROM_STATUS}\\n\")
  1761. if(\$ENV{VERBOSE})
  1762. message(\"\${RAW_SIZE_OUTPUT}\\n\")
  1763. elseif(\$ENV{VERBOSE_SIZE})
  1764. message(\"\${RAW_SIZE_OUTPUT}\\n\")
  1765. endif()
  1766. else()
  1767. message(\"\${RAW_SIZE_OUTPUT}\")
  1768. endif()
  1769. ")
  1770. set(${OUTPUT_VAR} ${ARDUINO_SIZE_SCRIPT_PATH} PARENT_SCOPE)
  1771. endfunction()
  1772. #=============================================================================#
  1773. # [PRIVATE/INTERNAL]
  1774. #
  1775. # arduino_debug_on()
  1776. #
  1777. # Enables Arduino module debugging.
  1778. #=============================================================================#
  1779. function(ARDUINO_DEBUG_ON)
  1780. set(ARDUINO_DEBUG True PARENT_SCOPE)
  1781. endfunction()
  1782. #=============================================================================#
  1783. # [PRIVATE/INTERNAL]
  1784. #
  1785. # arduino_debug_off()
  1786. #
  1787. # Disables Arduino module debugging.
  1788. #=============================================================================#
  1789. function(ARDUINO_DEBUG_OFF)
  1790. set(ARDUINO_DEBUG False PARENT_SCOPE)
  1791. endfunction()
  1792. #=============================================================================#
  1793. # [PRIVATE/INTERNAL]
  1794. #
  1795. # arduino_debug_msg(MSG)
  1796. #
  1797. # MSG - Message to print
  1798. #
  1799. # Print Arduino debugging information. In order to enable printing
  1800. # use arduino_debug_on() and to disable use arduino_debug_off().
  1801. #=============================================================================#
  1802. function(ARDUINO_DEBUG_MSG MSG)
  1803. if(ARDUINO_DEBUG)
  1804. message("## ${MSG}")
  1805. endif()
  1806. endfunction()
  1807. #=============================================================================#
  1808. # [PRIVATE/INTERNAL]
  1809. #
  1810. # remove_comments(SRC_VAR OUT_VAR)
  1811. #
  1812. # SRC_VAR - variable holding sources
  1813. # OUT_VAR - variable holding sources with no comments
  1814. #
  1815. # Removes all comments from the source code.
  1816. #=============================================================================#
  1817. function(REMOVE_COMMENTS SRC_VAR OUT_VAR)
  1818. string(REGEX REPLACE "[\\./\\\\]" "_" FILE "${NAME}")
  1819. set(SRC ${${SRC_VAR}})
  1820. #message(STATUS "removing comments from: ${FILE}")
  1821. #file(WRITE "${CMAKE_BINARY_DIR}/${FILE}_pre_remove_comments.txt" ${SRC})
  1822. #message(STATUS "\n${SRC}")
  1823. # remove all comments
  1824. string(REGEX REPLACE "([/][/][^\n]*)|([/][\\*]([^\\*]|([\\*]+[^/\\*]))*[\\*]+[/])" "" OUT "${SRC}")
  1825. #file(WRITE "${CMAKE_BINARY_DIR}/${FILE}_post_remove_comments.txt" ${SRC})
  1826. #message(STATUS "\n${SRC}")
  1827. set(${OUT_VAR} ${OUT} PARENT_SCOPE)
  1828. endfunction()
  1829. #=============================================================================#
  1830. # [PRIVATE/INTERNAL]
  1831. #
  1832. # get_num_lines(DOCUMENT OUTPUT_VAR)
  1833. #
  1834. # DOCUMENT - Document contents
  1835. # OUTPUT_VAR - Variable which will hold the line number count
  1836. #
  1837. # Counts the line number of the document.
  1838. #=============================================================================#
  1839. function(GET_NUM_LINES DOCUMENT OUTPUT_VAR)
  1840. string(REGEX MATCHALL "[\n]" MATCH_LIST "${DOCUMENT}")
  1841. list(LENGTH MATCH_LIST NUM)
  1842. set(${OUTPUT_VAR} ${NUM} PARENT_SCOPE)
  1843. endfunction()
  1844. #=============================================================================#
  1845. # [PRIVATE/INTERNAL]
  1846. #
  1847. # required_variables(MSG msg VARS var1 var2 .. varN)
  1848. #
  1849. # MSG - Message to be displayed in case of error
  1850. # VARS - List of variables names to check
  1851. #
  1852. # Ensure the specified variables are not empty, otherwise a fatal error is emmited.
  1853. #=============================================================================#
  1854. function(REQUIRED_VARIABLES)
  1855. cmake_parse_arguments(INPUT "" "MSG" "VARS" ${ARGN})
  1856. error_for_unparsed(INPUT)
  1857. foreach(VAR ${INPUT_VARS})
  1858. if ("${${VAR}}" STREQUAL "")
  1859. message(FATAL_ERROR "${VAR} not set: ${INPUT_MSG}")
  1860. endif()
  1861. endforeach()
  1862. endfunction()
  1863. #=============================================================================#
  1864. # [PRIVATE/INTERNAL]
  1865. #
  1866. # error_for_unparsed(PREFIX)
  1867. #
  1868. # PREFIX - Prefix name
  1869. #
  1870. # Emit fatal error if there are unparsed argument from cmake_parse_arguments().
  1871. #=============================================================================#
  1872. function(ERROR_FOR_UNPARSED PREFIX)
  1873. set(ARGS "${${PREFIX}_UNPARSED_ARGUMENTS}")
  1874. if (NOT ( "${ARGS}" STREQUAL "") )
  1875. message(FATAL_ERROR "unparsed argument: ${ARGS}")
  1876. endif()
  1877. endfunction()
  1878. #=============================================================================#
  1879. # C Flags
  1880. #=============================================================================#
  1881. if (NOT DEFINED ARDUINO_C_FLAGS)
  1882. set(ARDUINO_C_FLAGS "-g -Os -w -ffunction-sections -fdata-sections -MMD")
  1883. endif (NOT DEFINED ARDUINO_C_FLAGS)
  1884. set(CMAKE_C_FLAGS "${ARDUINO_C_FLAGS}" CACHE STRING "")
  1885. set(CMAKE_C_FLAGS_DEBUG "${ARDUINO_C_FLAGS}" CACHE STRING "")
  1886. set(CMAKE_C_FLAGS_MINSIZEREL "${ARDUINO_C_FLAGS}" CACHE STRING "")
  1887. set(CMAKE_C_FLAGS_RELEASE "${ARDUINO_C_FLAGS}" CACHE STRING "")
  1888. set(CMAKE_C_FLAGS_RELWITHDEBINFO "${ARDUINO_C_FLAGS}" CACHE STRING "")
  1889. #=============================================================================#
  1890. # C++ Flags
  1891. #=============================================================================#
  1892. if (NOT DEFINED ARDUINO_CXX_FLAGS)
  1893. set(ARDUINO_CXX_FLAGS "-g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD")
  1894. endif (NOT DEFINED ARDUINO_CXX_FLAGS)
  1895. set(CMAKE_CXX_FLAGS "${ARDUINO_CXX_FLAGS}" CACHE STRING "")
  1896. set(CMAKE_CXX_FLAGS_DEBUG "${ARDUINO_CXX_FLAGS}" CACHE STRING "")
  1897. set(CMAKE_CXX_FLAGS_MINSIZEREL "${ARDUINO_CXX_FLAGS}" CACHE STRING "")
  1898. set(CMAKE_CXX_FLAGS_RELEASE "${ARDUINO_CXX_FLAGS}" CACHE STRING "")
  1899. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${ARDUINO_CXX_FLAGS}" CACHE STRING "")
  1900. #=============================================================================#
  1901. # Executable Linker Flags #
  1902. #=============================================================================#
  1903. set(ARDUINO_LINKER_FLAGS "-w -Os -Wl,--gc-sections")
  1904. set(CMAKE_EXE_LINKER_FLAGS "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1905. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1906. set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1907. set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1908. set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1909. #=============================================================================#
  1910. #=============================================================================#
  1911. # Shared Lbrary Linker Flags #
  1912. #=============================================================================#
  1913. set(CMAKE_SHARED_LINKER_FLAGS "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1914. set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1915. set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1916. set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1917. set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1918. set(CMAKE_MODULE_LINKER_FLAGS "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1919. set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1920. set(CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1921. set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1922. set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
  1923. #=============================================================================#
  1924. # Arduino Settings
  1925. #=============================================================================#
  1926. set(ARDUINO_OBJCOPY_EEP_FLAGS -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load
  1927. --no-change-warnings --change-section-lma .eeprom=0 CACHE STRING "")
  1928. set(ARDUINO_OBJCOPY_HEX_FLAGS -O ihex -R .eeprom CACHE STRING "")
  1929. set(ARDUINO_AVRDUDE_FLAGS -V CACHE STRING "")
  1930. #=============================================================================#
  1931. # Initialization
  1932. #=============================================================================#
  1933. if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH)
  1934. register_hardware_platform(${ARDUINO_SDK_PATH}/hardware/arduino/)
  1935. find_file(ARDUINO_LIBRARIES_PATH
  1936. NAMES libraries
  1937. PATHS ${ARDUINO_SDK_PATH}
  1938. DOC "Path to directory containing the Arduino libraries."
  1939. NO_SYSTEM_ENVIRONMENT_PATH)
  1940. find_file(ARDUINO_VERSION_PATH
  1941. NAMES lib/version.txt
  1942. PATHS ${ARDUINO_SDK_PATH}
  1943. DOC "Path to Arduino version file."
  1944. NO_SYSTEM_ENVIRONMENT_PATH)
  1945. find_program(ARDUINO_AVRDUDE_PROGRAM
  1946. NAMES avrdude
  1947. PATHS ${ARDUINO_SDK_PATH}
  1948. PATH_SUFFIXES hardware/tools hardware/tools/avr/bin
  1949. NO_DEFAULT_PATH)
  1950. find_program(ARDUINO_AVRDUDE_PROGRAM
  1951. NAMES avrdude
  1952. DOC "Path to avrdude programmer binary.")
  1953. find_program(AVRSIZE_PROGRAM
  1954. NAMES avr-size)
  1955. find_file(ARDUINO_AVRDUDE_CONFIG_PATH
  1956. NAMES avrdude.conf
  1957. PATHS ${ARDUINO_SDK_PATH} /etc/avrdude /etc
  1958. PATH_SUFFIXES hardware/tools
  1959. hardware/tools/avr/etc
  1960. DOC "Path to avrdude programmer configuration file."
  1961. NO_SYSTEM_ENVIRONMENT_PATH)
  1962. if(NOT CMAKE_OBJCOPY)
  1963. find_program(AVROBJCOPY_PROGRAM
  1964. avr-objcopy)
  1965. set(ADDITIONAL_REQUIRED_VARS AVROBJCOPY_PROGRAM)
  1966. set(CMAKE_OBJCOPY ${AVROBJCOPY_PROGRAM} CACHE PATH "OBJCOPY Program for firmware convertion in hex")
  1967. endif(NOT CMAKE_OBJCOPY)
  1968. set(ARDUINO_DEFAULT_BOARD uno CACHE STRING "Default Arduino Board ID when not specified.")
  1969. set(ARDUINO_DEFAULT_PORT CACHE STRING "Default Arduino port when not specified.")
  1970. set(ARDUINO_DEFAULT_SERIAL CACHE STRING "Default Arduino Serial command when not specified.")
  1971. set(ARDUINO_DEFAULT_PROGRAMMER CACHE STRING "Default Arduino Programmer ID when not specified.")
  1972. # Ensure that all required paths are found
  1973. required_variables(VARS
  1974. ARDUINO_PLATFORMS
  1975. ARDUINO_CORES_PATH
  1976. ARDUINO_BOOTLOADERS_PATH
  1977. ARDUINO_LIBRARIES_PATH
  1978. ARDUINO_BOARDS_PATH
  1979. ARDUINO_PROGRAMMERS_PATH
  1980. ARDUINO_VERSION_PATH
  1981. ARDUINO_AVRDUDE_FLAGS
  1982. ARDUINO_AVRDUDE_PROGRAM
  1983. ARDUINO_AVRDUDE_CONFIG_PATH
  1984. AVRSIZE_PROGRAM
  1985. ${ADDITIONAL_REQUIRED_VARS}
  1986. MSG "Invalid Arduino SDK path (${ARDUINO_SDK_PATH}).\n")
  1987. detect_arduino_version(ARDUINO_SDK_VERSION)
  1988. set(ARDUINO_SDK_VERSION ${ARDUINO_SDK_VERSION} CACHE STRING "Arduino SDK Version")
  1989. set(ARDUINO_SDK_VERSION_MAJOR ${ARDUINO_SDK_VERSION_MAJOR} CACHE STRING "Arduino SDK Major Version")
  1990. set(ARDUINO_SDK_VERSION_MINOR ${ARDUINO_SDK_VERSION_MINOR} CACHE STRING "Arduino SDK Minor Version")
  1991. set(ARDUINO_SDK_VERSION_PATCH ${ARDUINO_SDK_VERSION_PATCH} CACHE STRING "Arduino SDK Patch Version")
  1992. if(ARDUINO_SDK_VERSION VERSION_LESS 0.19)
  1993. message(FATAL_ERROR "Unsupported Arduino SDK (require verion 0.19 or higher)")
  1994. endif()
  1995. message(STATUS "Arduino SDK version ${ARDUINO_SDK_VERSION}: ${ARDUINO_SDK_PATH}")
  1996. setup_arduino_size_script(ARDUINO_SIZE_SCRIPT)
  1997. set(ARDUINO_SIZE_SCRIPT ${ARDUINO_SIZE_SCRIPT} CACHE INTERNAL "Arduino Size Script")
  1998. #print_board_list()
  1999. #print_programmer_list()
  2000. set(ARDUINO_FOUND True CACHE INTERNAL "Arduino Found")
  2001. mark_as_advanced(
  2002. ARDUINO_CORES_PATH
  2003. ARDUINO_VARIANTS_PATH
  2004. ARDUINO_BOOTLOADERS_PATH
  2005. ARDUINO_LIBRARIES_PATH
  2006. ARDUINO_BOARDS_PATH
  2007. ARDUINO_PROGRAMMERS_PATH
  2008. ARDUINO_VERSION_PATH
  2009. ARDUINO_AVRDUDE_FLAGS
  2010. ARDUINO_AVRDUDE_PROGRAM
  2011. ARDUINO_AVRDUDE_CONFIG_PATH
  2012. ARDUINO_OBJCOPY_EEP_FLAGS
  2013. ARDUINO_OBJCOPY_HEX_FLAGS
  2014. AVRSIZE_PROGRAM)
  2015. endif()
  2016. if(ARDUINO_SDK_VERSION VERSION_LESS 1.5)
  2017. set(ARDUINO_PLATFORM "AVR")
  2018. else()
  2019. if(NOT ARDUINO_PLATFORM)
  2020. register_hardware_platform(${ARDUINO_SDK_PATH}/hardware/arduino/avr)
  2021. set(ARDUINO_PLATFORM "AVR")
  2022. else()
  2023. string(TOLOWER ${ARDUINO_PLATFORM} _platform)
  2024. register_hardware_platform(${ARDUINO_SDK_PATH}/hardware/arduino/${_platform})
  2025. endif()
  2026. endif()