Git Product home page Git Product logo

arduino-cmake-toolchain's Introduction

Arduino CMake Toolchain

Arduino CMake toolchain is a CMake toolchain for cross-compiling CMake based projects for all Arduino compatible boards (AVR, ESP32 etc.). Of course, this means all the benefits of CMake for Arduino compilation, like using your favourite IDE, configuration checks (e.g. try_compile, CheckTypeSize), etc. This also brings the Arduino compilation to professional users, who are limited by the Arduino IDE compilation.

Project Roots

Arduino-CMake-NG is a great project, which could have prevented me from writing yet another Arduino CMake toolchain. However, as claimed by the project, Arduino-CMake-NG could not be easily utilized/modified for other Arduino compatible boards other than AVR, like ESP32, due to the fact that it does not fully work the way Arduino IDE works and has lot of AVR specific stuff. An other important limitation is related to portability. Arduino-CMake-NG provides Arduino specific CMake interface, requiring CMake scripts to be written/modified specifically for Arduino, rather than just passing -D CMAKE_TOOLCHAIN_FILE=/path/to/Arduino-toolchain.cmake to a generic CMake project.

My initial expectation was to contribute to Arduino-CMake-NG to fix the above limitations, but had to redo a lot of core logic making it very incompatible (including the usage). Also, the project Arduino-CMake-NG seems to be no longer maintained. I would like to acknowledge the authors who contributed directly/indirectly to Arduino-CMake-NG, and thus indirectly contributed to this project.

Features

  • CMake Arduino toolchain (passed to CMake using -D CMAKE_TOOLCHAIN_FILE=/path/to/Arduino-toolchain.cmake)
    • Support for all Arduino compatible platforms (such as AVR, ESP32 etc.)
    • Generic CMake scripting interface without requiring Arduino specific functions
    • Arduino IDE compatible build (e.g. use of build rules and flags in board.local.txt, pre/postbuild hooks etc.)
    • Selection of board and board-specific menu options as in Arduino IDE tools menu (See ARDUINO_BOARD_OPTIONS_FILE)
  • Generate Arduino HEX binaries and upload to Arduino boards (See target_enable_arduino_upload)
    • Upload using serial port
    • Remote provisioning through network
    • Upload using programmer
    • Burn bootloader
  • Support linking with Arduino libraries (see target_link_arduino_libraries)
    • Arduino native libraries (e.g. Ethernet, Wire)
    • User installed 3rd Party Arduino libraries (e.g. IRremote)
    • Project specific Arduino libraries (those present in <CMAKE_SOURCE_DIR>/libraries)
  • Support for automatic dependency resolution (Arduino IDE like, but unprofessional)
  • Serial port monitoring
  • Support for .ino and '.pde' sketch files (Arduino IDE like, but unprofessional)
  • Board and Libraries Management without requiring installation of Arduino IDE

Usage

The provided toolchain file (Arduino-toolchain.cmake) is passed to cmake as folows

cmake -D CMAKE_TOOLCHAIN_FILE=/path/to/Arduino-toolchain.cmake <CMAKE_SOURCE_DIR>

Note: As this is cross compilation, use any cross compilation compatible generator, like makefile generators (e.g. -G "NMake Makefiles" or -G "MinGW Makefiles" on Windows command prompt or -G "Unix Makefiles" on UNIX compatible prompts etc.).

The above command generates a file BoardOptions.cmake in the build directory, that enumerates all the installed Arduino boards (installed through Arduino IDE or any other board manager) and their menu options. Select the Arduino board and any non-default options for the board from the BoardOptions.cmake (Or from cmake-gui), and then reinvoke the same command above.

If you already have a customized BoardOptions.cmake file for the Arduino Board, you can use that instead, without waiting for the generation of BoardOptions.cmake, as given below.

cmake -D CMAKE_TOOLCHAIN_FILE=/path/to/Arduino-toolchain.cmake -D ARDUINO_BOARD_OPTIONS_FILE=/path/to/any/BoardOptions.cmake <CMAKE_SOURCE_DIR>

Note:

  1. After the cmake generation is successful, changing the menu options in BoardOptions.cmake may work, but changing the board itself may not be allowed by CMake because the compiler, ABI, features determination and any cache dependencies may not be retriggered again.
  2. CMake does not support build for multiple architectures in the same build tree. If a project requires to build applications for more than one type of Arduino boards, refer to CMake documentation for multiple architecture build.
  3. When this toolchain is used, executables (added with add_executable) have the entry points setup()/loop() and not main(). Need to include "Arduino.h" for these entry points.
  4. If your source files are compiled for both Arduino and other platforms like linux, then the CMake flag ARDUINO and the compiler flag ARDUINO can be used for script/code portability. Other Arduino board/architecture specific standard flags can also be used.

Linking with Arduino code/libraries (target_link_arduino_libraries)

<CMAKE_SOURCE_DIR>/CMakeLists.txt and any other dependent CMake scripts of the project contain the standard CMake scripting using add_library, add_executable etc. without Arduino specific changes. Refer to CMake documentation for the same. However when the project source code depends on the Arduino code or libraries (i.e. if the corresponding header files are included), then appropriate linking is required, as expected. This is done using target_link_arduino_libraries as explained below.

If Arduino.h is included in your source files, then the target must be linked against the 'core' Arduino library as follows.

add_library(my_library my_library.c) # my_library.c includes Arduino.h
target_link_arduino_libraries(my_library PRIVATE core)

If any other native or 3rd party libraries are used, then those libraries must be linked similarly as follows.

add_executable(my_app my_app.c) # my_app.c includes Wire.h, Arduino.h
target_link_arduino_libraries(my_app PRIVATE Wire core)

Like Arduino IDE, if the required Arduino libraries are to be automatically identified and linked, then it can be done as follows.

add_executable(my_app my_app.c) # my_app.c includes Wire.h, Arduino.h
# Link Wire and core automatically (PUBLIC linking in this example)
target_link_arduino_libraries(my_app AUTO_PUBLIC)

Note:

  1. Wire and core in the above examples are not CMake targets. They are just Arduino library names (case-sensitive).
  2. It is required only to specify the direct dependencies. Any deeper dependencies are automatically identified and linked. For example, if SD.h is included, it is sufficient to link with SD, even if SD depends on other Arduino libraries, like SPI.

These examples illustrates simple usage, but powerful enough for most use cases. However more advanced control and customization of Arduino libraries should be possible. Please refer to the Examples folder, as well as the API documentation of target_link_arduino_libraries (Currently documented as comments in BoardBuildTargets.cmake).

Uploading to the target board (target_enable_arduino_upload)

If support for generating HEX binary and uploading it to the board is required, then a call to target_enable_arduino_upload is required for each executable target, as shown below.

add_executable(my_executable my_executable.c)
target_link_arduino_libraries(my_executable PRIVATE core) # Assuming my_executable.c includes Arduino.h
target_enable_arduino_upload(my_executable) # This adds a target upload-my_executable

Upload the executable (from the above example) to the board on COM3 serial port as follows

<make-command> upload-my_executable SERIAL_PORT=COM3

Upload the executable to the board through remote provisioning as follows

<make-command> upload-my_executable NETWORK_PORT=<IP>[:<port>]

For using a programmer, select the programmer in board options or the CMake GUI, and then execute the following

<make-command> program-my_executable CONFIRM=1

Using the programmer, bootloader can be flashed as below

<make-command> burn-bootloader CONFIRM=1

Serial port monitoring

Currently there is no support available for this within this toolchain. However any external serial port monitor can be used (e.g. Putty). External serial monitor may need to be closed before upload and reopened after upload, because both use the same serial port.

Known issues

Many of the issues in the master branch have been fixed in release-1.1-dev branch. Although not tested to be fully stable, release-1.1-dev is stable enough to try out and report any futher issues before it gets merged into master.

Below are the list of known issues in the master branch.

1. Uploaded application does not work on some boards

Caused by build linking issue that does not link some object files related to platform variant sources contained in the core library. Affects any Arduino platform that has variant source files in addition to the variant header files.

