aboutsummaryrefslogtreecommitdiffstats
path: root/meson.build
diff options
context:
space:
mode:
authorLibravatar Manuel Stoeckl <code@mstoeckl.com>2019-06-22 23:13:19 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-07-15 16:35:50 -0400
commit2dc4978d8af326c310057ca8fd22a4c7f5d09335 (patch)
treee49b4d10481309d90bd5330b7bbeec588f4de88c /meson.build
parentLayout tiled using a width/height fraction (diff)
downloadsway-2dc4978d8af326c310057ca8fd22a4c7f5d09335.tar.gz
sway-2dc4978d8af326c310057ca8fd22a4c7f5d09335.tar.zst
sway-2dc4978d8af326c310057ca8fd22a4c7f5d09335.zip
Use -fmacro-prefix-map to strip build path
Because meson does not provide a simple way to get the relative build path, it is computed with a pair of foreach loops. As meson does not have a simple way to compute string length (except via underscorify and 63 split operations), the build script uses a shell command instead. If the compiler does not suppot -fmacro-prefix-map, then fall back to passing in the relative path prefix, and use its length to offset the uses of __FILE__ in log messages so that the build path is at least still not included in the logs. This is significantly more efficient than calling _sway_strip_path.
Diffstat (limited to 'meson.build')
-rw-r--r--meson.build40
1 files changed, 38 insertions, 2 deletions
diff --git a/meson.build b/meson.build
index f657f874..eb5039ee 100644
--- a/meson.build
+++ b/meson.build
@@ -13,8 +13,6 @@ project(
13 13
14add_project_arguments( 14add_project_arguments(
15 [ 15 [
16 '-DSWAY_SRC_DIR="@0@"'.format(meson.current_source_dir()),
17
18 '-DWL_HIDE_DEPRECATED', 16 '-DWL_HIDE_DEPRECATED',
19 '-DWLR_USE_UNSTABLE', 17 '-DWLR_USE_UNSTABLE',
20 18
@@ -142,6 +140,44 @@ if git.found()
142endif 140endif
143add_project_arguments('-DSWAY_VERSION=@0@'.format(version), language: 'c') 141add_project_arguments('-DSWAY_VERSION=@0@'.format(version), language: 'c')
144 142
143# Compute the relative path used by compiler invocations.
144source_root = meson.current_source_dir().split('/')
145build_root = meson.build_root().split('/')
146relative_dir_parts = []
147i = 0
148in_prefix = true
149foreach p : build_root
150 if i >= source_root.length() or not in_prefix or p != source_root[i]
151 in_prefix = false
152 relative_dir_parts += '..'
153 endif
154 i += 1
155endforeach
156i = 0
157in_prefix = true
158foreach p : source_root
159 if i >= build_root.length() or not in_prefix or build_root[i] != p
160 in_prefix = false
161 relative_dir_parts += p
162 endif
163 i += 1
164endforeach
165relative_dir = join_paths(relative_dir_parts) + '/'
166
167# Strip relative path prefixes from the code if possible, otherwise hide them.
168if cc.has_argument('-fmacro-prefix-map=/prefix/to/hide=')
169 add_project_arguments(
170 '-fmacro-prefix-map=@0@='.format(relative_dir),
171 language: 'c',
172 )
173else
174 add_project_arguments(
175 '-DSWAY_REL_SRC_DIR="@0@"'.format(relative_dir),
176 language: 'c',
177 )
178endif
179
180
145sway_inc = include_directories('include') 181sway_inc = include_directories('include')
146 182
147subdir('include') 183subdir('include')