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