blobmsg_json: prefer to link against libjson-c over libjson (the new library name...
[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 SET(SOURCES avl.c avl-cmp.c blob.c blobmsg.c uloop.c usock.c ustream.c ustream-fd.c vlist.c utils.c)
16
17 ADD_LIBRARY(ubox SHARED ${SOURCES})
18
19 SET(LIBS)
20 CHECK_FUNCTION_EXISTS(clock_gettime HAVE_GETTIME)
21 IF(NOT HAVE_GETTIME)
22         CHECK_LIBRARY_EXISTS(rt clock_gettime "" NEED_GETTIME)
23         IF(NEED_GETTIME)
24                 TARGET_LINK_LIBRARIES(ubox rt)
25         ENDIF()
26 ENDIF()
27
28 FILE(GLOB headers *.h)
29 INSTALL(FILES ${headers}
30         DESTINATION include/libubox
31 )
32 INSTALL(TARGETS ubox
33         LIBRARY DESTINATION lib
34 )
35
36 ADD_SUBDIRECTORY(lua)
37
38 find_library(json NAMES json-c json)
39 IF(EXISTS ${json})
40         ADD_LIBRARY(blobmsg_json SHARED blobmsg_json.c)
41         TARGET_LINK_LIBRARIES(blobmsg_json ubox ${json})
42
43         ADD_EXECUTABLE(jshn jshn.c)
44         TARGET_LINK_LIBRARIES(jshn ${json})
45
46         INSTALL(TARGETS blobmsg_json jshn
47                 LIBRARY DESTINATION lib
48                 RUNTIME DESTINATION bin
49         )
50
51         FILE(GLOB scripts sh/*.sh)
52         INSTALL(FILES ${scripts}
53                 DESTINATION share/libubox
54         )
55
56 ENDIF()