1

I'm trying to link a downloaded library called ArduinoJson to my project with CMake, but it seems that whenever i include the file it is missing, it will just ask for the next file its missing. I will end up with a lot of include lines which i think isnt the right way. I cant seem to find the correct syntax to include a libary in CMake

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.11)

SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_FLAGS "-DTESTING")

include_directories(
    /usr/share/arduino/libraries/ArduinoJson/include
    /usr/share/arduino/hardware/arduino/cores/arduino
    )


set(files
    DataHandler.h 
    DataHandler.cpp
    JSON.cpp 
    JSON.h 
    HAL_mock.cpp 
    HAL_mock.h 
    HAL_Protocol.h 
    lib/ArduinoJson/ArduinoJson.h
    )

# Locate GTest
find_package(GTest REQUIRED)

# Link runTests with what we want to test and the GTest library
add_executable(runTests DataHandlerTests.cpp JSONTests.cpp HALTests.cpp ${files})

target_link_libraries(runTests GTest::Main ArduinoJson)

The error I get

[ 14%] Building CXX object CMakeFiles/runTests.dir/JSONTests.cpp.o
In file included from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../Internals/../String.hpp:14:0,
                 from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../Internals/DynamicStringBuilder.hpp:11,
                 from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../Internals/JsonPrintable.hpp:12,
                 from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../JsonVariant.hpp:13,
                 from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../JsonBuffer.hpp:14,
                 from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/BlockJsonBuffer.hpp:10,
                 from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/DynamicJsonBuffer.hpp:10,
                 from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson.hpp:10,
                 from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson.h:8,
                 from /usr/share/arduino/libraries/ArduinoJson/ArduinoJson.h:8,
                 from /home/zizyx/Desktop/git-sensorNetwerk/sensor-network/gtest/JSON.h:6,
                 from /home/zizyx/Desktop/git-sensorNetwerk/sensor-network/gtest/JSONTests.cpp:5:
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:29:26: fatal error: avr/pgmspace.h: No such file or directory
compilation terminated.
CMakeFiles/runTests.dir/build.make:86: recipe for target 'CMakeFiles/runTests.dir/JSONTests.cpp.o' failed
make[2]: *** [CMakeFiles/runTests.dir/JSONTests.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/runTests.dir/all' failed
make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

I would like to add 2 maybe 3 lines which include all the libraries i need for my ArduinoJson library

Yoeri Kroon
  • 33
  • 1
  • 4
  • Seems like `/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:29:26: fatal error: avr/pgmspace.h: No such file or directory` is the problem. Check what pgmspace.h is ? – avrono Oct 27 '16 at 08:40
  • pgmspace.h is a file which is included by Wstring.h which is included by ArduinoJson.h and so on. I think that when i include pgmspace.h manually it will just say its missing another library which i then have to include manually. Isn't there a way to make this easier? – Yoeri Kroon Oct 27 '16 at 08:50
  • [This example](https://raw.githubusercontent.com/wisoltech/arduino-getting-started/master/CMakeLists.txt) of Arduino usage include much more directories for search headers. `Isn't there a way to make this easier?` - in CMake usual way is to create `FindXXX.cmake` CMake script which detects installation of package `XXX` and setup some CMake variables for use them in the project. You may download one of existed `FindAdruino.cmake` files, or create you own one. Using command `find_package(Adruino)` in the project will trigger the `FindAdruino.cmake` script execution. – Tsyvarev Oct 27 '16 at 09:43
  • @Tsyvarev , I want to unittest my Arduino code and not upload it. The example is usefull in some extend but it has too much overhead which I dont understand very well – Yoeri Kroon Oct 27 '16 at 10:23

0 Answers0