• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/ucode/CMakeLists.txt

  1 cmake_minimum_required(VERSION 3.13)
  2 include(CheckFunctionExists)
  3 include(CheckSymbolExists)
  4 
  5 PROJECT(ucode C)
  6 ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -ffunction-sections -fwrapv -D_GNU_SOURCE)
  7 
  8 IF(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6)
  9         ADD_DEFINITIONS(-Wextra -Werror=implicit-function-declaration)
 10         ADD_DEFINITIONS(-Wformat -Werror=format-security -Werror=format-nonliteral)
 11 ENDIF()
 12 ADD_DEFINITIONS(-Wmissing-declarations -Wno-error=unused-variable -Wno-unused-parameter)
 13 
 14 INCLUDE_DIRECTORIES(include)
 15 
 16 OPTION(COMPILE_SUPPORT "Support compilation from source" ON)
 17 
 18 IF(NOT COMPILE_SUPPORT)
 19   ADD_DEFINITIONS(-DNO_COMPILE)
 20 ENDIF()
 21 
 22 OPTION(FS_SUPPORT "Filesystem plugin support" ON)
 23 OPTION(MATH_SUPPORT "Math plugin support" ON)
 24 OPTION(UBUS_SUPPORT "Ubus plugin support" ON)
 25 OPTION(UCI_SUPPORT "UCI plugin support" ON)
 26 OPTION(RTNL_SUPPORT "Route Netlink plugin support" ON)
 27 OPTION(NL80211_SUPPORT "Wireless Netlink plugin support" ON)
 28 OPTION(RESOLV_SUPPORT "NS resolve plugin support" ON)
 29 OPTION(STRUCT_SUPPORT "Struct plugin support" ON)
 30 
 31 SET(LIB_SEARCH_PATH "${CMAKE_INSTALL_PREFIX}/lib/ucode/*.so:${CMAKE_INSTALL_PREFIX}/share/ucode/*.uc:./*.so:./*.uc" CACHE STRING "Default library search path")
 32 STRING(REPLACE ":" "\", \"" LIB_SEARCH_DEFINE "${LIB_SEARCH_PATH}")
 33 ADD_DEFINITIONS(-DLIB_SEARCH_PATH="${LIB_SEARCH_DEFINE}")
 34 
 35 IF(NOT APPLE)
 36   SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "-Wl,--gc-sections")
 37 ENDIF()
 38 
 39 FIND_LIBRARY(json NAMES json-c json)
 40 
 41 IF(DEBUG)
 42   ADD_DEFINITIONS(-DDEBUG -g3 -O0)
 43 ELSE()
 44   ADD_DEFINITIONS(-DNDEBUG)
 45 ENDIF()
 46 
 47 INCLUDE(FindPkgConfig)
 48 PKG_CHECK_MODULES(JSONC json-c json)
 49 IF(JSONC_FOUND)
 50   ADD_DEFINITIONS(-DJSONC)
 51   INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS})
 52 ENDIF()
 53 
 54 SET(UCODE_SOURCES lexer.c lib.c vm.c chunk.c vallist.c compiler.c source.c types.c program.c)
 55 ADD_LIBRARY(libucode SHARED ${UCODE_SOURCES})
 56 SET(SOVERSION 0 CACHE STRING "Override ucode library version")
 57 SET_TARGET_PROPERTIES(libucode PROPERTIES OUTPUT_NAME ucode SOVERSION ${SOVERSION})
 58 TARGET_LINK_LIBRARIES(libucode ${json})
 59 
 60 SET(CLI_SOURCES main.c)
 61 ADD_EXECUTABLE(ucode ${CLI_SOURCES})
 62 TARGET_LINK_LIBRARIES(ucode libucode ${json})
 63 
 64 CHECK_FUNCTION_EXISTS(dlopen DLOPEN_FUNCTION_EXISTS)
 65 IF (NOT DLOPEN_FUNCTION_EXISTS)
 66   TARGET_LINK_LIBRARIES(libucode dl)
 67 ENDIF()
 68 
 69 CHECK_FUNCTION_EXISTS(fmod FMOD_FUNCTION_EXISTS)
 70 IF (NOT FMOD_FUNCTION_EXISTS)
 71   TARGET_LINK_LIBRARIES(libucode m)
 72 ENDIF()
 73 
 74 SET(CMAKE_REQUIRED_LIBRARIES json-c)
 75 CHECK_SYMBOL_EXISTS(json_object_array_shrink "json.h" HAVE_ARRAY_SHRINK)
 76 IF(HAVE_ARRAY_SHRINK)
 77   ADD_DEFINITIONS(-DHAVE_ARRAY_SHRINK)
 78 ELSE()
 79   CHECK_SYMBOL_EXISTS(json_object_array_shrink "json-c/json.h" HAVE_ARRAY_SHRINK2)
 80   IF(HAVE_ARRAY_SHRINK2)
 81     ADD_DEFINITIONS(-DHAVE_ARRAY_SHRINK)
 82   ENDIF()
 83 ENDIF()
 84 UNSET(CMAKE_REQUIRED_LIBRARIES)
 85 
 86 SET(LIBRARIES "")
 87 
 88 IF(FS_SUPPORT)
 89   SET(LIBRARIES ${LIBRARIES} fs_lib)
 90   ADD_LIBRARY(fs_lib MODULE lib/fs.c)
 91   SET_TARGET_PROPERTIES(fs_lib PROPERTIES OUTPUT_NAME fs PREFIX "")
 92 ENDIF()
 93 
 94 IF(MATH_SUPPORT)
 95   SET(LIBRARIES ${LIBRARIES} math_lib)
 96   ADD_LIBRARY(math_lib MODULE lib/math.c)
 97   SET_TARGET_PROPERTIES(math_lib PROPERTIES OUTPUT_NAME math PREFIX "")
 98   CHECK_FUNCTION_EXISTS(ceil CEIL_FUNCTION_EXISTS)
 99   IF (NOT CEIL_FUNCTION_EXISTS)
