meson: strip build relative paths from file macros

This commit is contained in:
Daniel Eklöf 2020-02-16 14:40:02 +01:00
parent 38a682f0d0
commit 3e6321155e
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -10,12 +10,41 @@ project('foot', 'c',
is_debug_build = get_option('buildtype').startswith('debug')
cc = meson.get_compiler('c')
add_project_arguments(
['-D_GNU_SOURCE=200809L'] + (is_debug_build ? ['-D_DEBUG'] : []),
language: 'c',
)
cc = meson.get_compiler('c')
# Compute the relative path used by compiler invocations.
source_root = meson.current_source_dir().split('/')
build_root = meson.build_root().split('/')
relative_dir_parts = []
i = 0
in_prefix = true
foreach p : build_root
if i >= source_root.length() or not in_prefix or p != source_root[i]
in_prefix = false
relative_dir_parts += '..'
endif
i += 1
endforeach
i = 0
in_prefix = true
foreach p : source_root
if i >= build_root.length() or not in_prefix or build_root[i] != p
in_prefix = false
relative_dir_parts += p
endif
i += 1
endforeach
relative_dir = join_paths(relative_dir_parts) + '/'
if cc.has_argument('-fmacro-prefix-map=/foo=')
add_project_arguments('-fmacro-prefix-map=@0@='.format(relative_dir), language: 'c')
endif
math = cc.find_library('m')
threads = dependency('threads')
pixman = dependency('pixman-1')