Closed JonasProgrammer closed 7 years ago
Well, I never used the sketch functionality, but from peeking at how it's implemented, your SKETCH parameter should be the directory containing the .ino file, rather than the file itself. Using this approach, generating works for me.
@MrPointer As you refractored that stuff, could you have a look at this please? Using the directory generating works, but the include statement for Arduino.h is generated only after the setup function, not before, thus breaking the build due to undefined variable names etc.
As someone suggested (not sure if it was you) it is actually fixed if I change the SKECTH
from
SKETCH "${CMAKE_CURRENT_SOURCE_DIR}/myproject/Sketch.ino"
to
SKETCH "${CMAKE_CURRENT_SOURCE_DIR}/myproject"
Still a bit weird it worked with the extension in the first place.
Yep, it was me. As stated, this suggestion was based soley on looking at the underlying cmake script. @MrPointer reworked the sketch part there on the 1.6 feature branch, so there might have been changes there. As it worked with the full path before, I'm still not sure whether we should take this as a bug or a breaking change (which wouldn't be too bad considering we have no official releases atm).
By the way, did you #include
No, I did not include #include <Arduino.h>
explicitly. But I did include #include <SoftwareSerial.h>
, which implicitly does #include <Arduino.h>
.
Just for the sake of testing I just ran both scenarios (implicit and explicit includes) and both worked fine with the lastest commit on this repo and arduino sdk1.8
@Souler Does it mean that it builds successfully now both when using the directory path and the file path? Or did you test it just for the directory path approach?
At least from my testing, the file path solution is broken whilst the directory approach works. And for him apparently only the directory works as well.
The explicit/implicit stuff seems to be another bug, where sketches can't be compiled after CMake generation due to the setup() function being defined before the Arduino.h-include. With "most" sketches that include headers other than Arduino.h anyways, this shouldn't be a problem though, as their includes are properly output to the top.
Have a look at this gist which was generated from the official Blink sketch (https://www.arduino.cc/en/Tutorial/Blink): https://gist.github.com/JonasProgrammer/04e1901d8658337fec7341d1413a623b
@MrPointer When setting SKETCH
to the directory where the the .ino
file resides, it works fine. Setting SKETCH
to the .ino
file path itself, fails.
@Souler I think I managed to fix this issue by forcing CMake to work on the directory, even when an explicit file is given. This is possible since the generate_arduino_sketch function finds all existing .ino or .pde files in that directory and then generates them as sketch sources.
Please have a look at f04faf8124e2bc6000a8c2a900f1d4786c5e7ef9 and tell me if it has worked for you so I would merge it further.
It worked fine, just in case I did a diff of both outputs (both using both directory and sketch).
64c64
< -- SKETCH_SOURCES: /home/barbosa/projs/project/firmware/src//Sketch.ino
---
> -- SKETCH_SOURCES: /home/barbosa/projs/project/firmware/src/Sketch.ino
121c121
< [ 95%] Building CXX object CMakeFiles/project.dir/project_Sketch.ino.cpp.obj
---
> [ 95%] Building CXX object CMakeFiles/project.dir/project_src.cpp.obj
@Souler Merging fix into master. See #9 . Thank you for finding this bug!
[copy of https://github.com/JonasProgrammer/arduino-cmake/issues/7 by @Souler]
After the latest changes(e97627543505ecdc9247be595490a03b9e178028), cmake build broke (at least for me). Also, this same config works fine on version 144eccc08513026d881cb55023e0c343e7e9bc5b
CMakeLists.txt
CMake output