uloop: use clock_gettime with the monotonic clock instead of using gettimeofday()
[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
29 SET(CMAKE_INSTALL_PREFIX /usr)
30
31 FILE(GLOB headers *.h)
32 INSTALL(FILES ${headers}
33         DESTINATION include/libubox
34 )
35 INSTALL(TARGETS ubox
36         LIBRARY DESTINATION lib
37 )
38
39 ADD_SUBDIRECTORY(lua)
40
41 find_library(json json)
42 IF(EXISTS ${json})
43         ADD_LIBRARY(blobmsg_json SHARED blobmsg_json.c)
44         TARGET_LINK_LIBRARIES(blobmsg_json ubox json)
45
46         ADD_EXECUTABLE(jshn jshn.c)
47         TARGET_LINK_LIBRARIES(jshn json)
48
49         INSTALL(TARGETS blobmsg_json jshn
50                 LIBRARY DESTINATION lib
51                 RUNTIME DESTINATION bin
52         )
53
54         FILE(GLOB scripts sh/*.sh)
55         INSTALL(FILES ${scripts}
56                 DESTINATION share/libubox
57         )
58
59 ENDIF()