Arduino CMake problem with includes

I have just converted a more complex sketch to use CMake. It would seem that the header file is not included at the right time as the declarations are not found in scope. The Arduino IDE will include the header files at the top of the CPP file that is generated and then compile. This way all declarations are in scope. With CMake I don't get this. Any advise please?

In C/C++, you need to actually declare functions before calling them. The Arduino preprocessor lets you cheat and put functions wherever by automatically pushing a pile of declarations to the top of the file - if your CMake doesn't do this, you'll have to add in declarations yourself.

For example:

Arduino:

void setup() {}
void loop() { foo(); }
void foo() {}

This works even though foo is undeclared before loop() because Arduino pushes a void foo(); on top of everything.
Standard C/C++:

void foo(); // <-- important

void setup() {}
void loop() {foo();}
void foo() {}

Declarations need to come first.

Including header files at the top is your job. #include exists for a reason, after all. CMake will not, unless you tell it to, automatically add #include lines into your code.

I get what you are saying and I am used to doing it like that. I was under the impression the the CMake for Arduino code actually did just that ( the same as the Arduino IDE ). It would concat the .c, .pde, . cpp files and place the header files at the top of the whole lot.
Not a problem, then I know what to do to fix the problem.
I understand that there is a sketch converter underway - I wonder how this problem will be addressed?

I'm not too sure what the CMake build option actually does right now, but I always thought that the CMake system was supposed to be a way to avoid the limitations of the Arduino IDE (especially the includes), and allow a more C/C++ style development environment.

However, I'm a bad reference - I switched to Eclipse for AVR development about a year ago, and have only opened the IDE to test if my suggestions for the forum compile.

Marius

where did you find the CMake code?
It's not something that we have released therefore there is no support for it.. The original author is the best place where to ask.

m

On the playground under Development Tools/other there is reference to this link