diff --git a/CMakeLists.txt b/CMakeLists.txt index 820ae631..d1316987 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,16 +19,41 @@ if(NOT COMPILE_SUPPORT) add_definitions(-DNO_COMPILE) endif() +find_library(libuci NAMES uci) +find_library(libubox NAMES ubox) +find_library(libubus NAMES ubus) +find_library(libblobmsg_json NAMES blobmsg_json) + +if(LINUX) + find_library(libnl_tiny NAMES nl-tiny) + + if(libnl_tiny AND libubox) + set(DEFAULT_NL_SUPPORT ON) + endif() +endif() + +if(libuci AND libubox) + set(DEFAULT_UCI_SUPPORT ON) +endif() + +if(libubus AND libblobmsg_json) + set(DEFAULT_UBUS_SUPPORT ON) +endif() + +if(libubox) + set(DEFAULT_ULOOP_SUPPORT ON) +endif() + option(DEBUG_SUPPORT "Debug plugin support" ON) option(FS_SUPPORT "Filesystem plugin support" ON) option(MATH_SUPPORT "Math plugin support" ON) -option(UBUS_SUPPORT "Ubus plugin support" ON) -option(UCI_SUPPORT "UCI plugin support" ON) -option(RTNL_SUPPORT "Route Netlink plugin support" ${LINUX}) -option(NL80211_SUPPORT "Wireless Netlink plugin support" ${LINUX}) +option(UBUS_SUPPORT "Ubus plugin support" ${DEFAULT_UBUS_SUPPORT}) +option(UCI_SUPPORT "UCI plugin support" ${DEFAULT_UCI_SUPPORT}) +option(RTNL_SUPPORT "Route Netlink plugin support" ${DEFAULT_NL_SUPPORT}) +option(NL80211_SUPPORT "Wireless Netlink plugin support" ${DEFAULT_NL_SUPPORT}) option(RESOLV_SUPPORT "NS resolve plugin support" ON) option(STRUCT_SUPPORT "Struct plugin support" ON) -option(ULOOP_SUPPORT "Uloop plugin support" ON) +option(ULOOP_SUPPORT "Uloop plugin support" ${DEFAULT_ULOOP_SUPPORT}) set(LIB_SEARCH_PATH "${CMAKE_INSTALL_PREFIX}/lib/ucode/*.so:${CMAKE_INSTALL_PREFIX}/share/ucode/*.uc:./*.so:./*.uc" CACHE STRING "Default library search path") string(REPLACE ":" "\", \"" LIB_SEARCH_DEFINE "${LIB_SEARCH_PATH}") @@ -95,11 +120,10 @@ if(DEBUG_SUPPORT) add_library(debug_lib MODULE lib/debug.c) set_target_properties(debug_lib PROPERTIES OUTPUT_NAME debug PREFIX "") target_link_options(debug_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) - find_library(ubox NAMES ubox) - if(ubox) + if(libubox) find_path(uloop_include_dir NAMES libubox/uloop.h) include_directories(${uloop_include_dir}) - target_link_libraries(debug_lib ${ubox} ${libucode}) + target_link_libraries(debug_lib ${libubox} ${libucode}) set_target_properties(debug_lib PROPERTIES COMPILE_DEFINITIONS HAVE_ULOOP) endif() endif() @@ -123,15 +147,13 @@ if(MATH_SUPPORT) endif() if(UBUS_SUPPORT) - find_library(ubus NAMES ubus) - find_library(blobmsg_json NAMES blobmsg_json) find_path(ubus_include_dir NAMES libubus.h) include_directories(${ubus_include_dir}) set(LIBRARIES ${LIBRARIES} ubus_lib) add_library(ubus_lib MODULE lib/ubus.c) set_target_properties(ubus_lib PROPERTIES OUTPUT_NAME ubus PREFIX "") target_link_options(ubus_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) - target_link_libraries(ubus_lib ${ubus} ${blobmsg_json}) + target_link_libraries(ubus_lib ${libubus} ${libblobmsg_json}) file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c" " #include int main() { return UBUS_STATUS_NO_MEMORY; } @@ -145,39 +167,33 @@ if(UBUS_SUPPORT) endif() if(UCI_SUPPORT) - find_library(uci NAMES uci) - find_library(ubox NAMES ubox) find_path(uci_include_dir uci.h) include_directories(${uci_include_dir}) set(LIBRARIES ${LIBRARIES} uci_lib) add_library(uci_lib MODULE lib/uci.c) set_target_properties(uci_lib PROPERTIES OUTPUT_NAME uci PREFIX "") target_link_options(uci_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) - target_link_libraries(uci_lib ${uci} ${ubox}) + target_link_libraries(uci_lib ${libuci} ${libubox}) endif() if(RTNL_SUPPORT) - find_library(nl NAMES nl-tiny) - find_library(ubox NAMES ubox) find_path(nl_include_dir NAMES netlink/msg.h PATH_SUFFIXES libnl-tiny) include_directories(${nl_include_dir}) set(LIBRARIES ${LIBRARIES} rtnl_lib) add_library(rtnl_lib MODULE lib/rtnl.c) set_target_properties(rtnl_lib PROPERTIES OUTPUT_NAME rtnl PREFIX "") target_link_options(rtnl_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) - target_link_libraries(rtnl_lib ${nl} ${ubox}) + target_link_libraries(rtnl_lib ${libnl_tiny} ${libubox}) endif() if(NL80211_SUPPORT) - find_library(nl NAMES nl-tiny) - find_library(ubox NAMES ubox) find_path(nl_include_dir NAMES netlink/msg.h PATH_SUFFIXES libnl-tiny) include_directories(${nl_include_dir}) set(LIBRARIES ${LIBRARIES} nl80211_lib) add_library(nl80211_lib MODULE lib/nl80211.c) set_target_properties(nl80211_lib PROPERTIES OUTPUT_NAME nl80211 PREFIX "") target_link_options(nl80211_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) - target_link_libraries(nl80211_lib ${nl} ${ubox}) + target_link_libraries(nl80211_lib ${libnl_tiny} ${libubox}) endif() if(RESOLV_SUPPORT) @@ -208,20 +224,19 @@ if(STRUCT_SUPPORT) endif() if(ULOOP_SUPPORT) - find_library(ubox NAMES ubox) find_path(uloop_include_dir NAMES libubox/uloop.h) include_directories(${uloop_include_dir}) set(LIBRARIES ${LIBRARIES} uloop_lib) add_library(uloop_lib MODULE lib/uloop.c) set_target_properties(uloop_lib PROPERTIES OUTPUT_NAME uloop PREFIX "") target_link_options(uloop_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) - set(CMAKE_REQUIRED_LIBRARIES ${ubox}) + set(CMAKE_REQUIRED_LIBRARIES ${libubox}) check_function_exists(uloop_timeout_remaining64 REMAINING64_FUNCTION_EXISTS) unset(CMAKE_REQUIRED_LIBRARIES) if(REMAINING64_FUNCTION_EXISTS) target_compile_definitions(uloop_lib PUBLIC HAVE_ULOOP_TIMEOUT_REMAINING64) endif() - target_link_libraries(uloop_lib ${ubox}) + target_link_libraries(uloop_lib ${libubox}) endif() if(UNIT_TESTING)