Resolution: Please try with release-1.1-dev branch or otherwise, temporary fixes are available in the branches fix/variant_link_alt1 and fix/variant_link_alt2.

Compromises when using the fix/variant_link_alt1 fix: (1) CMake version must be above 3.13, (2) Application needs to link with core directly, like in Examples/01_hello_world, and not like in Examples/03_portable_app which links transitively.

Compromises when using the fix/variant_link_alt2 fix: Need to retrigger cmake and do rebuild, after the first successful build, if transitive linking of core is used in the project. May get "source some_file.o not found error" in CMake during the first invocation of CMake that can be ignored.

2. Build/link issue on some 3rd party platforms

Resolution: Please try with release-1.1-dev branch.

3. Some libraries are not detected by target_link_arduino_libraries

Currently, target_link_arduino_libraries takes only include names (i.e. the name of the header file without extension). If the include name does not match with the library name (as mentioned in library.properties of the library), the detection of the library fails (Refer issue #19).

Workaround: Rename the library folder to the include name and use include name in target_link_arduino_libraries.

Resolution: Please try with release-1.1-dev branch.

How it works

This toolchain follows the build process described in Arduino Build Process, and processes the JSON, platform.txt and boards.txt files correponding to the Arduino platform as specified in the documentation Arduino IDE 1.5 3rd party Hardware specification.

License

MIT © 2020 Arduino-CMake-Toolchain

arduino-cmake-toolchain's People

Contributors

a9183756-gh avatar petermitrano avatar robertwilbrandt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-cmake-toolchain's Issues

Unknown CMake command "target_link_arduino_libraries"

I'm trying to compile the example project hello-world, but i'm stuck with the issue it can not find
target_link_arduino_libraries.

do you have any hints to solve this issue?

/home/hacki/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/201.7223.86/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -D ARDUINO_TOOLCHAIN_FILE=~/git/Arduino-CMake-Toolchain/Arduino-toolchain.cmake -G "CodeBlocks - Unix Makefiles" /home/hacki/git/Arduino-CMake-Toolchain/Examples/01_hello_world
-- The CXX compiler identification is GNU 9.3.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:7 (target_link_arduino_libraries):
  Unknown CMake command "target_link_arduino_libraries".


-- Configuring incomplete, errors occurred!
See also "/home/hacki/git/Arduino-CMake-Toolchain/Examples/01_hello_world/cmake-build-debug/CMakeFiles/CMakeOutput.log".

[Finished]
``

Linking error when compiling stm32duino project

When compiling a stm32duino project the linker complains about missing references. I tried all branches. The output is:

/home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: lib_arduino_lib_core.a(startup_stm32yyxx.S.obj): in function LoopFillZerobss': (.text.Reset_Handler+0x2a): undefined reference to SystemInit'
/home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: lib_arduino_lib_STM32duino_Low_Power.a(STM32LowPower.cpp.o): in function STM32LowPower::begin()': STM32LowPower.cpp:(.text._ZN13STM32LowPower5beginEv+0x4): undefined reference to LowPower_init'
/home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: lib_arduino_lib_core.a(HardwareSerial.cpp.o): in function HardwareSerial::write(unsigned char)': HardwareSerial.cpp:(.text._ZN14HardwareSerial5writeEh+0x2a): undefined reference to uart_enable_tx'
/home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: HardwareSerial.cpp:(.text._ZN14HardwareSerial5writeEh+0x46): undefined reference to serial_tx_active' /home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: HardwareSerial.cpp:(.text._ZN14HardwareSerial5writeEh+0x52): undefined reference to uart_attach_tx_callback'
/home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: lib_arduino_lib_core.a(HardwareSerial.cpp.o): in function HardwareSerial::HardwareSerial(void*, HalfDuplexMode_t)': HardwareSerial.cpp:(.text._ZN14HardwareSerialC2EPv16HalfDuplexMode_t+0x52): undefined reference to pinmap_pin'
/home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: HardwareSerial.cpp:(.text._ZN14HardwareSerialC2EPv16HalfDuplexMode_t+0x5c): undefined reference to pinmap_pin' /home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: lib_arduino_lib_core.a(HardwareSerial.cpp.o): in function HardwareSerial::enableHalfDuplexRx()':
HardwareSerial.cpp:(.text._ZN14HardwareSerial18enableHalfDuplexRxEv+0x28): undefined reference to uart_enable_rx' /home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: lib_arduino_lib_core.a(board.c.o): in function init':
board.c:(.text.init+0x2): undefined reference to hw_config_init' /home/user/local/arduino/arduino15/packages/STM32/tools/xpack-arm-none-eabi-gcc/9.2.1-1.1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: lib_arduino_lib_core.a(wiring_time.c.o): in function millis':
wiring_time.c:(.text.millis+0x2): undefined reference to `getCurrentMillis'
collect2: error: ld returned 1 exit status
CMake Error at .scripts/LinkScript.cmake:286 (message):
Linking test_deepsleep failed!!!

The CXX compiler identification is unknown (Optiboot)

Hi,
having my Board as mega 2560 everything is fine. All compilers are found and perfectly used.
But now i have burned Optiboot onto my mega and selected the optiboot2560 board.

Now it searches avr-gcc and avr-g++ in paths where no binary is located. avr-gcc and avrg++ are available via Path. I have added CMAKE_CXX_COMPILER and CMAKE_C_COMPILER but no success.

Can you give me any pointers where i could possibly look?
I can't tell if the optiboot files are wrong or there is something with arduino toolchain.

hacki@lx-hacki:~/git/homeduino$ cmake -DCMAKE_TOOLCHAIN_FILE=~/git/Arduino-CMake-Toolchain/Arduino-toolchain.cmake -G "CodeBlocks - Unix Makefiles" .
/usr/share/arduino
-- Found Arduino package /home/hacki/.arduino15/package_index.json
-- Found Arduino package /home/hacki/.arduino15/package_optiboot_optiboot-additional_index.json
-- Found Arduino package /usr/share/arduino/hardware/package_index_bundled.json
-- Found Arduino Platform: /usr/share/arduino/hardware/arduino/avr
-- Found Arduino Platform: /home/hacki/.arduino15/packages/Optiboot/hardware/avr/0.8.0
-- Selected Arduino Board: Optiboot on Mega2560 [avr.optiboot2560]
-- The CXX compiler identification is unknown
-- Indexing Arduino libraries for the project
CMake Error at CMakeLists.txt:3 (project):
  The CMAKE_CXX_COMPILER:

    /home/hacki/git/homeduino/_pkg_mgr/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "/home/hacki/git/homeduino/CMakeFiles/CMakeOutput.log".
See also "/home/hacki/git/homeduino/CMakeFiles/CMakeError.log".

Board from Optiboot set(ARDUINO_BOARD "avr.optiboot2560") # Optiboot on Mega2560

CMakeError.log

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /home/hacki/git/homeduino/cmake-build-debug/_pkg_mgr/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ 
Build flags: 
Id flags:  

The output was:
No such file or directory

No compiler warnings? Can compiler flags be set on a by-target basis?

Potential bug? I don't see any compiler warnings even though I expect some.

Is there a way to set compiler flags either globally or on a per-target basis? And is it expected to not see anything from a #pragma message directive?

I've attempted to use the following:

  • set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") both before and after the toolchain file inclusion and with and without cacheing
  • add_definitions("-Wall -Wextra -pedantic")
  • target_compile_options(myLib PUBLIC -Wall -Wextra -pedantic)

However when I have an unused and uninitialized variable, e.g.,

void loop() {
   int x;
}

I see no warnings.

And even when attempting either the #pragma message "test" or #warning "test" I don't see any warnings printed to the screen. Switching to #error "test" triggers a compile-time error and shows the message.

Output from CMake config shown below running on MacOS 12.2 using Arduino SDK 1.8.19:

/Applications/Arduino.app/Contents/Java
-- Found Arduino Platform: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr
-- Found Arduino Platform: /Users/connorfuhrman/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0
-- Selected Arduino Board: Arduino Uno [avr.uno]
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-gcc
-- Found Arduino Library TimerInterrupt: /Users/connorfuhrman/Documents/Arduino/libraries/TimerInterrupt
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/my/project

Query: do you know if this works with the Arduino setup on Mac OS?

It didn't work out of the box for me, but I expect this is an error between chair and keyboard. However, if this hasn't been tested on Mac OS then I'll have a look at the cmake code as well.

My cmake commands was:

cmake -DARDUINO_BOARD=mbed_giga.giga  -DCMAKE_MAKE_PROGRAM=make -D ARDUINO_INSTALL_PATH=/opt/homebrew/bin -D CMAKE_TOOLCHAIN_FILE=$AR_CMAKE/Arduino-toolchain.cmake $AR_CMAKE/Examples/04_multi_app

I also tried /Applications/Arduino\ IDE.app as the install path.

As far as I can tell the search_paths in the library index is fine, but the find library function has an empty search path.

_library_search_process excludes valid libraries when there isn't a matching header.

In Arduino-CMake-Toolchain-release-1.1-dev\Arduino\System\BoardBuildTargets.cmake at the end of the function function(_library_search_process lib search_paths_var search_suffixes_var return_var) is this final check:

	# Although we got the match, let us search for the required header within the folder
	file(GLOB_RECURSE lib_header_path "${matched_lib_path}/${lib}.h*")
	if (NOT lib_header_path)
		set ("${return_var}" "${lib}-NOTFOUND" PARENT_SCOPE)
		return()
	endif()

I am not sure if this applied to other libraries. But the ESP32 BLE Arduino library has some caveats:

  1. The library folder name is BLE. So the call has to be target_link_arduino_libraries(arc003-2 AUTO_PUBLIC PRIVATE BLE) even though that isn't the library name.
  2. The library name is 'ESP32 BLE Arduino'. The mismatch here does not seem to be an issue (probably because BLE is still in the name).
  3. There is no BLE.h or BLE.cpp in the src as the library is comprised of other files. This is the core issue that prevents this library from being found.

Possible fixes are to:

  1. Modify the final check in _library_search_process to maybe include a flag to skip that check or remove it.
  2. Add BLE.h or BLE.cpp to the library (not ideal).

For me, I have commented out the check for the time being.

Looking forward to your thoughts.

Maintained version

Hi,

this projects seems to be not maintained now for over two years. Many issues are open and no pull requests are merged.

I've started to integrate a few pull requests and would continue to do so with other open issues / PRs:

https://github.com/technyon/Arduino-CMake-Toolchain

I was already able to compile with ESP32 core 2.0.3 which isn't possible with the code from the original repository.

Should one of the authors of the open PRs here read this, please reopen your PRs against my fork. Otherwise I'd see to manually integrate them.

'Arduino Uno WiFi Rev2' support

Hi!

First of all I would like to say you great thank you for this awesome project which allows coding in normal IDEs. =)

And now about the problem I faced... Seems Arduino-CMake-Toolchain detected this board (Arduino Uno WiFi Rev2) correctly, build of simple hello-world code passes, but:

  • I don't see any available Serial for this board (it was IDE problem, but still interesting why it doesn't see it)
  • Even Blink example doesn't work correctly after flashing - it blinks with delay ~9 ms and doesn't matter which parameter I pass to delay: 1000 or 1000000.

What I've tried:

  • Branch release-1.1-dev: I don't see upload target for this hello-world project
  • Branches variant_link_alt (both): didn't resolve the problem

Hello-world project: hello-world.zip

Could you please fix it or suggest something helpful for me?

Dependency on the Arduino IDE

This should not have a hard dependency on the Arduino IDE. The way forward for Arduino is to use the CLI, even the installed IDE will use the CLI. It would be nice to be able to set your ARDUINO_INSTALL_PATH to the CLI path. I could try to make this change but it will take me a while to get up to speed on all of this code.

Also you shouldn't be reading all of these files, just invoke the executable and get the results directly from the CLI! It is much more efficient, readable and maintainable.
For example, getting the CLI version...

exec_program(Executable "${ARDUINO_INSTALL_PATH}/arduino-cli" "version" _version)

Can't find pins_arduino.h on Attiny85

Using Toolchain master & https://github.com/damellis/attiny (added in Arduino IDE, works fine there) I'm having a couple of issues (one easy to work around).

CMake 3.19.2 (bundled with Jetbrains CLion)

  JSON path 'packages.1.platforms.3.toolsDependencies.N' in 'ard_pkg.2'
  invalid!!!

This can be worked around by adding "toolsDependencies": [] to the package index json.

  1. The titular issue:
In file included from C:\Users\lex\Downloads\arduino-1.8.15\hardware\arduino\avr\cores\arduino\wiring_private.h:31:0,
                 from C:\Users\lex\Downloads\arduino-1.8.15\hardware\arduino\avr\cores\arduino\WInterrupts.c:33:
C:\Users\lex\Downloads\arduino-1.8.15\hardware\arduino\avr\cores\arduino\Arduino.h:258:10: fatal error: pins_arduino.h: No such file or directory
 #include "pins_arduino.h"
          ^~~~~~~~~~~~~~~~
compilation terminated.
mingw32-make.exe[3]: *** [CMakeFiles\_arduino_lib_core.dir\build.make:81: CMakeFiles/_arduino_lib_core.dir/C_/Users/lex/Downloads/arduino-1.8.15/hardware/arduino/avr/cores/arduino/WInterrupts.c.o] Error 1

The file definitely exists.

Board options:

set(ARDUINO_BOARD "ATtiny25/45/85 [avr.ATtinyX5]") # ATtiny25/45/85
set(ARDUINO_AVR_ATTINYX5_MENU_CPU_ATTINY85 TRUE) # ATtiny85
set(ARDUINO_AVR_ATTINYX5_MENU_CLOCK_INTERNAL8 TRUE) # Internal 8 MHz

ESP8266

Hello, nice work to bring a actual version of a cmake-toolchain variant.

I like to use this with arduino + esp8266 so i tried to setup a project with this, but i can't link it.

Look at following terminal output:

Executing recipe.hooks.linking.prelink.1.pattern hook
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: warning: cannot find entry symbol app_entry; defaulting to 0000000040100000
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-dtoa.o):(.literal+0x44): undefined reference to `malloc'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-dtoa.o): in function `_dtoa_r':
/home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/dtoa.c:238: undefined reference to `malloc'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-mprec.o):(.literal+0x0): undefined reference to `_calloc_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-mprec.o): in function `_Balloc':
/home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/mprec.c:103: undefined reference to `malloc'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/mprec.c:107: undefined reference to `_calloc_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/mprec.c:124: undefined reference to `_calloc_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-mprec.o): in function `_Bfree':
/home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/mprec.c:139: undefined reference to `malloc'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-mprec.o): in function `__pow5mult':
/home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdlib/mprec.c:435: undefined reference to `malloc'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-nano-svfprintf.o):(.literal+0x0): undefined reference to `_malloc_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-nano-svfprintf.o):(.literal+0x4): undefined reference to `_realloc_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-nano-svfprintf.o):(.literal+0x8): undefined reference to `_free_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-nano-svfprintf.o): in function `__ssputs_r':
/home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c:202: undefined reference to `_malloc_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c:213: undefined reference to `_realloc_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c:217: undefined reference to `_free_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-nano-svfprintf.o): in function `__ssprint_r':
/home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c:293: undefined reference to `_malloc_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c:304: undefined reference to `_realloc_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c:309: undefined reference to `_free_r'
/home/jonas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: /home/jonas/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/sdk/libc/xtensa-lx106-elf/lib/libc.a(lib_a-nano-svfprintf.o): in function `_svfprintf_r':
/home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c:507: undefined reference to `_malloc_r'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/IOTNetCore.dir/build.make:92: IOTNetCore.elf] Fehler 1
make[3]: Verzeichnis „/home/jonas/DEV/Projects/DEV.CPP.IOTNetCore/cmake-build-debug“ wird verlassen
make[2]: *** [CMakeFiles/Makefile2:170: CMakeFiles/IOTNetCore.dir/all] Fehler 2
make[2]: Verzeichnis „/home/jonas/DEV/Projects/DEV.CPP.IOTNetCore/cmake-build-debug“ wird verlassen
make[1]: *** [CMakeFiles/Makefile2:177: CMakeFiles/IOTNetCore.dir/rule] Fehler 2
make[1]: Verzeichnis „/home/jonas/DEV/Projects/DEV.CPP.IOTNetCore/cmake-build-debug“ wird verlassen
make: *** [Makefile:157: IOTNetCore] Fehler 2

