CMakeLists.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. cmake_minimum_required(VERSION 3.5)
  2. PROJECT(netifd C)
  3. include(CheckCCompilerFlag)
  4. check_c_compiler_flag(-Wimplicit-fallthrough HAS_IMPLICIT_FALLTHROUGH)
  5. ADD_DEFINITIONS(-Wall -Werror)
  6. IF(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6)
  7. add_definitions(-Wextra -Werror=implicit-function-declaration)
  8. add_definitions(-Wformat -Werror=format-security -Werror=format-nonliteral)
  9. ENDIF()
  10. ADD_DEFINITIONS(-Os --std=gnu99 -Wmissing-declarations -Wno-unused-parameter -Wno-unused-but-set-parameter)
  11. IF(HAS_IMPLICIT_FALLTHROUGH)
  12. ADD_DEFINITIONS(-Wimplicit-fallthrough)
  13. ENDIF()
  14. SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  15. SET(SOURCES
  16. main.c utils.c system.c tunnel.c handler.c
  17. interface.c interface-ip.c interface-event.c
  18. iprule.c proto.c proto-static.c proto-shell.c
  19. config.c device.c bridge.c veth.c vlan.c alias.c
  20. macvlan.c ubus.c vlandev.c wireless.c
  21. extdev.c bonding.c)
  22. FIND_LIBRARY(uci NAMES uci)
  23. FIND_LIBRARY(ubox NAMES ubox)
  24. FIND_LIBRARY(ubus NAMES ubus)
  25. FIND_LIBRARY(json NAMES json-c json)
  26. FIND_LIBRARY(udebug NAMES udebug)
  27. FIND_LIBRARY(blobmsg_json NAMES blobmsg_json)
  28. SET(LIBS ${ubox} ${ubus} ${uci} ${json} ${blobmsg_json} ${udebug})
  29. FIND_PATH(ubox_include_dir libubox/usock.h)
  30. FIND_PATH(udebug_include_dir udebug.h)
  31. INCLUDE_DIRECTORIES(${ubox_include_dir})
  32. IF (NOT DEFINED LIBNL_LIBS)
  33. include(FindPkgConfig)
  34. pkg_search_module(LIBNL libnl-3.0 libnl-3 libnl nl-3 nl)
  35. IF (LIBNL_FOUND)
  36. include_directories(${LIBNL_INCLUDE_DIRS})
  37. SET(LIBNL_LIBS ${LIBNL_LIBRARIES})
  38. ENDIF()
  39. ENDIF()
  40. ADD_CUSTOM_COMMAND(
  41. OUTPUT ethtool-modes.h
  42. COMMAND ./make_ethtool_modes_h.sh ${CMAKE_C_COMPILER} > ./ethtool-modes.h
  43. DEPENDS ./make_ethtool_modes_h.sh
  44. )
  45. ADD_CUSTOM_TARGET(ethtool-modes-h DEPENDS ethtool-modes.h)
  46. IF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" AND NOT DUMMY_MODE)
  47. SET(SOURCES ${SOURCES} system-linux.c)
  48. SET(LIBS ${LIBS} ${LIBNL_LIBS})
  49. ELSE()
  50. ADD_DEFINITIONS(-DDUMMY_MODE=1)
  51. SET(SOURCES ${SOURCES} system-dummy.c)
  52. ENDIF()
  53. IF(DEBUG)
  54. ADD_DEFINITIONS(-DDEBUG -g3)
  55. IF(NO_OPTIMIZE)
  56. ADD_DEFINITIONS(-O0)
  57. ENDIF()
  58. ENDIF()
  59. ADD_EXECUTABLE(netifd ${SOURCES})
  60. TARGET_LINK_LIBRARIES(netifd ${LIBS})
  61. INSTALL(TARGETS netifd
  62. RUNTIME DESTINATION sbin
  63. )
  64. ADD_DEPENDENCIES(netifd ethtool-modes-h)