blobmsg_example: fix output
[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
10 IF(APPLE)
11 INCLUDE_DIRECTORIES(/opt/local/include)
12 LINK_DIRECTORIES(/opt/local/lib)
13 ENDIF()
14
15 INCLUDE(FindPkgConfig)
16 PKG_CHECK_MODULES(JSONC json-c json)
17 IF(JSONC_FOUND)
18 ADD_DEFINITIONS(-DJSONC)
19 INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS})
20 ENDIF()
21
22 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)
23
24 ADD_LIBRARY(ubox SHARED ${SOURCES})
25 ADD_LIBRARY(ubox-static STATIC ${SOURCES})
26 SET_TARGET_PROPERTIES(ubox-static PROPERTIES OUTPUT_NAME ubox)
27
28 SET(LIBS)
29 CHECK_FUNCTION_EXISTS(clock_gettime HAVE_GETTIME)
30 IF(NOT HAVE_GETTIME)
31 CHECK_LIBRARY_EXISTS(rt clock_gettime "" NEED_GETTIME)
32 IF(NEED_GETTIME)
33 TARGET_LINK_LIBRARIES(ubox rt)
34 ENDIF()
35 ENDIF()
36
37 FILE(GLOB headers *.h)
38 INSTALL(FILES ${headers}
39 DESTINATION include/libubox
40 )
41 INSTALL(TARGETS ubox ubox-static
42 ARCHIVE DESTINATION lib
43 LIBRARY DESTINATION lib
44 )
45
46 ADD_SUBDIRECTORY(lua)
47
48 find_library(json NAMES json-c json)
49 IF(EXISTS ${json})
50 ADD_LIBRARY(blobmsg_json SHARED blobmsg_json.c)
51 TARGET_LINK_LIBRARIES(blobmsg_json ubox ${json})
52
53 ADD_EXECUTABLE(jshn jshn.c)
54 TARGET_LINK_LIBRARIES(jshn ${json})
55
56 ADD_LIBRARY(json_script SHARED json_script.c)
57 TARGET_LINK_LIBRARIES(json_script ubox)
58
59 INSTALL(TARGETS blobmsg_json jshn json_script
60 LIBRARY DESTINATION lib
61 RUNTIME DESTINATION bin
62 )
63
64 FILE(GLOB scripts sh/*.sh)
65 INSTALL(FILES ${scripts}
66 DESTINATION share/libubox
67 )
68
69 ENDIF()