Toolchain build fails on Mac OS with ESP32 Platform v2.x.x

Hi there!

I faced the problem of setting up toolchain for building for ESP32 v2.x.x platform on Mac OS.

The typical setup like using basic hello_world example fails with the next error:

CMake Error at CMakeLists.txt:5 (project):
  The CMAKE_CXX_COMPILER:

    {tools.xtensa-esp32-elf-gcc.path}/bin/xtensa-esp32-elf-g++

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

As I researched the problem is that complex variables of platform.txt for 2.0.x are not expanded properly.

For example this one:

compiler.path={tools.{build.tarch}-{build.target}-elf-gcc.path}/bin/

All properties that are constructed of variables inside variables like in the example above are expanded to only one level.

I compared platform.txt of v1 and v2 — and indeed, v2 heavily uses kind of recursive expansion.

I'm trying to figure out the place inside the toolchain where this expansion is made to fix it. If someone knows — please point me to.

UPDATE: I'm testing on release-1.1-dev branch.

/cc @a9183756-gh @technyon

Upload fails on avr:leonardo

Hello,

First, thank you for sharing your work, it is very useful and appreciated. I used it successfully with an Arduino Uno board.

I am having trouble finding the cause of the upload failure using a Leonardo board. I am following these simple steps to configure, build and upload your hello_world example:

  • configure: cmake .. -D CMAKE_TOOLCHAIN_FILE=path/to/Arduino-toolchain.cmake
  • edit BoardOptions.cmake and uncomment the following line:
