Files
Abhi c2f219c95a meson: guard the class-import test on the file's existence
test/test_import.py is referenced but not committed on all branches,
which makes meson configure abort on Windows with
ERROR: File test/test_import.py does not exist. Wire the test only
when the file is present.
2026-10-18 11:45:15 +05:30

129 lines
3.4 KiB
Meson

project(
'r2unity',
'c',
version: '1.2.9',
default_options: [
'c_std=c99',
'warning_level=2',
'buildtype=debugoptimized',
],
)
add_project_arguments(
[
'-D_DEFAULT_SOURCE',
'-D_POSIX_C_SOURCE=200809L',
],
language: 'c',
)
r2 = find_program('r2', required: true)
r2_cflags = run_command(r2, '-H', 'R2_CFLAGS', check: true).stdout().strip().split()
r2_ldflags = run_command(r2, '-H', 'R2_LDFLAGS', check: true).stdout().strip().split()
r2_libs = run_command(r2, '-H', 'R2_LIBS', check: true).stdout().strip().split()
r2_fallback_dep = declare_dependency(
compile_args: r2_cflags,
link_args: r2_ldflags + r2_libs,
)
# Windows release ZIPs are relocatable and are not registered with pkg-config.
# Fall back to the paths reported by r2 when pkg-config cannot find its SDK.
r_util_dep = dependency('r_util', required: false)
if not r_util_dep.found()
r_util_dep = r2_fallback_dep
endif
r_bin_dep = dependency('r_bin', required: false)
if not r_bin_dep.found()
r_bin_dep = r2_fallback_dep
endif
conf = configuration_data()
conf.set_quoted('R2UNITY_VERSION', meson.project_version())
configure_file(output: 'r2unity_config.h', configuration: conf)
lib_inc = include_directories('src/lib')
lib_sources = files(
'src/lib/lib.c',
'src/lib/bin/elf.c',
'src/lib/bin/macho.c',
'src/lib/bin/native.c',
'src/lib/bin/pe.c',
'src/lib/paths.c',
'src/lib/serialized_file.c',
'src/lib/sbom.c',
)
r2unity = executable(
'r2unity',
files('src/main.c') + lib_sources,
include_directories: lib_inc,
dependencies: [r_util_dep, r_bin_dep],
install: true,
)
test('r2unity-help', r2unity, args: ['-h'])
test('r2unity-version', r2unity, args: ['-v'])
plugins_opt = get_option('plugins')
r_core_dep = dependency('r_core', required: false)
if not r_core_dep.found() and not plugins_opt.disabled()
r_core_dep = r2_fallback_dep
endif
build_plugins = plugins_opt.enabled() or (
plugins_opt.auto() and r_core_dep.found() and r_bin_dep.found()
)
if build_plugins
r2_plugindir = get_option('r2_plugindir')
if r2_plugindir == ''
r2 = find_program('r2', required: false)
if r2.found()
r2_user_plugins = run_command(r2, '-H', 'R2_USER_PLUGINS', check: false)
if r2_user_plugins.returncode() == 0
r2_plugindir = r2_user_plugins.stdout().strip()
endif
endif
endif
if r2_plugindir == ''
r2_plugindir = join_paths(get_option('libdir'), 'radare2', 'plugins')
warning('r2 was not found; installing plugins under ' + r2_plugindir)
endif
core_plugin = shared_library(
'core_r2unity',
files('src/r2/core_r2unity.c') + lib_sources,
include_directories: lib_inc,
dependencies: [r_core_dep, r_bin_dep],
name_prefix: '',
install: true,
install_dir: r2_plugindir,
)
shared_library(
'bin_r2unity',
files(
'src/r2/bin_r2unity.c',
'src/lib/bgdatabase.c',
'src/lib/resource_pack.c',
) + lib_sources,
include_directories: lib_inc,
dependencies: [r_bin_dep],
name_prefix: '',
install: true,
install_dir: r2_plugindir,
)
# test_import.py is not always present (it is not committed yet on every
# branch); only wire the test when the file exists
fs = import('fs')
python = find_program('python3', required: false)
if python.found() and fs.exists('test' / 'test_import.py')
test('r2unity-class-import', python,
args: [files('test/test_import.py'), core_plugin],
)
endif
endif