CMakeLists.txt 2.9 KB

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