set(ARDUINO_BOARD "Arduino Leonardo [avr.leonardo]") # Arduino Leonardo
  • configure again: cmake .
  • build: make
  • upload:
$ make SERIAL_PORT=/dev/ttyACM0 upload-hello_world
[ 89%] Built target _arduino_lib_core
[ 96%] Built target hello_world
[100%] Uploading 'hello_world'

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/sylvain/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/home/sylvain/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM0
         Using Programmer              : avr109
         Overriding Baud Rate          : 57600
         AVR Part                      : ATmega32U4
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : butterfly
         Description     : Atmel AppNote AVR109 Boot Loader

Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding

avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = "�"; type =
    Software Version = .; Hardware Version = .
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: exit bootloader

I'm not sure where to go from here.
Uploading a sketch with arduino-cli works well.

build.opt not found

Hello,
I just tried out to build the examples for ESP8266 generic board:

----------------------------------------- log starts here--------------------------------

andreas@notebook-fh:~/github/Arduino-CMake-Toolchain/Examples/b$ cmake -DCMAKE_TOOLCHAIN_FILE=../../Arduino-toolchain.cmake -DARDUINO_INSTALL_PATH=/usr/local/arduino-1.8.16 -DARDUINO_BOARD="Generic ESP8266 Module [esp8266.generic]" ..
/usr/local/arduino-1.8.16
-- Found Arduino Platform: /usr/local/arduino-1.8.16/hardware/arduino/avr
-- Found Arduino Platform: /home/andreas/.arduino15/packages/esp32/hardware/esp32/2.0.0
-- Found Arduino Platform: /home/andreas/.arduino15/packages/esp8266/hardware/esp8266/3.1.2
-- Found Arduino Platform: /home/andreas/.arduino15/packages/arduino/hardware/avr/1.8.6
-- Found Arduino Platform: /home/andreas/.arduino15/packages/SparkFun/hardware/apollo3/1.2.1
-- Selected Arduino Board: Generic ESP8266 Module [esp8266.generic]
-- Selected board option: "CPU Frequency" = "80 MHz"
-- Selected board option: "VTables" = "Flash"
-- Selected board option: "C++ Exceptions" = "Disabled (new aborts on oom)"
-- Selected board option: "Stack Protection" = "Disabled"
-- Selected board option: "SSL Support" = "All SSL ciphers (most compatible)"
-- Selected board option: "MMU" = "32KB cache + 32KB IRAM (balanced)"
-- Selected board option: "Non-32-Bit Access" = "Use pgm_read macros for IRAM/PROGMEM"
-- Selected board option: "Reset Method" = "dtr (aka nodemcu)"
-- Selected board option: "Crystal Frequency" = "26 MHz"
-- Selected board option: "Flash Frequency" = "40MHz"
-- Selected board option: "Flash Mode" = "DOUT (compatible)"
-- Selected board option: "Flash Size" = "1MB (FS:64KB OTA:~470KB)"
-- Selected board option: "Builtin Led" = "2"
-- Selected board option: "NONOS SDK Version" = "nonos-sdk 2.2.1+100 (190703)"
-- Selected board option: "lwIP Variant" = "v2 Lower Memory"
-- Selected board option: "Debug port" = "Disabled"
-- Selected board option: "Debug Level" = "None"
-- Selected board option: "Erase Flash" = "Only Sketch"
-- Selected board option: "Upload Speed" = "115200"
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Check for working C compiler: /home/andreas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/bin/xtensa-lx106-elf-gcc
-- Check for working C compiler: /home/andreas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/bin/xtensa-lx106-elf-gcc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "/home/andreas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/bin/xtensa-lx106-elf-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/andreas/github/Arduino-CMake-Toolchain/Examples/b/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make cmTC_49ea6/fast && /usr/bin/make -f CMakeFiles/cmTC_49ea6.dir/build.make CMakeFiles/cmTC_49ea6.dir/build
    make[1]: Verzeichnis „/home/andreas/github/Arduino-CMake-Toolchain/Examples/b/CMakeFiles/CMakeTmp“ wird betreten
    Building C object CMakeFiles/cmTC_49ea6.dir/testCCompiler.c.o
    /home/andreas/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.1.0-gcc10.3-e5f9fec/bin/xtensa-lx106-elf-gcc  -D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ -D_GNU_SOURCE -DESP8266 @/home/andreas/github/Arduino-CMake-Toolchain/Examples/b/core/build.opt -I/home/andreas/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/sdk/include -I/home/andreas/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/sdk/lwip2/include -I/home/andreas/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/sdk/libc/xtensa-lx106-elf/include -I/home/andreas/github/Arduino-CMake-Toolchain/Examples/b/core -c @/home/andreas/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/warnings/none-cflags -std=gnu17  -Os -g -free -fipa-pta -Werror=return-type -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -ffunction-sections -fdata-sections -fno-exceptions  -DMMU_IRAM_SIZE=0x8000 -DMMU_ICACHE_SIZE=0x8000  -DNONOSDK22x_190703=1 -DF_CPU=80000000L -DLWIP_OPEN_SRC -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0   -DARDUINO=108016 -DARDUINO_ESP8266_GENERIC -DARDUINO_ARCH_ESP8266 "-DARDUINO_BOARD=\"ESP8266_GENERIC\"" "-DARDUINO_BOARD_ID=\"{_id}\"" -DLED_BUILTIN=2 -DFLASHMODE_DOUT   -DARDUINO_ESP8266_GENERIC_MENU_BAUD_115200 -DARDUINO_ESP8266_GENERIC_MENU_CRYSTALFREQ_26 -DARDUINO_ESP8266_GENERIC_MENU_DBG_DISABLED -DARDUINO_ESP8266_GENERIC_MENU_EESZ_1M64 -DARDUINO_ESP8266_GENERIC_MENU_EXCEPTION_DISABLED -DARDUINO_ESP8266_GENERIC_MENU_FLASHFREQ_40 -DARDUINO_ESP8266_GENERIC_MENU_FLASHMODE_DOUT -DARDUINO_ESP8266_GENERIC_MENU_IP_LM2F -DARDUINO_ESP8266_GENERIC_MENU_LED_2 -DARDUINO_ESP8266_GENERIC_MENU_LVL_NONE____ -DARDUINO_ESP8266_GENERIC_MENU_MMU_3232 -DARDUINO_ESP8266_GENERIC_MENU_NON32XFER_FAST -DARDUINO_ESP8266_GENERIC_MENU_RESETMETHOD_NODEMCU -DARDUINO_ESP8266_GENERIC_MENU_SDK_NONOSDK_190703 -DARDUINO_ESP8266_GENERIC_MENU_SSL_ALL -DARDUINO_ESP8266_GENERIC_MENU_STACKSMASH_DISABLED -DARDUINO_ESP8266_GENERIC_MENU_VT_FLASH -DARDUINO_ESP8266_GENERIC_MENU_WIPE_NONE -DARDUINO_ESP8266_GENERIC_MENU_XTAL_80   /home/andreas/github/Arduino-CMake-Toolchain/Examples/b/CMakeFiles/CMakeTmp/testCCompiler.c -o CMakeFiles/cmTC_49ea6.dir/testCCompiler.c.o
    xtensa-lx106-elf-gcc: error: /home/andreas/github/Arduino-CMake-Toolchain/Examples/b/core/build.opt: No such file or directory
    make[1]: *** [CMakeFiles/cmTC_49ea6.dir/build.make:66: CMakeFiles/cmTC_49ea6.dir/testCCompiler.c.o] Fehler 1
    make[1]: Verzeichnis „/home/andreas/github/Arduino-CMake-Toolchain/Examples/b/CMakeFiles/CMakeTmp“ wird verlassen
    make: *** [Makefile:121: cmTC_49ea6/fast] Fehler 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)


