Skip to content

Commit a5c2e11

Browse files
committed
Cause the cmake include dirs to also have ${CMAKE_INSTALL_INCLUDEDIR}/json-c, so downstream packages that use cmake to link against json-c can choose whether to include headers as just e.g. #include <json_object.h>, if they care to do so.
Update the README to better explain this, and make a few other tweaks.
1 parent 2d2382d commit a5c2e11

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ install(TARGETS ${CMAKE_TARGETS}
503503
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
504504
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
505505
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
506-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
506+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/json-c
507507
)
508508

509509
install(EXPORT ${PROJECT_NAME}-targets

README.md

+31-7
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,29 @@
1616
JSON-C - A JSON implementation in C <a name="overview"></a>
1717
-----------------------------------
1818

19+
JSON-C implements a reference counting object model that allows you to easily
20+
construct JSON objects in C, output them as JSON formatted strings and parse
21+
JSON formatted strings back into the C representation of JSON objects.
22+
It aims to conform to [RFC 7159](https://tools.ietf.org/html/rfc7159).
23+
24+
Skip down to [Using json-c](#using)
25+
or check out the [API docs](https://json-c.github.io/json-c/),
26+
if you already have json-c installed and ready to use.
27+
28+
Home page for json-c: https://github.com/json-c/json-c/wiki
29+
1930
Build Status
2031
* [AppVeyor Build](https://ci.appveyor.com/project/hawicz/json-c) ![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/json-c/json-c?branch=master&svg=true)
2132
* [Travis Build](https://travis-ci.org/json-c/json-c) ![Travis Build Status](https://travis-ci.org/json-c/json-c.svg?branch=master)
2233

2334
Test Status
2435
* [Coveralls](https://coveralls.io/github/json-c/json-c?branch=master) [![Coverage Status](https://coveralls.io/repos/github/json-c/json-c/badge.svg?branch=master)](https://coveralls.io/github/json-c/json-c?branch=master)
2536

26-
JSON-C implements a reference counting object model that allows you to easily
27-
construct JSON objects in C, output them as JSON formatted strings and parse
28-
JSON formatted strings back into the C representation of JSON objects.
29-
It aims to conform to [RFC 7159](https://tools.ietf.org/html/rfc7159).
30-
3137
Building on Unix with `git`, `gcc` and `cmake` <a name="buildunix"></a>
3238
--------------------------------------------------
3339

34-
Home page for json-c: https://github.com/json-c/json-c/wiki
40+
If you already have json-c installed, see [Linking to `libjson-c`](#linking)
41+
for how to build and link your program against it.
3542

3643
### Prerequisites: <a name="installprereq"></a>
3744

@@ -220,14 +227,31 @@ CFLAGS += $(shell pkg-config --cflags json-c)
220227
LDFLAGS += $(shell pkg-config --libs json-c)
221228
```
222229

223-
Without `pkgconfig`, you would do something like this:
230+
Without `pkgconfig`, you might do something like this:
224231

225232
```make
226233
JSON_C_DIR=/path/to/json_c/install
227234
CFLAGS += -I$(JSON_C_DIR)/include/json-c
235+
# Or to use lines like: #include <json-c/json_object.h>
236+
#CFLAGS += -I$(JSON_C_DIR)/include
228237
LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c
229238
```
230239

240+
If your project uses cmake:
241+
242+
* Add to your CMakeLists.txt file:
243+
244+
```cmake
245+
find_package(json-c CONFIG)
246+
target_link_libraries(${PROJECT_NAME} PRIVATE json-c::json-c)
247+
```
248+
249+
* Then you might run in your project:
250+
251+
```sh
252+
cd build
253+
cmake -DCMAKE_PREFIX_PATH=/path/to/json_c/install/lib64/cmake ..
254+
```
231255

232256
Using json-c <a name="using">
233257
------------

0 commit comments

Comments
 (0)