diff options
author | Jo-Philipp Wich <jo@mein.io> | 2023-10-09 17:43:30 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2023-10-10 16:08:03 +0200 |
commit | 6a01adca12b48c1992a568c97202389d414e3251 (patch) | |
tree | 252753cba44ecc957dbbcf381950d1294ebc1298 | |
parent | 8700665099c7d502c43af9e3abe55ba181495145 (diff) |
build: convert CMakeLists.txt into lowercase
Convert cmake directives into lowercase notation for better readability.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | CMakeLists.txt | 496 |
1 files changed, 248 insertions, 248 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c2aead..820ae63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,256 +2,256 @@ cmake_minimum_required(VERSION 3.13) include(CheckFunctionExists) include(CheckSymbolExists) -PROJECT(ucode C) -ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -ffunction-sections -fwrapv -D_GNU_SOURCE) - -IF(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6) - ADD_DEFINITIONS(-Wextra -Werror=implicit-function-declaration) - ADD_DEFINITIONS(-Wformat -Werror=format-security -Werror=format-nonliteral) -ENDIF() -ADD_DEFINITIONS(-Wmissing-declarations -Wno-error=unused-variable -Wno-unused-parameter) - -INCLUDE_DIRECTORIES(include) - -OPTION(COMPILE_SUPPORT "Support compilation from source" ON) - -IF(NOT COMPILE_SUPPORT) - ADD_DEFINITIONS(-DNO_COMPILE) -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(RESOLV_SUPPORT "NS resolve plugin support" ON) -OPTION(STRUCT_SUPPORT "Struct plugin support" ON) -OPTION(ULOOP_SUPPORT "Uloop plugin support" ON) - -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}") -ADD_DEFINITIONS(-DLIB_SEARCH_PATH="${LIB_SEARCH_DEFINE}") - -IF(APPLE) - SET(UCODE_MODULE_LINK_OPTIONS "LINKER:-undefined,dynamic_lookup") - ADD_DEFINITIONS(-DBIND_8_COMPAT) -ELSE() - SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,--gc-sections") -ENDIF() - -IF(DEBUG) - ADD_DEFINITIONS(-DDEBUG -g3 -O0) -ELSE() - ADD_DEFINITIONS(-DNDEBUG) -ENDIF() - -INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(JSONC REQUIRED json-c) -INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS}) - -SET(UCODE_SOURCES lexer.c lib.c vm.c chunk.c vallist.c compiler.c source.c types.c program.c platform.c) -ADD_LIBRARY(libucode SHARED ${UCODE_SOURCES}) -SET(SOVERSION 0 CACHE STRING "Override ucode library version") -SET_TARGET_PROPERTIES(libucode PROPERTIES OUTPUT_NAME ucode SOVERSION ${SOVERSION}) -TARGET_LINK_LIBRARIES(libucode ${JSONC_LINK_LIBRARIES}) - -SET(CLI_SOURCES main.c) -ADD_EXECUTABLE(ucode ${CLI_SOURCES}) -TARGET_LINK_LIBRARIES(ucode libucode ${JSONC_LINK_LIBRARIES}) - -CHECK_FUNCTION_EXISTS(dlopen DLOPEN_FUNCTION_EXISTS) -IF (NOT DLOPEN_FUNCTION_EXISTS) - TARGET_LINK_LIBRARIES(libucode dl) -ENDIF() - -CHECK_FUNCTION_EXISTS(fmod FMOD_FUNCTION_EXISTS) -IF (NOT FMOD_FUNCTION_EXISTS) - TARGET_LINK_LIBRARIES(libucode m) -ENDIF() - -SET(CMAKE_REQUIRED_INCLUDES ${JSONC_INCLUDE_DIRS}) -SET(CMAKE_REQUIRED_LIBRARIES ${JSONC_LINK_LIBRARIES}) -CHECK_SYMBOL_EXISTS(json_tokener_get_parse_end "json-c/json.h" HAVE_PARSE_END) -IF(HAVE_PARSE_END) - ADD_DEFINITIONS(-DHAVE_PARSE_END) -ENDIF() -CHECK_SYMBOL_EXISTS(json_object_new_array_ext "json-c/json.h" HAVE_ARRAY_EXT) -IF(HAVE_ARRAY_EXT) - ADD_DEFINITIONS(-DHAVE_ARRAY_EXT) -ENDIF() -CHECK_SYMBOL_EXISTS(json_object_new_uint64 "json-c/json.h" HAVE_JSON_UINT64) -IF(HAVE_JSON_UINT64) - ADD_DEFINITIONS(-DHAVE_JSON_UINT64) -ENDIF() -UNSET(CMAKE_REQUIRED_INCLUDES) -UNSET(CMAKE_REQUIRED_LIBRARIES) - -SET(LIBRARIES "") - -IF(DEBUG_SUPPORT) - SET(LIBRARIES ${LIBRARIES} debug_lib) - 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) - FIND_PATH(uloop_include_dir NAMES libubox/uloop.h) - INCLUDE_DIRECTORIES(${uloop_include_dir}) - TARGET_LINK_LIBRARIES(debug_lib ${ubox} ${libucode}) - SET_TARGET_PROPERTIES(debug_lib PROPERTIES COMPILE_DEFINITIONS HAVE_ULOOP) - ENDIF() -ENDIF() - -IF(FS_SUPPORT) - SET(LIBRARIES ${LIBRARIES} fs_lib) - ADD_LIBRARY(fs_lib MODULE lib/fs.c) - SET_TARGET_PROPERTIES(fs_lib PROPERTIES OUTPUT_NAME fs PREFIX "") - TARGET_LINK_OPTIONS(fs_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) -ENDIF() - -IF(MATH_SUPPORT) - SET(LIBRARIES ${LIBRARIES} math_lib) - ADD_LIBRARY(math_lib MODULE lib/math.c) - SET_TARGET_PROPERTIES(math_lib PROPERTIES OUTPUT_NAME math PREFIX "") - TARGET_LINK_OPTIONS(math_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) - CHECK_FUNCTION_EXISTS(ceil CEIL_FUNCTION_EXISTS) - IF (NOT CEIL_FUNCTION_EXISTS) - TARGET_LINK_LIBRARIES(math_lib m) - ENDIF() -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}) - FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c" " +project(ucode C) +add_definitions(-Os -Wall -Werror --std=gnu99 -ffunction-sections -fwrapv -D_GNU_SOURCE) + +if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6) + add_definitions(-Wextra -Werror=implicit-function-declaration) + add_definitions(-Wformat -Werror=format-security -Werror=format-nonliteral) +endif() +add_definitions(-Wmissing-declarations -Wno-error=unused-variable -Wno-unused-parameter) + +include_directories(include) + +option(COMPILE_SUPPORT "Support compilation from source" ON) + +if(NOT COMPILE_SUPPORT) + add_definitions(-DNO_COMPILE) +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(RESOLV_SUPPORT "NS resolve plugin support" ON) +option(STRUCT_SUPPORT "Struct plugin support" ON) +option(ULOOP_SUPPORT "Uloop plugin support" ON) + +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}") +add_definitions(-DLIB_SEARCH_PATH="${LIB_SEARCH_DEFINE}") + +if(APPLE) + set(UCODE_MODULE_LINK_OPTIONS "LINKER:-undefined,dynamic_lookup") + add_definitions(-DBIND_8_COMPAT) +else() + set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,--gc-sections") +endif() + +if(DEBUG) + add_definitions(-DDEBUG -g3 -O0) +else() + add_definitions(-DNDEBUG) +endif() + +include(FindPkgConfig) +pkg_check_modules(JSONC REQUIRED json-c) +include_directories(${JSONC_INCLUDE_DIRS}) + +set(UCODE_SOURCES lexer.c lib.c vm.c chunk.c vallist.c compiler.c source.c types.c program.c platform.c) +add_library(libucode SHARED ${UCODE_SOURCES}) +set(SOVERSION 0 CACHE STRING "Override ucode library version") +set_target_properties(libucode PROPERTIES OUTPUT_NAME ucode SOVERSION ${SOVERSION}) +target_link_libraries(libucode ${JSONC_LINK_LIBRARIES}) + +set(CLI_SOURCES main.c) +add_executable(ucode ${CLI_SOURCES}) +target_link_libraries(ucode libucode ${JSONC_LINK_LIBRARIES}) + +check_function_exists(dlopen DLOPEN_FUNCTION_EXISTS) +if(NOT DLOPEN_FUNCTION_EXISTS) + target_link_libraries(libucode dl) +endif() + +check_function_exists(fmod FMOD_FUNCTION_EXISTS) +if(NOT FMOD_FUNCTION_EXISTS) + target_link_libraries(libucode m) +endif() + +set(CMAKE_REQUIRED_INCLUDES ${JSONC_INCLUDE_DIRS}) +set(CMAKE_REQUIRED_LIBRARIES ${JSONC_LINK_LIBRARIES}) +check_symbol_exists(json_tokener_get_parse_end "json-c/json.h" HAVE_PARSE_END) +if(HAVE_PARSE_END) + add_definitions(-DHAVE_PARSE_END) +endif() +check_symbol_exists(json_object_new_array_ext "json-c/json.h" HAVE_ARRAY_EXT) +if(HAVE_ARRAY_EXT) + add_definitions(-DHAVE_ARRAY_EXT) +endif() +check_symbol_exists(json_object_new_uint64 "json-c/json.h" HAVE_JSON_UINT64) +if(HAVE_JSON_UINT64) + add_definitions(-DHAVE_JSON_UINT64) +endif() +unset(CMAKE_REQUIRED_INCLUDES) +unset(CMAKE_REQUIRED_LIBRARIES) + +set(LIBRARIES "") + +if(DEBUG_SUPPORT) + set(LIBRARIES ${LIBRARIES} debug_lib) + 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) + find_path(uloop_include_dir NAMES libubox/uloop.h) + include_directories(${uloop_include_dir}) + target_link_libraries(debug_lib ${ubox} ${libucode}) + set_target_properties(debug_lib PROPERTIES COMPILE_DEFINITIONS HAVE_ULOOP) + endif() +endif() + +if(FS_SUPPORT) + set(LIBRARIES ${LIBRARIES} fs_lib) + add_library(fs_lib MODULE lib/fs.c) + set_target_properties(fs_lib PROPERTIES OUTPUT_NAME fs PREFIX "") + target_link_options(fs_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) +endif() + +if(MATH_SUPPORT) + set(LIBRARIES ${LIBRARIES} math_lib) + add_library(math_lib MODULE lib/math.c) + set_target_properties(math_lib PROPERTIES OUTPUT_NAME math PREFIX "") + target_link_options(math_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) + check_function_exists(ceil CEIL_FUNCTION_EXISTS) + if(NOT CEIL_FUNCTION_EXISTS) + target_link_libraries(math_lib m) + endif() +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}) + file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c" " #include <libubus.h> int main() { return UBUS_STATUS_NO_MEMORY; } ") - TRY_COMPILE(HAVE_NEW_UBUS_STATUS_CODES + try_compile(HAVE_NEW_UBUS_STATUS_CODES ${CMAKE_BINARY_DIR} "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.c") - IF(HAVE_NEW_UBUS_STATUS_CODES) - ADD_DEFINITIONS(-DHAVE_NEW_UBUS_STATUS_CODES) - ENDIF() -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}) -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}) -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}) -ENDIF() - -IF(RESOLV_SUPPORT) - SET(LIBRARIES ${LIBRARIES} resolv_lib) - ADD_LIBRARY(resolv_lib MODULE lib/resolv.c) - SET_TARGET_PROPERTIES(resolv_lib PROPERTIES OUTPUT_NAME resolv PREFIX "") - TARGET_LINK_OPTIONS(resolv_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) - CHECK_FUNCTION_EXISTS(res_mkquery RES_MKQUERY_FUNCTION_EXISTS) - CHECK_FUNCTION_EXISTS(ns_initparse NS_INITARSE_FUNCTION_EXISTS) - CHECK_FUNCTION_EXISTS(clock_gettime CLOCK_GETTIME_FUNCTION_EXISTS) - IF (NOT RES_MKQUERY_FUNCTION_EXISTS OR NOT NS_INITARSE_FUNCTION_EXISTS) - TARGET_LINK_LIBRARIES(resolv_lib resolv) - ENDIF() - IF (NOT CLOCK_GETTIME_FUNCTION_EXISTS) - TARGET_LINK_LIBRARIES(resolv_lib rt) - ENDIF() -ENDIF() - -IF(STRUCT_SUPPORT) - SET(LIBRARIES ${LIBRARIES} struct_lib) - ADD_LIBRARY(struct_lib MODULE lib/struct.c) - SET_TARGET_PROPERTIES(struct_lib PROPERTIES OUTPUT_NAME struct PREFIX "") - TARGET_LINK_OPTIONS(struct_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) - CHECK_FUNCTION_EXISTS(frexp FREXP_FUNCTION_EXISTS) - IF (NOT FREXP_FUNCTION_EXISTS) - TARGET_LINK_LIBRARIES(struct_lib m) - ENDIF() -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}) - 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}) -ENDIF() - -IF(UNIT_TESTING) - ENABLE_TESTING() - ADD_DEFINITIONS(-DUNIT_TESTING) - ADD_SUBDIRECTORY(tests) - LIST(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure") - - IF(CMAKE_C_COMPILER_ID STREQUAL "Clang") - ADD_EXECUTABLE(ucode-san ${CLI_SOURCES} ${UCODE_SOURCES}) - SET_PROPERTY(TARGET ucode-san PROPERTY ENABLE_EXPORTS 1) - TARGET_LINK_LIBRARIES(ucode-san ${JSONC_LINK_LIBRARIES}) - TARGET_COMPILE_OPTIONS(ucode-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all) - TARGET_LINK_OPTIONS(ucode-san PRIVATE -fsanitize=undefined,address,leak) - ENDIF() -ENDIF() - -INSTALL(TARGETS ucode RUNTIME DESTINATION bin) -INSTALL(TARGETS libucode LIBRARY DESTINATION lib) -INSTALL(TARGETS ${LIBRARIES} LIBRARY DESTINATION lib/ucode) - -ADD_CUSTOM_TARGET(utpl ALL COMMAND ${CMAKE_COMMAND} -E create_symlink ucode utpl) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/utpl DESTINATION bin) - -IF(COMPILE_SUPPORT) - ADD_CUSTOM_TARGET(ucc ALL COMMAND ${CMAKE_COMMAND} -E create_symlink ucode ucc) - INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ucc DESTINATION bin) -ENDIF() - -FILE(GLOB UCODE_HEADERS "include/ucode/*.h") -INSTALL(FILES ${UCODE_HEADERS} DESTINATION include/ucode) - -ADD_SUBDIRECTORY(examples) + if(HAVE_NEW_UBUS_STATUS_CODES) + add_definitions(-DHAVE_NEW_UBUS_STATUS_CODES) + endif() +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}) +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}) +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}) +endif() + +if(RESOLV_SUPPORT) + set(LIBRARIES ${LIBRARIES} resolv_lib) + add_library(resolv_lib MODULE lib/resolv.c) + set_target_properties(resolv_lib PROPERTIES OUTPUT_NAME resolv PREFIX "") + target_link_options(resolv_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) + check_function_exists(res_mkquery RES_MKQUERY_FUNCTION_EXISTS) + check_function_exists(ns_initparse NS_INITARSE_FUNCTION_EXISTS) + check_function_exists(clock_gettime CLOCK_GETTIME_FUNCTION_EXISTS) + if(NOT RES_MKQUERY_FUNCTION_EXISTS OR NOT NS_INITARSE_FUNCTION_EXISTS) + target_link_libraries(resolv_lib resolv) + endif() + if(NOT CLOCK_GETTIME_FUNCTION_EXISTS) + target_link_libraries(resolv_lib rt) + endif() +endif() + +if(STRUCT_SUPPORT) + set(LIBRARIES ${LIBRARIES} struct_lib) + add_library(struct_lib MODULE lib/struct.c) + set_target_properties(struct_lib PROPERTIES OUTPUT_NAME struct PREFIX "") + target_link_options(struct_lib PRIVATE ${UCODE_MODULE_LINK_OPTIONS}) + check_function_exists(frexp FREXP_FUNCTION_EXISTS) + if(NOT FREXP_FUNCTION_EXISTS) + target_link_libraries(struct_lib m) + endif() +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}) + 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}) +endif() + +if(UNIT_TESTING) + enable_testing() + add_definitions(-DUNIT_TESTING) + add_subdirectory(tests) + list(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure") + + if(CMAKE_C_COMPILER_ID STREQUAL "Clang") + add_executable(ucode-san ${CLI_SOURCES} ${UCODE_SOURCES}) + set_property(TARGET ucode-san PROPERTY ENABLE_EXPORTS 1) + target_link_libraries(ucode-san ${JSONC_LINK_LIBRARIES}) + target_compile_options(ucode-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all) + target_link_options(ucode-san PRIVATE -fsanitize=undefined,address,leak) + endif() +endif() + +install(TARGETS ucode RUNTIME DESTINATION bin) +install(TARGETS libucode LIBRARY DESTINATION lib) +install(TARGETS ${LIBRARIES} LIBRARY DESTINATION lib/ucode) + +add_custom_target(utpl ALL COMMAND ${CMAKE_COMMAND} -E create_symlink ucode utpl) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/utpl DESTINATION bin) + +if(COMPILE_SUPPORT) + add_custom_target(ucc ALL COMMAND ${CMAKE_COMMAND} -E create_symlink ucode ucc) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ucc DESTINATION bin) +endif() + +file(GLOB UCODE_HEADERS "include/ucode/*.h") +install(FILES ${UCODE_HEADERS} DESTINATION include/ucode) + +add_subdirectory(examples) |