a9183756-gh / Arduino-CMake-Toolchain

CMake toolchain for all Arduino compatible boards
MIT License
137 stars 40 forks source link

Constants not defined during compilation #66

Open FalcoGer opened 7 months ago

FalcoGer commented 7 months ago

I am trying to compile for an avr.micro and to use the HID-Project library.

When I try to compile with this CMake file

cmake_minimum_required(VERSION 3.0.0)

set(CMAKE_TOOLCHAIN_FILE "/home/user/repositories/arduino/Arduino-CMake-Toolchain/Arduino-toolchain.cmake")

set(ARDUINO_INSTALL_PATH "/home/user/repositories/arduino/arduino-ide/build")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project (AH64MFDContorller CXX)

add_executable(AH64MFDContorller lnk/MFDController.cpp)

target_link_arduino_libraries(AH64MFDContorller PRIVATE HID HID-Project core)

set_target_properties(AH64MFDContorller PROPERTIES LINKER_LANGUAGE CXX)

target_enable_arduino_upload(AH64MFDContorller)

I get those errors

In file included from /home/user/Documents/Projects/arduino/AH64MFD/MFDController/lnk/MFDController.cpp:1:0:
/home/user/Documents/Projects/arduino/libraries/HID-Project/src/HID-Project.h:31:2: error: #error HID Project requires Arduino IDE 1.6.7 or greater. Please update your IDE.
 #error HID Project requires Arduino IDE 1.6.7 or greater. Please update your IDE.
  ^~~~~
/home/user/Documents/Projects/arduino/libraries/HID-Project/src/HID-Project.h:35:2: error: #error HID Project can only be used with an USB MCU.
 #error HID Project can only be used with an USB MCU.
  ^~~~~

However when I define them, I get warning about redefinitions.

technyon commented 7 months ago

A few points:

FalcoGer commented 7 months ago

I'm using Arduino IDE 1.8.20 AH64 is an attack helicopter. I'm trying to make an MFD game controller for it to use in DCS World (A flight sim) Thanks. I fixed the typo, but that wasn't the actual problem.

I am using this CMake file and it seems to work. However without setting those compile definitions, it will error out (see above).

cmake_minimum_required(VERSION 3.0.0)

add_compile_definitions(ARDUINO=10820)
add_compile_definitions(USBCON=1)

set(CMAKE_TOOLCHAIN_FILE "/home/user/repositories/arduino/Arduino-CMake-Toolchain/Arduino-toolchain.cmake")

set(ARDUINO_INSTALL_PATH "/home/user/repositories/arduino/arduino-ide/build")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project (AH64MFDController CXX)

add_executable(AH64MFDController lnk/MFDController.cpp)

target_link_arduino_libraries(AH64MFDController PRIVATE HID HID-Project core)

set_target_properties(AH64MFDController PROPERTIES LINKER_LANGUAGE CXX)

target_enable_arduino_upload(AH64MFDController)

My project directory structure is as such:

../AH64MFD
   \- MFDController.ino
   \- CMakeLists.txt
   \- /build
       \- Whatever cmake makes
   \- /lnk
       \- MFDController.cpp     -> ../MFDController.ino
       \- compile_commands.json -> ../build/compile_commands.json
technyon commented 7 months ago

Sorry I was confused about the AH64 :D.

The question is what's your target board, what hardware are you planning to run this on? I was getting at if it has USB HID functionality, but if settings those constants work, I guess yes.

FalcoGer commented 7 months ago

I'm using an arduino pro micro. Flashing with the arduino ide works just fine. I selected avr.micro.

I actually just got done debugging and testing the thing on a breadboard and it works fine, even in the flight sim. So it definitely has HID capability.

technyon commented 7 months ago

Hi,

I could replicate the issue, I'll see what I can do,

technyon commented 7 months ago

I get compilation errors like

AH64MFD-Arduino/lnk/MFDController.cpp:164:41: error: 'PIN_A0' was not declared in this scope

Where are those definitions supposed to come from?

technyon commented 7 months ago

I've added setting the ARDUINO symbol to the toolchain, it's one error less. Not sure how to get the USBCON symbol, it would need to come from the board definition.

FalcoGer commented 7 months ago

Strange. it compiles fine for me. I run cmake-gui and I have to configure 3 times before all the errors disappear and then I hit generate. I leave the programmer blank. Though flashing is another issue.

Honestly, I just want to use nvim to write my code. I don't mind compiling and uploading with the arduino thing. But that IDE is a joke.

Edit: Fixed flashing. Had to touch the serial interface first. Would be neat if that were done automagically though.

technyon commented 7 months ago

The Arduino IDE only helps you installing the SDK files, besides that it's just a text editor. I went for cmake because it's a powerful build system, and it allows me to use CLion instead of the Arduino IDE.

So your issue is fixed now?

BTW, you can use my fork which includes PRs not merged here, and a few other fixes.

FalcoGer commented 7 months ago

I am using your fork. And no, it seems it defines `ARDUINO=10000´ and it complains about the version being wrong. I still have to re-define it.

technyon commented 7 months ago

I'm a but confused, did you try with my latest changes? For me it did define a number that was bigger than the required minimum version, so I could compile without redefining it.

FalcoGer commented 7 months ago

When I look at compile_commands.json, then -DARDUINO=10000