3bb02305fcdaba9de8d945d209189b49029af747
[project/uqmi.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2
3 PROJECT(uqmi C)
4
5 OPTION(BUILD_STATIC OFF)
6
7 ADD_DEFINITIONS(-Os -ggdb -Wall -Werror --std=gnu99 -Wmissing-declarations -Wno-enum-conversion)
8
9 SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
10
11 SET(SOURCES main.c dev.c commands.c qmi-message.c)
12
13 FIND_PATH(ubox_include_dir libubox/usock.h)
14 FIND_PATH(blobmsg_json_include_dir libubox/blobmsg_json.h)
15 FIND_PATH(json_include_dir json-c/json.h json/json.h json.h)
16 INCLUDE_DIRECTORIES(${ubox_include_dir} ${blobmsg_json_include_dir} ${json_include_dir})
17
18 IF(BUILD_STATIC)
19 FIND_LIBRARY(json_library NAMES libjson.a libjson-c.a)
20 FIND_LIBRARY(blobmsg_json_library NAMES libblobmsg_json.a)
21 FIND_LIBRARY(ubox_library NAMES libubox.a)
22 ELSE(BUILD_STATIC)
23 FIND_LIBRARY(json_library NAMES json-c json)
24 FIND_LIBRARY(blobmsg_json_library NAMES blobmsg_json)
25 FIND_LIBRARY(ubox_library NAMES ubox)
26 ENDIF(BUILD_STATIC)
27
28 SET(LIBS ${ubox_library} ${blobmsg_json_library} ${json_library})
29
30 IF(DEBUG_PACKET)
31 ADD_DEFINITIONS(-DDEBUG_PACKET)
32 ENDIF()
33
34 IF(DEBUG)
35 ADD_DEFINITIONS(-DDEBUG -g3)
36 ENDIF()
37
38 SET(service_headers)
39 SET(service_sources)
40 FOREACH(service ctl dms nas pds wds wms wda)
41 ADD_CUSTOM_COMMAND(
42 OUTPUT ${CMAKE_SOURCE_DIR}/qmi-message-${service}.h
43 COMMAND ${CMAKE_SOURCE_DIR}/data/gen-header.pl ${service}_ ${CMAKE_SOURCE_DIR}/data/qmi-service-${service}.json > ${CMAKE_SOURCE_DIR}/qmi-message-${service}.h
44 DEPENDS ${CMAKE_SOURCE_DIR}/data/gen-header.pl ${CMAKE_SOURCE_DIR}/data/qmi-service-${service}.json ${CMAKE_SOURCE_DIR}/data/gen-common.pm
45 )
46 SET(service_headers ${service_headers} qmi-message-${service}.h)
47 ADD_CUSTOM_COMMAND(
48 OUTPUT ${CMAKE_SOURCE_DIR}/qmi-message-${service}.c
49 COMMAND ${CMAKE_SOURCE_DIR}/data/gen-code.pl ${service}_ ${CMAKE_SOURCE_DIR}/data/qmi-service-${service}.json > ${CMAKE_SOURCE_DIR}/qmi-message-${service}.c
50 DEPENDS ${CMAKE_SOURCE_DIR}/data/gen-code.pl ${CMAKE_SOURCE_DIR}/data/qmi-service-${service}.json ${CMAKE_SOURCE_DIR}/data/gen-common.pm
51 )
52 SET(service_sources ${service_sources} qmi-message-${service}.c)
53 set_property(SOURCE qmi-message-${service}.c PROPERTY COMPILE_FLAGS "-Wno-unused")
54 ENDFOREACH()
55
56 ADD_CUSTOM_COMMAND(
57 OUTPUT ${CMAKE_SOURCE_DIR}/qmi-errors.c
58 COMMAND ${CMAKE_SOURCE_DIR}/data/gen-error-list.pl ${CMAKE_SOURCE_DIR}/qmi-errors.h > ${CMAKE_SOURCE_DIR}/qmi-errors.c
59 DEPENDS ${CMAKE_SOURCE_DIR}/data/gen-error-list.pl ${CMAKE_SOURCE_DIR}/qmi-errors.h
60 )
61 ADD_CUSTOM_TARGET(gen-errors DEPENDS qmi-errors.c)
62 ADD_CUSTOM_TARGET(gen-headers DEPENDS ${service_headers})
63
64 ADD_EXECUTABLE(uqmi ${SOURCES} ${service_sources})
65 ADD_DEPENDENCIES(uqmi gen-headers gen-errors)
66
67 TARGET_LINK_LIBRARIES(uqmi ${LIBS})
68
69 INSTALL(TARGETS uqmi
70 RUNTIME DESTINATION sbin
71 )