meson.build (8149B)
1 project('quickjs-tart', 'c', 2 version : '0.0.1', 3 meson_version: '>=0.55.0', 4 default_options : [ 5 'warning_level=1', 6 'optimization=2', 7 ], 8 ) 9 10 flags = [ 11 '-D_GNU_SOURCE', 12 '-D_LARGEFILE_SOURCE', 13 '-D_FILE_OFFSET_BITS=64', 14 '-DCONFIG_VERSION="0.0.1"', 15 '-DCONFIG_BIGNUM', 16 '-fno-omit-frame-pointer', 17 ] 18 19 add_project_arguments(flags, language : 'c') 20 add_project_arguments(flags, language : 'c', native : true) 21 22 if host_machine.system() == 'android' 23 add_project_link_arguments('-Wl,--hash-style=both', language : 'c') 24 endif 25 26 cc = meson.get_compiler('c') 27 28 m_dep = cc.find_library('m', required : false) 29 dl_dep = cc.find_library('dl', required : true) 30 thread_dep = dependency('threads') 31 32 cmake = import('cmake') 33 cmake_opts = cmake.subproject_options() 34 cmake_opts.add_cmake_defines({ 35 'CMAKE_POSITION_INDEPENDENT_CODE' : true, 36 'ENABLE_TESTING' : false, 37 'ENABLE_PROGRAMS' : false}) 38 39 # TLS library 40 mbedtls_proj = cmake.subproject('mbedtls', required : true, options : cmake_opts) 41 mbedcrypto_dep = mbedtls_proj.dependency('mbedcrypto') 42 mbedtls_dep = mbedtls_proj.dependency('mbedtls') 43 mbedx509_dep = mbedtls_proj.dependency('mbedx509') 44 45 # Library for HTTP requests 46 if host_machine.system() != 'ios' and host_machine.system() != 'android' 47 curl_proj = subproject('curl', required : true) 48 curl_dep = curl_proj.get_variable('curl_dep') 49 endif 50 51 # Crypto library 52 sodium_proj = subproject('libsodium', required : true) 53 sodium_dep = sodium_proj.get_variable('sodium_dep') 54 55 # quickjs math library (big float) 56 libbf = static_library('bf', 'quickjs/libbf.c') 57 # regular expression library 58 libregexp = static_library('regexp', 'quickjs/libregexp.c') 59 # unicode 60 libunicode = static_library('unicode', 'quickjs/libunicode.c') 61 # general utilities 62 cutils = static_library('cutils', 'quickjs/cutils.c') 63 # standard library for quickjs (std and os modules) 64 # mobile apps use native networking 65 if host_machine.system() == 'ios' or host_machine.system() == 'android' 66 quickjs_libc = static_library('quickjs-libc', ['quickjs/quickjs-libc.c']) 67 else 68 quickjs_libc = static_library('quickjs-libc', ['quickjs/quickjs-libc.c', 'quickjs/quickjs-http.c'], dependencies : curl_dep) 69 endif 70 71 # base JS interpreter 72 quickjs = static_library('quickjs', 'quickjs/quickjs.c') 73 74 # for iOS use Apple's hand-optimized sqlite3 75 if host_machine.system() == 'ios' 76 sqlite3_dep = cc.find_library('sqlite3', required : true) 77 else 78 sqlite_cargs = [] 79 if host_machine.system() == 'android' 80 # flags taken from AOSP 81 sqlite_cargs += [ 82 '-DNDEBUG=1', 83 '-DHAVE_USLEEP=1', 84 '-DSQLITE_HAVE_ISNAN', 85 '-DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576', 86 '-DSQLITE_THREADSAFE=2', 87 '-DSQLITE_TEMP_STORE=3', 88 '-DSQLITE_POWERSAFE_OVERWRITE=1', 89 '-DSQLITE_DEFAULT_FILE_FORMAT=4', 90 '-DSQLITE_DEFAULT_AUTOVACUUM=1', 91 '-DSQLITE_ENABLE_MEMORY_MANAGEMENT=1', 92 '-DSQLITE_ENABLE_FTS3', 93 '-DSQLITE_ENABLE_FTS3_PARENTHESIS', 94 '-DSQLITE_ENABLE_FTS4', 95 '-DSQLITE_ENABLE_FTS4_PARENTHESIS', 96 '-DSQLITE_ENABLE_FTS5', 97 '-DSQLITE_ENABLE_FTS5_PARENTHESIS', 98 '-DSQLITE_ENABLE_JSON1', 99 '-DSQLITE_ENABLE_RTREE=1', 100 '-DSQLITE_UNTESTABLE', 101 '-DSQLITE_OMIT_COMPILEOPTION_DIAGS', 102 '-DSQLITE_DEFAULT_FILE_PERMISSIONS=0600', 103 '-DSQLITE_DEFAULT_MEMSTATUS=0', 104 '-DSQLITE_MAX_EXPR_DEPTH=0', 105 '-DSQLITE_USE_ALLOCA', 106 '-DSQLITE_ENABLE_BATCH_ATOMIC_WRITE', 107 ] 108 endif 109 110 sqlite3 = static_library('sqlite3', 'sqlite3/sqlite3.c', c_args : sqlite_cargs) 111 endif 112 113 # avoid warning but compile more slowly on non-cross builds 114 avoid_cross_warning = true 115 116 # native version of quickjs used by the qjsc (.js -> .c compiler), 117 # compiled for the build platform. 118 if avoid_cross_warning or meson.is_cross_build() 119 libbf_native = static_library('bf_native', 'quickjs/libbf.c', native : true) 120 libregexp_native = static_library('regexp_native', 'quickjs/libregexp.c', native : true) 121 libunicode_native = static_library('unicode_native', 'quickjs/libunicode.c', native : true) 122 cutils_native = static_library('cutils_native', 'quickjs/cutils.c', native : true) 123 quickjs_native = static_library('quickjs_native', 'quickjs/quickjs.c', native : true) 124 else 125 libbf_native = libbf 126 libregexp_native = libregexp 127 libunicode_native = libunicode 128 cutils_native = cutils 129 quickjs_libc_native = quickjs_libc 130 quickjs_native = quickjs 131 endif 132 133 # QuickJS compiler (.js -> C) 134 qjsc_exe = executable('qjsc', [ 135 'quickjs/qjsc.c', 136 'quickjs/quickjs-libc.c', 137 ], 138 # Just the compiler, no HTTP support required 139 c_args : ['-DNO_HTTP'], 140 link_with: [ 141 libbf_native, 142 libregexp_native, 143 libunicode_native, 144 cutils_native, 145 quickjs_native, 146 ], 147 dependencies: [ 148 m_dep, 149 dl_dep, 150 thread_dep, 151 ], 152 native : true) 153 154 # JS implementation of the read-eval-print loop, 155 # just used for interactive testing 156 repl_c = custom_target('repl_c', 157 input : ['quickjs/repl.js'], 158 output : ['repl.c'], 159 command : [qjsc_exe, '-c', '-m', 160 '-o', '@OUTPUT@', 161 '@INPUT@']) 162 163 # Helper functions used by the wallet-core JS, 164 # compiled to C. 165 prelude_c = custom_target('prelude_c', 166 input : ['prelude.js'], 167 output : ['prelude.c'], 168 command : [qjsc_exe, '-c', '-m', '-M', 'tart', 169 '-o', '@OUTPUT@', 170 '@INPUT@']) 171 172 # Wallet core JS file, 173 # compiled to C. 174 wallet_core_c = custom_target('wallet_core_c', 175 input : ['taler-wallet-core-qjs.mjs'], 176 output : ['wallet_core.c'], 177 command : [qjsc_exe, '-c', '-m', '-M', 'tart', '-N', 'qjsc_wallet_core', 178 '-o', '@OUTPUT@', 179 '@INPUT@']) 180 181 # Static libraries from the generated C files 182 repl = static_library('repl', repl_c) 183 prelude = static_library('prelude', prelude_c) 184 wallet_core = static_library('wallet_core', wallet_core_c) 185 186 # Taler runtime ("tart") loadable JavaScript module 187 if host_machine.system() == 'ios' 188 tart = static_library('tart', 'tart_module.c', 189 dependencies : [ 190 m_dep, 191 mbedcrypto_dep, 192 mbedtls_dep, 193 mbedx509_dep, 194 sodium_dep, 195 sqlite3_dep 196 ]) 197 else 198 tart = static_library('tart', 'tart_module.c', 199 link_with : [sqlite3], 200 dependencies : [ 201 m_dep, 202 mbedcrypto_dep, 203 mbedtls_dep, 204 mbedx509_dep, 205 sodium_dep 206 ]) 207 endif 208 209 # Interactive JS interpreter with Taler-specific 210 # functions (crypto etc.) 211 if not meson.is_cross_build() 212 dependencies = [ 213 m_dep, 214 mbedcrypto_dep, 215 mbedtls_dep, 216 mbedx509_dep, 217 sodium_dep, 218 ] 219 220 # mobile apps use native networking 221 if host_machine.system() != 'ios' and host_machine.system() != 'android' 222 dependencies += [curl_dep] 223 endif 224 225 qtart_exe = executable('qtart', [ 226 'qtart.c', 227 ], 228 link_with: [ 229 libbf, 230 libregexp, 231 libunicode , 232 cutils, 233 quickjs_libc, 234 quickjs, 235 repl, 236 wallet_core, 237 prelude, 238 tart, 239 ], 240 dependencies: dependencies) 241 endif 242 243 # Library that implements wallet-core, typically 244 # the only build output directly used by the UI layer. 245 if host_machine.system() == 'ios' 246 talerwalletcore_lib = static_library('talerwalletcore', 'taler_wallet_core_lib.c', 247 link_with : [ 248 libbf, 249 libregexp, 250 libunicode, 251 cutils, 252 quickjs_libc, 253 quickjs, 254 tart, 255 wallet_core, 256 prelude, 257 ], 258 dependencies: [ 259 m_dep, 260 mbedcrypto_dep, 261 mbedtls_dep, 262 mbedx509_dep, 263 sodium_dep, 264 ], c_args : ['-DNO_CURL']) 265 else 266 talerwalletcore_cargs = [] 267 if host_machine.system() == 'android' 268 # no cURL, Android is using native networking 269 talerwalletcore_cargs += ['-DNO_CURL'] 270 endif 271 talerwalletcore_lib = shared_library('talerwalletcore', 'taler_wallet_core_lib.c', 272 link_with : [ 273 libbf, 274 libregexp, 275 libunicode, 276 cutils, 277 quickjs_libc, 278 quickjs, 279 tart, 280 wallet_core, 281 prelude, 282 ], 283 dependencies: [ 284 m_dep, 285 mbedcrypto_dep, 286 mbedtls_dep, 287 mbedx509_dep, 288 sodium_dep, 289 ], c_args : talerwalletcore_cargs) 290 endif 291 292 # Example for using libtalerwalletcore.so 293 if not meson.is_cross_build() 294 wallet_client_example_exe = executable('wallet-client-example', 295 'wallet-client-example.c', 296 link_with : [talerwalletcore_lib]) 297 endif