Files
cell/meson.build
2025-12-05 12:52:40 -06:00

261 lines
6.5 KiB
Meson

project('cell', ['c', 'cpp'],
version: '0.9.3',
meson_version: '>=1.4',
default_options : [ 'cpp_std=c++11', 'default_library=static'])
libtype = get_option('default_library')
link = []
src = []
add_project_arguments('-Wno-gnu-label-as-value', '-Wno-int-conversion', language: ['c'])
git_tag_cmd = run_command('git', 'describe', '--tags', '--abbrev=0', check: false)
cell_version = 'unknown'
if git_tag_cmd.returncode() == 0
cell_version = git_tag_cmd.stdout().strip()
endif
git_commit_cmd = run_command('git', 'rev-parse', '--short', 'HEAD', check: false)
cell_commit = 'unknown'
if git_commit_cmd.returncode() == 0
cell_commit = git_commit_cmd.stdout().strip()
endif
# Important: pass the definitions without double-escaping quotes
add_project_arguments(
'-DCELL_VERSION="' + cell_version + '"',
'-DCELL_COMMIT="' + cell_commit + '"',
language : 'c'
)
add_project_arguments('-Wno-incompatible-pointer-types', language: 'c')
add_project_arguments('-Wno-narrowing', language: 'cpp')
add_project_arguments('-Wno-missing-braces', language:'c')
add_project_arguments('-Wno-strict-prototypes', language:'c')
add_project_arguments('-Wno-unused-command-line-argument', language: 'c')
add_project_arguments('-Wno-unused-command-line-argument', language: 'cpp')
deps = []
if host_machine.system() == 'darwin'
add_project_arguments('-x', 'objective-c', language: 'c')
fworks = [
]
foreach fkit : fworks
deps += dependency('appleframeworks', modules: fkit)
endforeach
endif
cmake = import('cmake')
cc = meson.get_compiler('c')
if host_machine.system() == 'linux'
deps += cc.find_library('asound', required:true)
deps += [dependency('x11'), dependency('xi'), dependency('xcursor'), dependency('egl'), dependency('gl')]
endif
if host_machine.system() == 'windows'
deps += cc.find_library('d3d11')
deps += cc.find_library('ws2_32', required:true)
deps += cc.find_library('dbghelp')
deps += cc.find_library('winmm')
deps += cc.find_library('setupapi')
deps += cc.find_library('imm32')
deps += cc.find_library('version')
deps += cc.find_library('cfgmgr32')
deps += cc.find_library('bcrypt')
link += ['-static', '-static-libgcc', '-static-libstdc++']
add_project_link_arguments('-static-libgcc', '-static-libstdc++', language: ['c', 'cpp'])
endif
# Try to find system-installed curl first
curl_dep = dependency('libcurl', static: true, required: false)
if not curl_dep.found()
message('⚙ System curl not found, building subproject...')
deps += dependency('libcurl', static:true)
else
deps += curl_dep
endif
if host_machine.system() != 'emscripten'
# Try to find system-installed enet first
enet_dep = dependency('enet', static: true, required: false)
if not enet_dep.found()
message('⚙ System enet not found, building subproject...')
deps += dependency('enet', static:true)
else
deps += enet_dep
endif
mimalloc_enabled = get_option('mimalloc')
if mimalloc_enabled
message('⚙ Using mimalloc subproject for static linking...')
deps += dependency('mimalloc', static:true)
add_project_arguments('-DHAVE_MIMALLOC', language: ['c', 'cpp'])
else
message('⚙ Mimalloc support disabled')
endif
tracy_enabled = get_option('tracy')
if tracy_enabled
message('⚙ Tracy profiling enabled')
tracy_opts = ['fibers=true', 'no_exit=true', 'on_demand=true']
add_project_arguments('-DTRACY_ENABLE', language:['c','cpp'])
# Try to find system-installed tracy first
tracy_dep = dependency('tracy', static: true, required: false)
if not tracy_dep.found()
message('⚙ System tracy not found, building subproject...')
deps += dependency('tracy', static:true, default_options:tracy_opts)
else
deps += tracy_dep
endif
else
message('⚙ Tracy profiling disabled')
endif
endif
link += '-rdynamic'
link_args = link
sources = []
src += [ # core
'qjs_blob.c',
'monocypher.c',
'cell.c',
'wildmatch.c',
'qjs_actor.c',
'qjs_wota.c',
'miniz.c'
]
if get_option('single_threaded')
src += ['scheduler_single.c']
else
src += ['scheduler_threaded.c']
endif
src += ['quickjs.c', 'libregexp.c', 'libunicode.c', 'cutils.c', 'dtoa.c']
scripts = [
'nota.c',
'js.c',
'qop.c',
'wildstar.c',
'fit.c',
'crypto.c',
'text.c',
'utf8.c',
'kim.c',
'time.c',
'nota.c',
'debug.c',
'os.c',
'fd.c',
'socket.c',
'http.c',
'enet.c',
'wildstar.c',
'miniz.c',
]
foreach file: scripts
full_path = join_paths('scripts', file)
sources += files(full_path)
endforeach
srceng = 'source'
includes = [srceng]
foreach file : src
full_path = join_paths(srceng, file)
sources += files(full_path)
endforeach
includers = []
foreach inc : includes
includers += include_directories(inc)
endforeach
if host_machine.system() == 'windows'
exe_ext = '.exe'
link += '-Wl,--export-all-symbols'
else
exe_ext = ''
link += '-Wl,-export_dynamic'
endif
cell_so = shared_library(
'cell_runtime',
sources,
include_directories: includers,
dependencies: deps,
install : true,
)
# Create core.zip from scripts folder
qop_target = custom_target('core.qop',
output: 'core.qop',
command: ['sh', '-c', ' qopconv -d ' + meson.project_source_root() / 'scripts . core.qop'],
build_by_default: true,
build_always_stale: true
)
# Determine RPATH based on OS
# MacOS uses @loader_path, Linux uses $ORIGIN
# We include both the current directory (for build) and ../lib (for install)
rpath_dirs = []
if host_machine.system() == 'darwin'
rpath_dirs += ['@loader_path', '@loader_path/../lib']
elif host_machine.system() == 'linux'
rpath_dirs += ['$ORIGIN', '$ORIGIN/../lib']
endif
# Create main executable linked against the cell library
cell_exe = executable('cell_exe',
'source/main.c',
dependencies: deps,
include_directories: includers,
link_with: cell_so,
link_args: link,
build_rpath: ':'.join(rpath_dirs),
install: false
)
# Create final cell executable by appending core.zip to cell_exe
cell = custom_target('cell',
input: [cell_exe, qop_target],
output: 'cell' + exe_ext,
command: [
'sh', '-c',
'cp "$1" "$3" && cat "$2" >> "$3" && chmod +x "$3"',
'cell-cat', '@INPUT0@', '@INPUT1@', '@OUTPUT@'
],
build_by_default: true,
install: true,
install_dir: get_option('bindir')
)
# Install headers for building dynamic libraries using Cell
install_headers('source/cell.h')
install_headers('source/quickjs.h')
install_headers('source/wota.h')
tests = [
'spawn_actor',
'empty',
'nota',
'wota',
'portalspawner',
'overling',
'send',
'delay'
]
foreach file : tests
test(file, cell, args:['tests/' + file])
endforeach