-- Configuring incomplete, errors occurred!
See also "/home/andreas/github/Arduino-CMake-Toolchain/Examples/b/CMakeFiles/CMakeOutput.log".
See also "/home/andreas/github/Arduino-CMake-Toolchain/Examples/b/CMakeFiles/CMakeError.log".

------------------------------ log ends here ----------------------------------

I also tried out technyon's fork which stated in the readme that a bug with a missing build.opt was fixed. Sadly this version produces the same error.
I also tried out to disable the compiler check by setting some variables in the CMakeLists.txt (just can't remember the details...), but then the same error occured during compiling the first cpp file for the core library. So the problem in
both cases (compiler test and regular lib compile) is that .../core/build.opt is missing.
Any ideas what could be wrong? I am trying to build the examples for a generic ESP8266 board.

BR, Andreas

Board options not found in Ubuntu

Hi,

I've been trying to get the toolchain running on Ubuntu 18.04, but after following the steps on https://github.com/a9183756-gh/Arduino-CMake-Toolchain/blob/master/Examples/README.md
the BoardOptions.cmake file it creates is empty:

# Copyright (c) 2020 Arduino CMake Toolchain

###############################################################################
# This is an automatically generated template file for board options.
# You may edit it to comment/uncomment selected board and board options.
# However do not change the structure of this template, which is fixed and 
# any change to the structure gets overwritten.

And I suspect it simply is not finding the installed Arduino framework, which I'm not really quite sure is installed properly in the first place. I followed the normal instructions to install it in the main Arduino page. I'm a bit of a newbie on Ubuntu so I'm not quite sure if I have everything configured properly. The installation path of arduino is on /usr/share/arduino.

I have tried the same examples on Windows and it works like a charm, it finds the Arduino installation and boards just fine, and the BoardOptions.cmake is populated properly.

Maybe I'm missing some environment variable, or the path of the Arduino installation is wrong, I'm not sure, or maybe is something completely different.

I'll look into the code to see how it determines the Arduino installation path, but I figured I asked for help anyways.

Thanks!

Cannot find Arduino Nano

It seems to be looking at the right places:

-- Found Arduino Platform: /home/blasco/.arduino15/packages/esp32/hardware/esp32/1.0.2
-- Found Arduino Platform: /home/blasco/.arduino15/packages/esp8266/hardware/esp8266/2.5.0
-- Found Arduino Platform: /home/blasco/.arduino15/packages/arduino/hardware/avr/1.6.23
-- Found Arduino Platform: /home/blasco/.arduino15/packages/arduino/hardware/megaavr/1.8.3
-- Found Arduino Platform: /home/blasco/.arduino15/packages/atmel-avr-xminis/hardware/avr/0.

I can see that there is a Arduino Nano option in boards.txt for

-- Found Arduino Platform: /home/blasco/.arduino15/packages/arduino/hardware/avr/1.6.23

And I can see the arduino nano in board.txt there:

nano.name=Arduino Nano

nano.upload.tool=avrdude
nano.upload.protocol=arduino

nano.bootloader.tool=avrdude
nano.bootloader.unlock_bits=0x3F
nano.bootloader.lock_bits=0x0F

nano.build.f_cpu=16000000L
nano.build.board=AVR_NANO
nano.build.core=arduino
nano.build.variant=eightanaloginputs

Nevertheless, I don't see arduino nano related content in platform.txt

Is the script currently looking only at platform txt? What do I need to change to make it work with nano? Thank you for the great project

[Question/Bug] target_link_arduino_libraries - possible bug

Hello,

I dedected a problem in using of target_link_arduino_libraries.
I installed the ESPAsyncWiFiManager lib and added it to the target_link_arduino_libraries in cmake.
Other libs that I had downloaded and installed works without problems, but on this it had a problem with including/finding DNSServer.h header - which is a lib from Arduino Core.

Is there a workaround for this? My workaround is very ugly:

## WiFiManager Fix

set(wifiManagerLibName _arduino_lib_WiFiManager)
set(wifiManagerLibDeps ESP8266WebServer)

if (USE_ASYNC_WEBSERVER)
find_arduino_library(ESPAsyncWiFiManager WiFiManagerLibPath)
set(wifiManagerLibName _arduino_lib_ESPAsyncWiFiManager)
set(wifiManagerLibDeps ESPAsyncWebServer)
else()
find_arduino_library(WiFiManager WiFiManagerLibPath)
endif()

file(GLOB_RECURSE _arduino_lib_WiFiManager_source_list "${WiFiManagerLibPath}/.cpp" "${WiFiManagerLibPath}/.hpp" "${WiFiManagerLibPath}/*.h")

add_library(${wifiManagerLibName} "${_arduino_lib_WiFiManager_source_list}")
target_link_libraries(${wifiManagerLibName} PUBLIC _arduino_lib_DNSServer)
target_include_directories(${wifiManagerLibName} PUBLIC "${DNSServerLibPath}/src")
target_link_arduino_libraries(${wifiManagerLibName} PRIVATE core ${wifiManagerLibDeps})

#message(STATUS "WiFiManagerLibPath: ${WiFiManagerLibPath}")

target_link_libraries(${MAIN_TARGET} PUBLIC _arduino_lib_WiFiManager)
target_include_directories(${MAIN_TARGET} PUBLIC "${WiFiManagerLibPath}")`

There are a other way to import finding and import this header? I tried already to add the DNSServer directly to target_link_arduino_libraries.

platform.local.txt not supported

I've noticed that the file platform.local.txt is not considered when detecting toolchains. For example create the file
~/.arduino15/packages/arduino/hardware/mbed_nano/2.5.2/platform.local.txt with the content:
compiler.path=/usr/bin/

if you compile your code with "make VERBOSE=1" you can see that still the original compiler is used, located somewhere else, instead of the one in /usr/bin/

Arduino due produces newline in build command

I am currently unable to compile any project (including the provided examples) for the arduino Due board. I think i see (at least one place) where this comes from, but any help would be appreciated.

Problem Description

I successfully followed your Example and created a BoardOptions.cmake with the line for the arduino due uncommented:

set(ARDUINO_BOARD "Arduino Due (Programming Port) [sam.arduino_due_x_dbg]") # Arduino Due (Programming Port)

Running cmake again works correctly using the command:

cmake -D CMAKE_TOOLCHAIN_FILE=../Arduino-toolchain.cmake ../Examples

But now actually building the project fails:

>  cmake --build . --target upload-hello_world -- SERIAL_PORT=/dev/ttyUSB0
01_hello_world/CMakeFiles/_arduino_lib_core.dir/build.make:64: *** missing separator.  Stop.
CMakeFiles/Makefile2:157: recipe for target '01_hello_world/CMakeFiles/_arduino_lib_core.dir/all' failed
make[2]: *** [01_hello_world/CMakeFiles/_arduino_lib_core.dir/all] Error 2
CMakeFiles/Makefile2:132: recipe for target '01_hello_world/CMakeFiles/upload-hello_world.dir/rule' failed
make[1]: *** [01_hello_world/CMakeFiles/upload-hello_world.dir/rule] Error 2
Makefile:131: recipe for target 'upload-hello_world' failed
make: *** [upload-hello_world] Error 2

Running the whole thing with Ninja instead of make (i.e. append ```-G Ninja to the cmake commands) yields the error