100     TARGET_LINK_LIBRARIES(math_lib m)
101   ENDIF()
102 ENDIF()
103 
104 IF(UBUS_SUPPORT)
105   FIND_LIBRARY(ubus NAMES ubus)
106   FIND_LIBRARY(blobmsg_json NAMES blobmsg_json)
107   FIND_PATH(ubus_include_dir NAMES libubus.h)
108   INCLUDE_DIRECTORIES(${ubus_include_dir})
109   SET(LIBRARIES ${LIBRARIES} ubus_lib)
110   ADD_LIBRARY(ubus_lib MODULE lib/ubus.c)
111   SET_TARGET_PROPERTIES(ubus_lib PROPERTIES OUTPUT_NAME ubus PREFIX "")
112   TARGET_LINK_LIBRARIES(ubus_lib ${ubus} ${blobmsg_json})
113 ENDIF()
114 
115 IF(UCI_SUPPORT)
116   FIND_LIBRARY(uci NAMES uci)
117   FIND_LIBRARY(ubox NAMES ubox)
118   FIND_PATH(uci_include_dir uci.h)
119   INCLUDE_DIRECTORIES(${uci_include_dir})
120   SET(LIBRARIES ${LIBRARIES} uci_lib)
121   ADD_LIBRARY(uci_lib MODULE lib/uci.c)
122   SET_TARGET_PROPERTIES(uci_lib PROPERTIES OUTPUT_NAME uci PREFIX "")
123   TARGET_LINK_LIBRARIES(uci_lib ${uci} ${ubox})
124 ENDIF()
125 
126 IF(RTNL_SUPPORT)
127   FIND_LIBRARY(nl NAMES nl-tiny)
128   FIND_PATH(nl_include_dir NAMES netlink/msg.h PATH_SUFFIXES libnl-tiny)
129   INCLUDE_DIRECTORIES(${nl_include_dir})
130   SET(LIBRARIES ${LIBRARIES} rtnl_lib)
131   ADD_LIBRARY(rtnl_lib MODULE lib/rtnl.c)
132   SET_TARGET_PROPERTIES(rtnl_lib PROPERTIES OUTPUT_NAME rtnl PREFIX "")
133   TARGET_LINK_LIBRARIES(rtnl_lib ${nl})
134 ENDIF()
135 
136 IF(NL80211_SUPPORT)
137   FIND_LIBRARY(nl NAMES nl-tiny)
138   FIND_PATH(nl_include_dir NAMES netlink/msg.h PATH_SUFFIXES libnl-tiny)
139   INCLUDE_DIRECTORIES(${nl_include_dir})
140   SET(LIBRARIES ${LIBRARIES} nl80211_lib)
141   ADD_LIBRARY(nl80211_lib MODULE lib/nl80211.c)
142   SET_TARGET_PROPERTIES(nl80211_lib PROPERTIES OUTPUT_NAME nl80211 PREFIX "")
143   TARGET_LINK_LIBRARIES(nl80211_lib ${nl})
144 ENDIF()
145 
146 IF(RESOLV_SUPPORT)
147   SET(LIBRARIES ${LIBRARIES} resolv_lib)
148   ADD_LIBRARY(resolv_lib MODULE lib/resolv.c)
149   SET_TARGET_PROPERTIES(resolv_lib PROPERTIES OUTPUT_NAME resolv PREFIX "")
150   CHECK_FUNCTION_EXISTS(res_mkquery RES_MKQUERY_FUNCTION_EXISTS)
151   CHECK_FUNCTION_EXISTS(clock_gettime CLOCK_GETTIME_FUNCTION_EXISTS)
152   IF (NOT RES_MKQUERY_FUNCTION_EXISTS)
153     TARGET_LINK_LIBRARIES(resolv_lib resolv)
154   ENDIF()
155   IF (NOT CLOCK_GETTIME_FUNCTION_EXISTS)
156     TARGET_LINK_LIBRARIES(resolv_lib rt)
157   ENDIF()
158 ENDIF()
159 
160 IF(STRUCT_SUPPORT)
161   SET(LIBRARIES ${LIBRARIES} struct_lib)
162   ADD_LIBRARY(struct_lib MODULE lib/struct.c)
163   SET_TARGET_PROPERTIES(struct_lib PROPERTIES OUTPUT_NAME struct PREFIX "")
164   CHECK_FUNCTION_EXISTS(frexp FREXP_FUNCTION_EXISTS)
165   IF (NOT FREXP_FUNCTION_EXISTS)
166     TARGET_LINK_LIBRARIES(struct_lib m)
167   ENDIF()
168 ENDIF()
169 
170 IF(UNIT_TESTING)
171   ENABLE_TESTING()
172   ADD_DEFINITIONS(-DUNIT_TESTING)
173   ADD_SUBDIRECTORY(tests)
174   LIST(APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
175 
176   IF(CMAKE_C_COMPILER_ID STREQUAL "Clang")
177     ADD_EXECUTABLE(ucode-san ${CLI_SOURCES} ${UCODE_SOURCES})
178     SET_PROPERTY(TARGET ucode-san PROPERTY ENABLE_EXPORTS 1)
179     TARGET_LINK_LIBRARIES(ucode-san ${json})
180     TARGET_COMPILE_OPTIONS(ucode-san PRIVATE -g -fno-omit-frame-pointer -fsanitize=undefined,address,leak -fno-sanitize-recover=all)
181     TARGET_LINK_OPTIONS(ucode-san PRIVATE -fsanitize=undefined,address,leak)
182   ENDIF()
183 ENDIF()
184 
185 INSTALL(TARGETS ucode RUNTIME DESTINATION bin)
186 INSTALL(TARGETS libucode LIBRARY DESTINATION lib)
187 INSTALL(TARGETS ${LIBRARIES} LIBRARY DESTINATION lib/ucode)
188 
189 FILE(GLOB UCODE_HEADERS "include/ucode/*.h")
190 INSTALL(FILES ${UCODE_HEADERS} DESTINATION include/ucode)
191 
192 ADD_SUBDIRECTORY(examples)

This page was automatically generated by LXR 0.3.1.  •  OpenWrt