jshn: add functionality to read big JSON
[project/libubox.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 INCLUDE(CheckLibraryExists)
3 INCLUDE(CheckFunctionExists)
4
5 PROJECT(ubox C)
6 ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
7
8 OPTION(BUILD_LUA "build Lua plugin" ON)
9 OPTION(BUILD_EXAMPLES "build examples" ON)
10
11 INCLUDE(FindPkgConfig)
12 PKG_SEARCH_MODULE(JSONC json-c)
13 IF(JSONC_FOUND)
14   ADD_DEFINITIONS(-DJSONC)
15   INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS})
16 ENDIF()
17
18 SET(SOURCES avl.c avl-cmp.c blob.c blobmsg.c uloop.c usock.c ustream.c ustream-fd.c vlist.c utils.c safe_list.c runqueue.c md5.c kvlist.c ulog.c base64.c)
19
20 ADD_LIBRARY(ubox SHARED ${SOURCES})
21 ADD_LIBRARY(ubox-static STATIC ${SOURCES})
22 SET_TARGET_PROPERTIES(ubox-static PROPERTIES OUTPUT_NAME ubox)
23
24 SET(LIBS)
25 CHECK_FUNCTION_EXISTS(clock_gettime HAVE_GETTIME)
26 IF(NOT HAVE_GETTIME)
27         CHECK_LIBRARY_EXISTS(rt clock_gettime "" NEED_GETTIME)
28         IF(NEED_GETTIME)
29                 TARGET_LINK_LIBRARIES(ubox rt)
30         ENDIF()
31 ENDIF()
32
33 FILE(GLOB headers *.h)
34 INSTALL(FILES ${headers}
35         DESTINATION include/libubox
36 )
37 INSTALL(TARGETS ubox ubox-static
38         ARCHIVE DESTINATION lib
39         LIBRARY DESTINATION lib
40 )
41
42 ADD_SUBDIRECTORY(lua)
43 ADD_SUBDIRECTORY(examples)
44
45 find_library(json NAMES json-c)
46 IF(EXISTS ${json})
47         ADD_LIBRARY(blobmsg_json SHARED blobmsg_json.c)
48         TARGET_LINK_LIBRARIES(blobmsg_json ubox ${json})
49
50         ADD_LIBRARY(blobmsg_json-static STATIC blobmsg_json.c)
51         SET_TARGET_PROPERTIES(blobmsg_json-static
52                               PROPERTIES OUTPUT_NAME blobmsg_json)
53
54         ADD_EXECUTABLE(jshn jshn.c)
55         TARGET_LINK_LIBRARIES(jshn blobmsg_json ${json})
56
57         ADD_LIBRARY(json_script SHARED json_script.c)
58         TARGET_LINK_LIBRARIES(json_script ubox)
59
60         INSTALL(TARGETS blobmsg_json blobmsg_json-static jshn json_script
61                 ARCHIVE DESTINATION lib
62                 LIBRARY DESTINATION lib
63                 RUNTIME DESTINATION bin
64         )
65
66         FILE(GLOB scripts sh/*.sh)
67         INSTALL(FILES ${scripts}
68                 DESTINATION share/libubox
69         )
70
71 ENDIF()