ninja: error: rules.ninja:29: expected '=', got identifier
 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM  -D__SAM3X8E__ -mthumb -DUSB_VID=0...
                   ^ near here

Incorrectly generated files

Checking the file from the make error description actually shows an incorrectly generated command:

[...]
59 
60 01_hello_world/CMakeFiles/_arduino_lib_core.dir/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino/WInterrupts.c.o: 01_hello_world/CMakeFiles/_arduino_lib_core.dir/flags.make
61 01_hello_world/CMakeFiles/_arduino_lib_core.dir/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino/WInterrupts.c.o: /home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino/WInterrupts.c
62 	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/wilbrandt/projects/tracked_robot/arduino_firmware/Arduino-CMake-Toolchain/Examples_build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building C object 62 01_hello_world/CMakeFiles/_arduino_lib_core.dir/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino/WInterrupts.c.o"
63 	cd /home/wilbrandt/projects/tracked_robot/arduino_firmware/Arduino-CMake-Toolchain/Examples_build/01_hello_world && /home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc  -c -g -Os -w -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=2:10005+dfsg2-401
64  -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM  -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" -I/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) /home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino/WInterrupts.c -o CMakeFiles/_arduino_lib_core.dir/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/cores/arduino/WInterrupts.c.o
65 
[...]

(Notice the line break before the -DARDUINO_SAM_DUE flag). The ninja.rules file shows a similar error:

[...]
24 
25 rule CXX_COMPILER__hello_world
26   depfile = $DEP_FILE
27   deps = gcc
28   command = /home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++  -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=2:10005+dfsg2-401
29  -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM  -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON "-DUSB_MANUFACTURER=\"Arduino LLC\"" "-DUSB_PRODUCT=\"Arduino Due\"" -I/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam -I/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/ -I/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/ $DEFINES $INCLUDES $FLAGS -MD -MT $out -MF $DEP_FILE $in -o $out
30   description = Building CXX object $out
[...]

Suspected Error Source

After browsing through the toolchain files i found this message call. Uncommenting it already showed the same problem:

> cmake -D CMAKE_TOOLCHAIN_FILE=../Arduino-toolchain.cmake ../Examples
-- Found Arduino Platform: /home/wilbrandt/.arduino15/packages/arduino/hardware/avr/1.8.2
-- Found Arduino Platform: /home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12
-- Selected Arduino Board: Arduino Due (Programming Port) [sam.arduino_due_x_dbg]
ARDUINO_RULE_recipe.c.o.pattern:"/home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc" -c -g -Os -w -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD -mcpu=cortex-m3 -mthumb -DF_CPU=84000000L -DARDUINO=2:10005+dfsg2-401
 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM  -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON '-DUSB_MANUFACTURER="Arduino LLC"' '-DUSB_PRODUCT="Arduino Due"' "-I/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/system/libsam" "-I/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/CMSIS/Include/" "-I/home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12/system/CMSIS/Device/ATMEL/" {includes} "{source_file}" -o "{object_file}"
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detecting C compile features
-- Detecting C compile features - failed
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting CXX compile features
-- Detecting CXX compile features - failed
-- The ASM compiler identification is GNU
-- Found assembler: /home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wilbrandt/projects/tracked_robot/arduino_firmware/Arduino-CMake-Toolchain/Examples_build

This (and also testing the written CMAKE_C_COMPILE_OBJECT, which also has the newline) leads me to believe that the _resolve_build_rule_properties function doesn't handle newlines in its input correctly.

System

I am not quite sure which information is relevant to you, so i'll just post some system information here. I work on an ubuntu 18.04.4.

> cmake --version
cmake version 3.10.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

I use the current Arduino IDE with version 1.8.12.

Miscellaneous

As i don't know too much about low-level CMake witchery any help would be appreciated. Thank you for providing this solution, it seems to be very neatly integrated (once it works for me) and looks like exactly the solution i was looking for.

Arduino Nano 33 BLE: undefined reference to `main'

Many thanks for this great toolchain!
I've found a bug when compiling for Arduino Nano 33 BLE.
When linking any project (for example Blink) you get the error:
~/.arduino15/packages/arduino/hardware/mbed_nano/2.5.2/variants/ARDUINO_NANO33BLE/libs/libmbed.a(mbed_boot_gcc_arm.o): In function __wrap_main': mbed_boot_gcc_arm.c:(.text.__wrap_main+0x0): undefined reference to main'

I think the archives and objects are linked in the wrong order, since the main.cpp where the main function gets defined is compiled too.

Constants not defined during compilation

I am trying to compile for an avr.micro and to use the HID-Project library.

When I try to compile with this CMake file

cmake_minimum_required(VERSION 3.0.0)

set(CMAKE_TOOLCHAIN_FILE "/home/user/repositories/arduino/Arduino-CMake-Toolchain/Arduino-toolchain.cmake")

set(ARDUINO_INSTALL_PATH "/home/user/repositories/arduino/arduino-ide/build")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project (AH64MFDContorller CXX)

add_executable(AH64MFDContorller lnk/MFDController.cpp)

target_link_arduino_libraries(AH64MFDContorller PRIVATE HID HID-Project core)

set_target_properties(AH64MFDContorller PROPERTIES LINKER_LANGUAGE CXX)

target_enable_arduino_upload(AH64MFDContorller)

I get those errors

In file included from /home/user/Documents/Projects/arduino/AH64MFD/MFDController/lnk/MFDController.cpp:1:0:
/home/user/Documents/Projects/arduino/libraries/HID-Project/src/HID-Project.h:31:2: error: #error HID Project requires Arduino IDE 1.6.7 or greater. Please update your IDE.
 #error HID Project requires Arduino IDE 1.6.7 or greater. Please update your IDE.
  ^~~~~
/home/user/Documents/Projects/arduino/libraries/HID-Project/src/HID-Project.h:35:2: error: #error HID Project can only be used with an USB MCU.
 #error HID Project can only be used with an USB MCU.
  ^~~~~

However when I define them, I get warning about redefinitions.

Feedback

Hello.

Firstly, thank you for this amazing tool.

Secondly, I have just worked my way through getting this working and I would like to add a little feedback that will make the instructions easier for someone who is potentially inexperienced to follow:

  1. I think it would be worth explaining that the CMakeLists.txt from the respective examples should be moved to the root.
  2. I'm using CLion and I needed to add the following to the CMake options (the second -D was critical)

-D CMAKE_TOOLCHAIN_FILE=Arduino-toolchain.cmake -D SERIAL_PORT=COM9

Sketch (ino) support broken

Hi,

first of all, thanks for developing this project and trying and avoiding the Arduino "IDE".

I'm trying to compile the Sketch Blink.ino:

cd /tmp
mkdir act && cd act
cp -r /opt/arduino-1.8.13/examples/01.Basics/Blink/ .
cd Blink
cat <<EOF > CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(Blink CXX)
add_executable(blink Blink.ino)
target_link_arduino_libraries(blink PRIVATE core)
EOF
cd ..
mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/04-sources/arduino-cmake-toolchain/Arduino-toolchain.cmake -DARDUINO_BOARD="Arduino Uno [avr.uno]" ../Blink
make

Compilation suceeds but linking fails:

/tmp/ccJpGAAX.ltrans0.ltrans.o: In function `main':
/opt/arduino-1.8.13/hardware/arduino/avr/cores/arduino/main.cpp:43: undefined reference to `setup'
/opt/arduino-1.8.13/hardware/arduino/avr/cores/arduino/main.cpp:46: undefined reference to `loop'
collect2: error: ld returned 1 exit status

