diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-03-15 00:09:55 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-03-15 23:15:11 +0100 |
commit | ada15857b058e360a04392171813f50470a36db3 (patch) | |
tree | 28ac39e654c6a655f467afc4fbdd77e6def5b206 | |
parent | befbb6924ccc31df1dc82d1ad1e18f9baf11aa23 (diff) |
build: consolidate CMakeLists.txt and cover OS X deviations
- Add OS X specific linker flags
- Default disable Linux specific modules on OS X
- Simplify json-c discovery
- Fix uloop_timeout_remaining64() detection
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | CMakeLists.txt | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e7322c..c0ed3d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,12 +19,18 @@ IF(NOT COMPILE_SUPPORT) ADD_DEFINITIONS(-DNO_COMPILE) ENDIF() +IF(APPLE) + SET(NOT_APPLE OFF) +ELSE() + SET(NOT_APPLE ON) +ENDIF() + 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" ON) -OPTION(NL80211_SUPPORT "Wireless Netlink plugin support" ON) +OPTION(RTNL_SUPPORT "Route Netlink plugin support" ${NOT_APPLE}) +OPTION(NL80211_SUPPORT "Wireless Netlink plugin support" ${NOT_APPLE}) OPTION(RESOLV_SUPPORT "NS resolve plugin support" ON) OPTION(STRUCT_SUPPORT "Struct plugin support" ON) OPTION(ULOOP_SUPPORT "Uloop plugin support" ON) @@ -33,12 +39,13 @@ SET(LIB_SEARCH_PATH "${CMAKE_INSTALL_PREFIX}/lib/ucode/*.so:${CMAKE_INSTALL_PREF STRING(REPLACE ":" "\", \"" LIB_SEARCH_DEFINE "${LIB_SEARCH_PATH}") ADD_DEFINITIONS(-DLIB_SEARCH_PATH="${LIB_SEARCH_DEFINE}") -IF(NOT APPLE) +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() -FIND_LIBRARY(json NAMES json-c json) - IF(DEBUG) ADD_DEFINITIONS(-DDEBUG -g3 -O0) ELSE() @@ -46,21 +53,18 @@ ELSE() ENDIF() INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(JSONC json-c json) -IF(JSONC_FOUND) - ADD_DEFINITIONS(-DJSONC) - INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS}) -ENDIF() +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) 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 ${json}) +TARGET_LINK_LIBRARIES(libucode ${JSONC_LINK_LIBRARIES}) SET(CLI_SOURCES main.c) ADD_EXECUTABLE(ucode ${CLI_SOURCES}) -TARGET_LINK_LIBRARIES(ucode libucode ${json}) +TARGET_LINK_LIBRARIES(ucode libucode ${JSONC_LINK_LIBRARIES}) CHECK_FUNCTION_EXISTS(dlopen DLOPEN_FUNCTION_EXISTS) IF (NOT DLOPEN_FUNCTION_EXISTS) @@ -90,12 +94,14 @@ 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) @@ -110,6 +116,7 @@ IF(UBUS_SUPPORT) 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}) ENDIF() @@ -121,6 +128,7 @@ IF(UCI_SUPPORT) 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() @@ -131,6 +139,7 @@ IF(RTNL_SUPPORT) 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}) ENDIF() @@ -141,6 +150,7 @@ IF(NL80211_SUPPORT) 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}) ENDIF() @@ -148,6 +158,7 @@ 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(clock_gettime CLOCK_GETTIME_FUNCTION_EXISTS) IF (NOT RES_MKQUERY_FUNCTION_EXISTS) @@ -162,6 +173,7 @@ 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) @@ -175,7 +187,8 @@ IF(ULOOP_SUPPORT) SET(LIBRARIES ${LIBRARIES} uloop_lib) ADD_LIBRARY(uloop_lib MODULE lib/uloop.c) SET_TARGET_PROPERTIES(uloop_lib PROPERTIES OUTPUT_NAME uloop PREFIX "") - SET(CMAKE_REQUIRED_LIBRARIES ubox) + 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) @@ -193,7 +206,7 @@ IF(UNIT_TESTING) 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 ${json}) + 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() |