Pages: [1]   Go Down
Author Topic: Arduino CMake problem with includes  (Read 1314 times)
0 Members and 1 Guest are viewing this topic.
Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
 
Logged

Rather people think you to be a fool than you open your mouth and confirm it.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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++:
Code:
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.
Logged

Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Rather people think you to be a fool than you open your mouth and confirm it.

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Forum Administrator
Offline Offline
God Member
*****
Karma: 52
Posts: 646
I find plain exciting
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the playground under Development Tools/other there is reference to this link
https://github.com/queezythegreat/arduino-cmake

Logged

Rather people think you to be a fool than you open your mouth and confirm it.

Pages: [1]   Go Up
Jump to: