eclipse / mraa

Linux Library for low speed IO Communication in C with bindings for C++, Python, Node.js & Java. Supports generic io platforms, as well as Intel Edison, Intel Joule, Raspberry Pi and many more.
http://mraa.io
MIT License
1.37k stars 614 forks source link

cmake uses the wrong include path for json library #799

Open skoehler opened 7 years ago

skoehler commented 7 years ago

On Arch Linux, Raspberry 2, cmake detects the json-c library's include folder as JSON-C_INCLUDE_DIR=/usr/include/json/ which leads to a rather confusing error

[  1%] Building C object src/CMakeFiles/mraa.dir/mraa.c.o
In file included from /usr/include/json/forwards.h:10:0,
                 from /usr/include/json/features.h:10,
                 from /usr/include/bits/libc-header-start.h:33,
                 from /usr/include/stdlib.h:25,
                 from /tmp/mraa-1.7.0/src/mraa.c:32:
/usr/include/json/config.h:9:10: fatal error: string: No such file or directory
 #include <string> //typedef String
          ^~~~~~~~
compilation terminated.

I had to override things with cmake -DJSON-C_INCLUDE_DIR=/usr/include/json-c/.

The problem is that /usr/include/json and /usr/include/json-c both contain a file called json.h which is used by your cmake scripts to find the right folder. The former belongs to a json c++ library. The latter is the json C library.

The cmake check could probably be improved by using json_c_version.h instead of json.h for detecting json-c.

alext-mkrs commented 7 years ago

Thanks for reporting!

alext-mkrs commented 6 years ago

Looking into this one, I think it can also be fixed by just removing json entry @Hbrinj added a while ago at this line: https://github.com/intel-iot-devkit/mraa/blob/master/cmake/modules/FindJSON-C.cmake#L6

@Hbrinj, could you please clarify why you've added that one?