For easier reference, the CMakeLists.txt file is

cmake_minimum_required(VERSION 3.10)
project(Blink CXX)
add_executable(blink Blink.ino)
target_link_arduino_libraries(blink PRIVATE core)

In the case that I'm doing something wrong and that other users might do the same, it would be good to document how to compile sketches.

The workaround to rename Blink.ino to Blink.cpp may work here, I didn't try it, but I have another project, where Arduino-Cmake-Toolchain doesn't find the Arduino library when using the cpp extension.

Arduino-Cmake-Toolchain e745a9b (2020-06-16), Arduino 1.8.13.

Feature request: Sketch exceeds program storage space warning.

Arduino IDE provides the following error and blocks upload. This is very useful and a challenging issue to diagnose when upload takes place anyway.

Sketch uses 1311950 bytes (100%) of program storage space. Maximum is 1310720 bytes.
Global variables use 57732 bytes (17%) of dynamic memory, leaving 269948 bytes for local variables. Maximum is 327680 bytes.
Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.
text section exceeds available space in board
Error compiling for board ESP32 Dev Module.

undefined reference to `setup()'

Hi all!

I'm trying to setup toolchain. After a bunch of experiments I managed to compile the code, but linking phase is errored.

I'm developing a library and have an examples folder with some ino sketches.

But I have no luck of compiling them. I'm not even talking about developing a library (that's beyond fantasy).

Here is what I get:

[100%] Linking CXX executable Callee-ESP32.elf
lib_arduino_lib_core.a(main.cpp.o):(.literal._Z8loopTaskPv+0x8): undefined reference to `setup()'
lib_arduino_lib_core.a(main.cpp.o):(.literal._Z8loopTaskPv+0xc): undefined reference to `loop()'
lib_arduino_lib_core.a(main.cpp.o): In function `loopTask(void*)':
/Users/kostik/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/main.cpp:18: undefined reference to `setup()'
/Users/kostik/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/main.cpp:21: undefined reference to `loop()'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/Callee-ESP32.dir/build.make:87: Callee-ESP32.elf] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:593: CMakeFiles/Callee-ESP32.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:600: CMakeFiles/Callee-ESP32.dir/rule] Error 2
gmake: *** [Makefile:332: Callee-ESP32] Error 2

Here is related part of my CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(WampCaster CXX)
set(CMAKE_CXX_STANDARD 11)

# Adding all examples as executables for syntax highlighting and building
add_executable(Callee-ESP32 examples/Callee-ESP32/Callee-ESP32.ino)
set_target_properties(Callee-ESP32 PROPERTIES LINKER_LANGUAGE CXX)
target_link_arduino_libraries(Callee-ESP32 AUTO_PRIVATE)

In the board I enabled one of the ESP32 (I tried some other variants, same results):

set(ARDUINO_BOARD "DOIT ESP32 DEVKIT V1 [esp32.esp32doit-devkit-v1]") # DOIT ESP32 DEVKIT V1

Of course if I try to compile the same sketches with arduino-cli - everything works as expected:

> /usr/local/bin/arduino-cli compile -b esp32:esp32:esp32doit-devkit-v1 examples/Callee-ESP32/Callee-ESP32.ino
...
Used library       Version Path                                                                                          
WiFi               1.0     /Users/kostik/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi            
WampCaster         0.1.0   /Users/kostik/Projects/WampCaster                                                             
ArduinoJson        6.20.1  /Users/kostik/Projects/Arduino/libraries/ArduinoJson                                          
WebSockets_Generic 2.16.1  /Users/kostik/Projects/WebSockets_Generic                                                     
WiFiClientSecure   1.0     /Users/kostik/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFiClientSecure
Crypto             0.4.0   /Users/kostik/Projects/Arduino/libraries/Crypto                                               
base64             1.3.0   /Users/kostik/Projects/Arduino/libraries/base64                                               

Used platform Version Path                                                               
esp32:esp32   1.0.6   /Users/kostik/Library/Arduino15/packages/esp32/hardware/esp32/1.0.6

If someone knows what it can be or where to look - would love to hear! Thnx!

Get it working with teensyduino

Hello,

I'm trying to get this working with teensyduino install.
I'm using:

It almost works out of the box using release-1.1-dev branch, there is only a couple of minor issues, some of them are fixed by patching files installed by teensyduino, and one modification is needed on Arduino-CMake-Toolchain side (I made it only for Linux since I'm not able to test it for other platforms).

Arduino-CMake-Toolchain

I'll do a merge request, I've made a quick fix for Linux platform only that set an additional property (extra.time.local) that is used to define some symbols on teensy ld command line.

Arduino install modified by TeensyduinoInstaller

Teensyduino installer is not modifying the package_index_bundle.json file nor providing one, but arduino IDE correctly find the new boards.
However Arduino-CMake-Toolchain seems to only rely on information found on various json files, maybe the procedure to detect available platform need to be improved to be closest of what arduino IDE is doing...
Anyway, a way to get it working is to patch the package_index_bundle.json to add teensy information, bellow patch is working for me:

diff --git a/hardware/package_index_bundled.json b/hardware/package_index_bundled.json
index 82ac683..e95f3d5 100644
--- a/hardware/package_index_bundled.json
+++ b/hardware/package_index_bundled.json
@@ -214,6 +214,27 @@
           ]
         }
       ]
-    }
+    },
+      {
+          "name": "teensy",
+          "platforms": [
+              {
+                  "name": "Teensy AVR Boards",
+                  "architecture": "avr",
+                  "version": "1.6.23",
+                  "category": "Teensyduino",
+                  "boards": [
+                      {"name": "Teensy 3.2 / 3.1"}
+                  ],
+                  "toolsDependencies": [
+                      {
+                          "packager": "arduino",
+                          "name": "avr-gcc",
+                          "version": "7.3.0-atmel3.6.1-arduino5"
+                      }
+                  ]
+              }
+          ]
+      }
   ]
 }

An other issue is that platform.txt file provided by teensyduino installer declare some post.build hook:

recipe.hooks.postbuild.1.pattern="{compiler.path}stdout_redirect" "{build.path}/{build.project_name}.lst" "{compiler.path}{build.toolchain}{build.command.objdump}" -d -S -C "{build.path}/{build.project_name}.elf"
recipe.hooks.postbuild.2.pattern="{compiler.path}stdout_redirect" "{build.path}/{build.project_name}.sym" "{compiler.path}{build.toolchain}{build.command.objdump}" -t -C "{build.path}/{build.project_name}.elf"
recipe.hooks.postbuild.3.pattern="{compiler.path}teensy_post_compile" "-file={build.project_name}" "-path={build.path}" "-tools={compiler.path}" "-board={build.board}"

Hook number 1 and 2 need the elf to be produced, their are obviously postlink hook not, postbuild, again, it works correctly on arduino IDE, so maybe the official IDE is more permissive about the notion of postbuild vs postlink hook...
Those hooks are here to automatically start the tool to upload firmware to the target, so they are not necessary for now (at least for me), I've simply declared those hooks as postlink (those seems to not be handled yet by Arduino-CMake-Toolchain) and I can now build the examples.

Unable to compile examples: "The C Compiler [...] is not able to compile a simple test program"

