jedisct1 / libhydrogen

A lightweight, secure, easy-to-use crypto library suitable for constrained environments.
https://libhydrogen.org
Other
631 stars 94 forks source link

cmake: Add arduino cross-compiling and package generation (`hydrogen-crypto.zip`) #54

Closed spinda closed 5 years ago

spinda commented 5 years ago

Arduino/Cross-Compiling:

Add a hydrogen-arduino-package target which generates hydrogen-crypto.zip for inclusion into Arduino Sketch projects.

Add a toolchain file for Arduino/AVR. Passing -DCMAKE_TOOLCHAIN_FILE=cmake/arduino-avr-toolchain.cmake to the CMake command line configures cross-compilation for Arduino. A target device identifier can be specified via -DARDUINO_AVR_TARGET_DEVICE=... (default: atmega328p), which configures -mmcu=... and enables the appropriate HYDRO_TARGET_DEVICE_* C preprocessor flag (e.g., HYDRO_TARGET_DEVICE_ATMEGA328). The path to the Arduino SDK home directory can be specified via -DARDUINO_AVR_SDK_DIR=...; if not set, the toolchain file checks for the ARDUINO_SDK_PATH environment variable, and then guesses a few locations based on the host OS (e.g., /Applications/Arduino.app/Contents/Java for macOS).

I plan on writing a toolchain file for cross-compiling to WASM as well.

CMake Tweaks for Maintainability:

Stick the project files list and compile options up at the top, as those are only bits most people would need to edit. Move the implementation details down below. For readability's sake, switch the project files list to use relative paths and then convert them to absolute at generation time.

Developer-facing settings are now prefixed with HYDROGEN_*, e.g., HYDROGEN_TARGET_ARCH, to avoid potential clashes when libhydrogen is built as part of a larger project.

jedisct1 commented 5 years ago

This is very nice, thank you!