MangoHud/meson.build

293 lines
7.5 KiB
Meson
Raw Normal View History

2020-03-12 07:24:37 +00:00
project('MangoHud',
['c', 'cpp'],
2024-01-26 07:04:56 +00:00
version : 'v0.7.1',
license : 'MIT',
meson_version: '>=0.60.0',
default_options : ['buildtype=release', 'c_std=c99', 'cpp_std=c++14', 'warning_level=2']
)
cc = meson.get_compiler('c')
cpp = meson.get_compiler('cpp')
prog_python = import('python').find_installation('python3', modules: ['mako'])
2020-01-30 17:52:15 +00:00
null_dep = dependency('', required : false)
2020-05-02 16:39:39 +00:00
mangohud_version = vcs_tag(
command: ['git', 'describe', '--tags', '--dirty=+'],
input: 'version.h.in',
output: 'version.h')
mangohud_version_dep = declare_dependency(sources : mangohud_version)
pre_args = [
'-D__STDC_CONSTANT_MACROS',
'-D__STDC_FORMAT_MACROS',
'-D__STDC_LIMIT_MACROS',
'-DPACKAGE_VERSION="@0@"'.format(meson.project_version()),
'-DSPDLOG_COMPILED_LIB'
]
# Always set max spdlog level, handle this using MANGOHUD_LOG_LEVEL instead.
2023-10-07 22:33:27 +00:00
if get_option('buildtype') == 'debug'
pre_args += '-DDEBUG'
2023-10-10 09:08:07 +00:00
pre_args += '-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE'
2023-10-12 03:34:21 +00:00
else
pre_args += '-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG'
2023-10-07 22:33:27 +00:00
endif
# TODO: this is very incomplete
2020-09-05 05:42:39 +00:00
is_unixy = false
if ['linux', 'cygwin', 'gnu'].contains(host_machine.system())
pre_args += '-D_GNU_SOURCE'
pre_args += '-DHAVE_PTHREAD'
2020-09-05 05:42:39 +00:00
is_unixy = true
endif
if get_option('glibcxx_asserts')
pre_args += '-D_GLIBCXX_ASSERTIONS'
endif
# Check for GCC style atomics
if cc.compiles('''#include <stdint.h>
int main() {
struct {
uint64_t *v;
} x;
return (int)__atomic_load_n(x.v, __ATOMIC_ACQUIRE) &
(int)__atomic_add_fetch(x.v, (uint64_t)1, __ATOMIC_ACQ_REL);
}''',
name : 'GCC atomic builtins')
pre_args += '-DUSE_GCC_ATOMIC_BUILTINS'
endif
# Not in C99, needs POSIX
if cc.compiles('''
#define _GNU_SOURCE
#include <time.h>
int main() {
struct timespec ts;
return timespec_get(&ts, TIME_UTC);
}''',
name : 'Supports timespec_get')
pre_args += '-DHAVE_TIMESPEC_GET'
endif
# Check for GCC style builtins
foreach b : ['bswap32', 'bswap64', 'clz', 'clzll', 'ctz', 'expect', 'ffs',
'ffsll', 'popcount', 'popcountll', 'unreachable']
if cc.has_function(b)
pre_args += '-DHAVE___BUILTIN_@0@'.format(b.to_upper())
endif
endforeach
vulkan_wsi_args = []
vulkan_wsi_deps = []
2020-09-05 05:42:39 +00:00
if is_unixy
dep_x11 = dependency('x11', required: get_option('with_x11'))
dep_wayland_client = dependency('wayland-client',
required: get_option('with_wayland'), version : '>=1.11')
dbus_dep = dependency('dbus-1', required: get_option('with_dbus')).partial_dependency(compile_args : true, includes : true)
2024-02-19 12:59:51 +00:00
dep_xkb = dependency('xkbcommon', required: get_option('with_wayland'))
2020-09-05 05:42:39 +00:00
else
dep_x11 = null_dep
dep_wayland_client = null_dep
dbus_dep = null_dep
endif
if dep_x11.found()
vulkan_wsi_args += ['-DVK_USE_PLATFORM_XLIB_KHR']
vulkan_wsi_deps += dep_x11.partial_dependency(compile_args : true, includes : true)
endif
if dep_wayland_client.found()
vulkan_wsi_args += ['-DVK_USE_PLATFORM_WAYLAND_KHR']
vulkan_wsi_deps += dep_wayland_client
2024-02-19 12:59:51 +00:00
vulkan_wsi_deps += dep_xkb
endif
2020-09-05 05:42:39 +00:00
if is_unixy and not dep_x11.found() and not dep_wayland_client.found()
error('At least one of "with_x11" and "with_wayland" should be enabled')
endif
inc_common = [
include_directories('include'),
]
dep_pthread = dependency('threads')
add_project_arguments(
cc.get_supported_arguments([
'-Werror=implicit-function-declaration',
'-Werror=missing-declarations',
'-Werror=missing-prototypes',
'-Werror=return-type',
'-Werror=incompatible-pointer-types',
'-Wno-unused-parameter',
'-Qunused-arguments',
'-fno-math-errno',
'-fno-trapping-math',
'-Wno-missing-field-initializers',
]), language : ['c'],
)
add_project_arguments(
cpp.get_supported_arguments([
'-Werror=missing-declarations',
'-Werror=return-type',
'-Wno-unused-parameter',
'-Qunused-arguments',
'-fno-math-errno',
'-fno-trapping-math',
'-Wno-non-virtual-dtor',
'-Wno-missing-field-initializers',
]), language : ['cpp'],
)
foreach a : pre_args
add_project_arguments(a, language : ['c', 'cpp'])
endforeach
# check for dl support
2020-09-05 05:42:39 +00:00
if is_unixy
if cc.has_function('dlopen')
dep_dl = null_dep
else
dep_dl = cc.find_library('dl')
endif
2020-09-05 09:16:20 +00:00
# check for linking with rt by default
if cc.has_function('clock_gettime')
dep_rt = null_dep
else
dep_rt = cc.find_library('rt')
endif
else
2020-09-05 05:42:39 +00:00
dep_dl = null_dep
dep_rt = null_dep
endif
vkh_sp = subproject('vulkan-headers')
vk_api_xml = vkh_sp.get_variable('vulkan_api_xml')
dep_vulkan = vkh_sp.get_variable('vulkan_headers_dep')
vk_enum_to_str = custom_target(
'vk_enum_to_str',
input : ['bin/gen_enum_to_str.py', vk_api_xml],
output : ['vk_enum_to_str.c', 'vk_enum_to_str.h'],
command : [
prog_python, '@INPUT0@', '--xml', '@INPUT1@',
'--outdir', meson.current_build_dir()
],
)
2020-03-11 16:04:10 +00:00
2021-10-18 17:19:59 +00:00
imgui_options = [
'default_library=static',
'werror=false',
2021-10-18 17:19:59 +00:00
# use 'auto_features=disabled' once available: https://github.com/mesonbuild/meson/issues/5320
'dx9=disabled',
'dx10=disabled',
'dx11=disabled',
'dx12=disabled',
'metal=disabled',
'opengl=disabled',
'vulkan=disabled',
'glfw=disabled',
'sdl2=disabled',
'osx=disabled',
'win=disabled',
'allegro5=disabled',
2023-10-05 16:25:05 +00:00
'webgpu=disabled',
'sdl_renderer=disabled'
2021-10-18 17:19:59 +00:00
]
sizeof_ptr = cc.sizeof('void*')
if sizeof_ptr == 8
2020-03-23 19:12:02 +00:00
pre_args += '-DMANGOHUD_ARCH="64bit"'
2021-10-18 15:50:27 +00:00
elif sizeof_ptr == 4
pre_args += '-DMANGOHUD_ARCH="32bit"'
endif
if get_option('mangoapp')
imgui_options += [
'opengl=enabled',
'glfw=enabled',
]
endif
2021-10-18 16:58:39 +00:00
dearimgui_sp = subproject('imgui', default_options: imgui_options)
dearimgui_dep = dearimgui_sp.get_variable('imgui_dep')
2023-09-21 20:05:21 +00:00
if is_unixy
2023-10-05 16:35:55 +00:00
implot_sp = subproject('implot', default_options: ['default_library=static'])
2023-09-21 20:05:21 +00:00
implot_dep = implot_sp.get_variable('implot_dep')
else
implot_dep = null_dep
implot_lib = static_library('nulllib', [])
endif
2021-07-16 00:28:46 +00:00
spdlog_dep = cpp.find_library('spdlog', required: get_option('use_system_spdlog'))
if not spdlog_dep.found()
spdlog_sp = subproject('spdlog', default_options: [
'default_library=static',
'compile_library=true',
2022-05-11 11:58:03 +00:00
'werror=false',
2024-01-27 08:47:53 +00:00
'tests=disabled',
2024-01-28 13:38:23 +00:00
'external_fmt=disabled',
'std_format=disabled'
2021-07-16 00:28:46 +00:00
])
spdlog_dep = spdlog_sp.get_variable('spdlog_dep')
else
spdlog_dep = dependency('spdlog', required: true)
endif
2020-09-05 05:42:15 +00:00
if ['windows', 'mingw'].contains(host_machine.system())
minhook_sp = subproject('minhook')
minhook_dep = minhook_sp.get_variable('minhook_dep')
2020-09-05 05:42:15 +00:00
windows_deps = [
2020-09-05 09:16:20 +00:00
minhook_dep,
2020-09-05 05:42:15 +00:00
]
else
windows_deps = null_dep
endif
2022-03-15 21:56:36 +00:00
if get_option('mangoapp') or get_option('mangoapp_layer')
2021-10-18 17:14:58 +00:00
glfw3_dep = dependency('glfw3')
2023-09-21 20:02:56 +00:00
glew_dep = dependency('glew')
2021-10-18 17:14:58 +00:00
endif
2021-09-06 06:21:10 +00:00
json_dep = dependency('nlohmann_json')
2020-01-29 10:23:51 +00:00
subdir('src')
if get_option('include_doc')
subdir('data')
endif
2022-10-26 01:52:04 +00:00
if get_option('tests').enabled()
2023-05-05 00:29:14 +00:00
cmocka_dep = dependency('cmocka', fallback: ['cmocka', 'cmocka_dep'])
2022-10-27 01:44:00 +00:00
2022-10-27 01:46:54 +00:00
e = executable('amdgpu', 'tests/test_amdgpu.cpp',
2022-10-27 01:44:00 +00:00
files(
'src/amdgpu.cpp',
'src/cpu.cpp',
'src/gpu.cpp',
'src/mesa/util/os_time.c',
'src/file_utils.cpp',
),
cpp_args: ['-DTEST_ONLY'],
2022-10-27 01:44:00 +00:00
dependencies: [
dep_vulkan,
2022-10-27 01:44:00 +00:00
cmocka_dep,
spdlog_dep,
dearimgui_dep
2023-01-05 09:54:34 +00:00
],
include_directories: inc_common)
2022-10-27 01:44:00 +00:00
test('test amdgpu', e, workdir : meson.project_source_root() + '/tests')
2022-10-26 01:52:04 +00:00
endif
# install helper sripts
2023-10-10 08:55:45 +00:00
if get_option('mangoplot').enabled()
subdir('bin')
endif