queezythegreat / arduino-cmake

Arduino CMake Build system
644 stars 216 forks source link

Eclipse Project Does Not Get Board Specific Includes #49

Closed arunh closed 11 years ago

arunh commented 11 years ago

Eclipse version: Juno Cmake: 2.8.8 / 2.8.9

When generating an Eclipse project file (Ninja or Make), symbols from AVR files used directly do not appear to be resolved by the indexer. E.g.

include <avr/sleep.h>

SLEEP_MODE_IDLE //unresolved

include <avr/io.h>

OCR1A //unresolved

I think this is caused by the indexer not having the '-mmcu=atmega328p' option (as appropriate for board) and thus not defining the correct symbol '__AVR_ATmega328P__' and so not including the chip specific parts which define example such as above. E.g. io.h actually just includes the correct machine specific version based on define.

Best demonstration is to clone the project below and generate an Eclipse project: https://github.com/arunh/navlights

arunh commented 11 years ago

Adding the following to the CMakeLists.txt file will solve the problem, but is a board dependent option and an obvious duplication against the BOARD parameter:

add_definitions( -D__AVR_ATmega328P__ )
queezythegreat commented 11 years ago

Hi, that may be caused by the Eclipse generator. Every firmware target has the following compiler options:

-DF_CPU=<CPU_FREQUENCY>
-DARDUINO=<ARDUINO_VERSION_DEFINE>
-mmcu=<CPU_NAME>

And the following linker option:

-mmcu=<CPU_NAME>

It's preaty understandable why that define is not defined in the project, as you can have multiple targets in a single project, and each target can be for a specific CPU type.

So if you had two firmware images, one for the UNO the other for the Mega, then you would have conflicting defines in the project.

I'm not sure I can solve your dilema with that define. I would suggest manually adding that define as you wrote, as I cannot make that automatic without causing problems for projects that build images for multiple CPUs.

arunh commented 11 years ago

Hi, I agree with your conclusion. I have currently included the following in my CMakeList.txt - this makes sure the define is only set when a generator is run, but not for the firmware target.

set(ARDUINO_IO_DEFINE __AVR_ATmega328P__)

if (CMAKE_EXTRA_GENERATOR)
  message("-- Added preprocessor define for generator: ${ARDUINO_IO_DEFINE}")
  add_definitions( -D${ARDUINO_IO_DEFINE} )
endif()

Including this here more for information for anyone else who comes looking. If there is somewhere better to put it, please let me know.

And thanks for Arduino-CMake :)