I am currently unable to build your examples as described without modifying the Toolchain file.

Problem Description

I tried building your examples just as descrbed in the markdown file. After a first run, i set the board in BoardOptions.cmake to the arduino due (also tested with arduino uno). Re-running the cmake command leads to the following error:

> cmake -D CMAKE_TOOLCHAIN_FILE=../Arduino-toolchain.cmake ../Examples
-- Found Arduino Platform: /home/wilbrandt/.arduino15/packages/arduino/hardware/avr/1.8.2
-- Found Arduino Platform: /home/wilbrandt/.arduino15/packages/arduino/hardware/sam/1.6.12
-- Selected Arduino Board: Arduino Due (Programming Port) [sam.arduino_due_x_dbg]
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Check for working C compiler: /home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc
-- Check for working C compiler: /home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/home/wilbrandt/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/wilbrandt/projects/tracked_robot/arduino_firmware/Arduino-CMake-Toolchain/Examples_build/CMakeFiles/CMakeTmp
    
    Run Build Command:"/usr/bin/make" "cmTC_5a574/fast"
    /usr/bin/make -f CMakeFiles/cmTC_5a574.dir/build.make CMakeFiles/cmTC_5a574.dir/build
    make[1]: Entering directory '/home/wilbrandt/projects/tracked_robot/arduino_firmware/Arduino-CMake-Toolchain/Examples_build/CMakeFiles/CMakeTmp'
    CMakeFiles/cmTC_5a574.dir/build.make:67: *** missing separator.  Stop.
    make[1]: Leaving directory '/home/wilbrandt/projects/tracked_robot/arduino_firmware/Arduino-CMake-Toolchain/Examples_build/CMakeFiles/CMakeTmp'
    Makefile:126: recipe for target 'cmTC_5a574/fast' failed
    make: *** [cmTC_5a574/fast] Error 2
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)


-- Configuring incomplete, errors occurred!

Workaround

After some googling this seems to be a common issue when crosscompiling with cmake. I was able to work around this problem by bypassing the compiler tests completely, but this doesn't seem like the correct way to do this. My workaround was simply adding the two lines

SET (CMAKE_C_COMPILER_WORKS 1)
SET (CMAKE_CXX_COMPILER_WORKS 1)

to Arduino-toolchain.cmake.

System

I am not quite sure which information is relevant to you, so i'll just post some system information here. I work on an ubuntu 18.04.4.

> cmake --version
cmake version 3.10.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

I use the current Arduino IDE with version 1.8.12.

Conclusion

As this seems to be a common problem with cross-compiling, it would be nice to find a usable fix for this. As i don't have any experience cross-compiling with cmake, any help would be appreciated.

Esp32 tests fail

I found that support for ESP32 is broken (most likely due to changes on Espressif end).

I run unit tests for ESP32:

cmake ../Arduino-CMake-Toolchain/Tests/
ctest -R esp32.esp32 --verbose

Here's one of errors:

3:         Start   3: esp32.esp32
3: 
3: 3: Test command: /bin/sh "/home/michalkowalczyk/room-access/stasik/toolchain-test/Arduino-CMake-Toolchain/Tests/RunTestWrapper.sh" "/home/michalkowalczyk/room-access/stasik/toolchain-test/Test/test_results/esp32.esp32/esp32.esp32" "/usr/bin/cmake" "-D" "CMAKE_GENERATOR=Unix Makefiles" "-D" "ARDUINO_TOOLCHAIN_DIR=/home/michalkowalczyk/room-access/stasik/toolchain-test/Arduino-CMake-Toolchain" "-D" "ARDUINO_BUILD_ROOT_DIR=/home/michalkowalczyk/room-access/stasik/toolchain-test/Test/build/esp32.esp32" "-D" "ARDUINO_SYSTEM_ROOT_DIR=/home/michalkowalczyk/room-access/stasik/toolchain-test/Test/toolchain/esp32.esp32" "-D" "ARDUINO_RESULT_ROOT_DIR=/home/michalkowalczyk/room-access/stasik/toolchain-test/Test/test_results/esp32.esp32" "-D" "ARDUINO_BOARD_OPTIONS_FILE=" "-D" "ARDUINO_BOARD_ID=esp32.esp32" "-D" "ARDUINO_PKG_MGR_DL_CACHE=/home/michalkowalczyk/room-access/stasik/toolchain-test/Test/_pkg_mgr/downloads" "-D" "ARDUINO_SKIP_REGULAR_EXPRESSION=" "-P" "/home/michalkowalczyk/room-access/stasik/toolchain-test/Arduino-CMake-Toolchain/Tests/RunBoardTest.cmake"
3: 3: Test timeout computed to be: 1500
3: 3: COMMAND /usr/bin/cmake -G Unix Makefiles -D CMAKE_TOOLCHAIN_FILE=/home/michalkowalczyk/room-access/stasik/toolchain-test/Arduino-CMake-Toolchain/Arduino-toolchain.cmake -D ARDUINO_SYSTEM_FILE=/home/michalkowalczyk/room-access/stasik/toolchain-test/Test/toolchain/esp32.esp32/esp32.esp32/ArduinoSystem.cmake -D CMAKE_VERBOSE_MAKEFILE=TRUE /home/michalkowalczyk/room-access/stasik/toolchain-test/Arduino-CMake-Toolchain/Examples/01_hello_world WORKING_DIRECTORY /home/michalkowalczyk/room-access/stasik/toolchain-test/Test/build/esp32.esp32/esp32.esp32 OUTPUT_VARIABLE _configure_content ERROR_VARIABLE _configure_content RESULT_VARIABLE _result
3: 3: -- The CXX compiler identification is unknown
3: 3: -- Indexing Arduino libraries for the project
3: 3: CMake Error at CMakeLists.txt:3 (project):
3: 3:   The CMAKE_CXX_COMPILER:
3: 3: 
3: 3:     {runtime.tools.xtensa-esp32-elf-gcc.path}/bin/xtensa-esp32-elf-g++
3: 3: 
3: 3:   is not a full path and was not found in the PATH.
3: 3: 
3: 3:   Tell CMake where to find the compiler by setting either the environment
3: 3:   variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
3: 3:   to the compiler, or to the compiler name if it is in the PATH.
3: 3: 
3: 3: 
3: 3: -- Configuring incomplete, errors occurred!
3: 3: See also "/home/michalkowalczyk/room-access/stasik/toolchain-test/Test/build/esp32.esp32/esp32.esp32/CMakeFiles/CMakeOutput.log".
3: 3: See also "/home/michalkowalczyk/room-access/stasik/toolchain-test/Test/build/esp32.esp32/esp32.esp32/CMakeFiles/CMakeError.log".
3: 3: 
3: 3: CMake Error at /home/michalkowalczyk/room-access/stasik/toolchain-test/Arduino-CMake-Toolchain/Tests/RunBoardTest.cmake:201 (message):
3: 3:   Configure failed!!!
3: 3: 
3: 3: 
3:   3/118 Test   #3: esp32.esp32 ..............................***Failed    0.27 sec

It seems that recursive property resolution doesn't work.

Arduino Due upload failure: No device found on ...

As discussed at the end of #25, the arduino due currently suffers from a problem in the uploading stage (carrying this over to this issue for better overview, sorry for the long delay):

$ cmake --build . --target upload -- TARGET=hello_world SERIAL_PORT_FILE=ttyACM0          
[100%] Uploading
[  3%] Built target _arduino_lib_core_vobjects_
[ 90%] Built target _arduino_lib_core_cobjects_
[ 93%] Built target _arduino_lib_core
[100%] Built target hello_world
Send auto-baud
Set binary mode
No device found on ttyACM0
CMake Error at .scripts/upload.cmake:374 (message):
  *** upload failed!

This is caused by a missing 1200bps reset in this toolchain. A current workaround on linux systems is to use

stty -F /dev/ttyACM0 speed 1200 && cmake --build . --target upload -- TARGET=hello_world SERIAL_PORT_FILE=ttyACM0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.