esp8266-cmake icon indicating copy to clipboard operation
esp8266-cmake copied to clipboard

More detailed instructions

Open patrickelectric opened this issue 8 years ago • 6 comments

Hello, it's possible to update the doc to make more friendly to new users ? I don't know if the problem is I that cannot make the compilation work or the project. Best regards.

patrickelectric avatar Jan 29 '17 01:01 patrickelectric

I would like to know more about this project too! It'll be great if @rpoisel can make this more documented

SuperMarcus avatar Feb 15 '17 05:02 SuperMarcus

This almost made my eyes bleed, but I made it work after hacking at it for the whole evening

here is the rough outline: (some of these steps might be redundant... but it's an ugly hack and it works. I don't know how to do this properly b/c CMake fights me at every step)

  • git clone this repo recursively

  • clone the Arduino ESP somewhere else https://github.com/esp8266/Arduino/

  • in the Arduino directory run build.py (it's under Arduino/tools)

  • add the compiler path to your PATH this will be something like 'Arduino/tools/xtensa-lx106-elf/bin/' it'll have all your GNU toolchain stuff with an xtensa-lx106-elf in the front: xtensa-lx106-elf-g++ and xtensa-lx106-elf-objcopy etc. (there is also Arduino/tools/xtensa-lx106-elf/xtensa-lx106-elf/bin/ ... but I don't know what that is really. It seems to be an x86 toolchain)

  • next are the horrible parts: There is a variable that tells CMake where the Arduino directory is: you can see it all over esp8266-cmake/CMakeLists.txt it's ARDUINO_ESP8266_DIR something about the CMake magic make it so that ccmake and KDevelop just won't show it to me. So I had to run cmake from the command line ie something like

cd esp8266-cmake
cmake -DARDUINO_ESP8266_DIR=path-to-arduino-directory/Arduino/ .

okay, but before you do that, there is more to fix! CMake is really dumb and will repeatedly try to using your system compiler (/usr/bin/cc /usr/bin/c++) I wasn't able to make it stop being dumb, so I forced it to use the xtensa tools at the top of esp8266-cmake/CMakeLists.txt I now have:

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_FORCE_C_COMPILER xtensa-lx106-elf-gcc GNU)
set(CMAKE_FORCE_CXX_COMPILER xtensa-lx106-elf-g++ GNU)

project(ArduinoBuild VERSION 0.9.0 LANGUAGES C CXX ASM)
[...]

oh but we're not finished! the last step is you need to go to esp8266-cmake/arduino/CMakeLists.txt here there is a line:

install(DIRECTORY cmake/ DESTINATION cmake FILES_MATCHING PATTERN "toolchain.*.cmake")

this is actually what's was supposed to switch CMake to use the correct toolchain from the beginning, but for some reason it doesn't work. Nevertheless it's doing someother stuff that you need, so you need to change that line to be

include("cmake/toolchain.ESP8266.cmake")

Now you can run

cd esp8266-cmake
cmake -DARDUINO_ESP8266_DIR=path-to-arduino-directory/Arduino/ .
make

and you should get your libarduino.a

tomorrow I might actually try to link it to a program like in this example: https://github.com/rpoisel/esp8266-arduino-oled-mqtt

but this is such a hack.. that I'm really tempted to drop it. The real benefit would be clean integration with KDevelop (and probably CLion) - but it might not be worth it b/c it's such a mess

if anyone can clean this up so it's usable, please let me know. I feel like @rpoisel has done 99% of the work here and someone with a bit more CMake knowledge could fix this in no-time

kxygk avatar Mar 28 '17 17:03 kxygk

@geokon-gh, you wrote add the compiler path to your PATH. You meant that we need to copy all files from this folder Arduino/tools/xtensa-lx106-elf/bin/ to the esp8266-cmake folder. Right?

o1eksiy avatar Apr 07 '17 17:04 o1eksiy

@o1eksiy no no. The PATH variable is a Linux variable that tells the system when to look for executables. What you're saying will work (though it's messy) but normally you just do PATH=$PATH:path-to-toolchain-and-stuff/xtensa-lx106-elf/bin/ in your .bashrc you may need an export PATH

just look up "adding directories to your PATH variable on Linux" or something to that effect

kxygk avatar Apr 10 '17 04:04 kxygk

@geokon-gh, thanks for the respond! On the last step cmake -DARDUINO_ESP8266_DIR=/opt/arduino-1.6.8 . I got

CMake Error at CMakeLists.txt:5 (project):
  VERSION not allowed unless CMP0048 is set to NEW
-- Configuring incomplete, errors occurred!

As I understood I should to use arduino 0.9.0, right?

o1eksiy avatar Apr 10 '17 09:04 o1eksiy

... I didn't have this issue Look at line 5 of CMakeLists.txt .. see what's triggering it. Maybe you can remove the VERSION line? Look up CMP0048 .. maybe it'll give you some clues?

I didn't mean to provide an install tutorial or something. Just a rough guideline. This repository isn't ready for general use in it's current form and it seems to have been sorta abandoned by it's original author. @rpoisel uses it in his other projects. Look at his repositories that start with "esp8266-". They usually depend on this library, so they may work more "out of the box". Just recursively clone them and see if it works

kxygk avatar Apr 11 '17 11:04 kxygk