Use -fmacro-prefix-map to strip build path 25/297225/1
authorSeunghun Lee <shiin.lee@samsung.com>
Tue, 8 Aug 2023 05:16:46 +0000 (14:16 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 14 Aug 2023 07:22:22 +0000 (16:22 +0900)
This is taken from wlroots to strip the build-path dependent bytes
of each __FILE__ string used by ds_log and related functions.

Change-Id: I6ac9babf381efafb62f03c30da5c7f3da5e1d36f

meson.build

index 434f1b9..0e50d10 100644 (file)
@@ -18,6 +18,42 @@ add_project_arguments(cc.get_supported_arguments([
   '-Wno-missing-braces',
 ]), language: ['c', 'cpp'])
 
+# Compute the relative path used by compiler invocations.
+source_root = meson.current_source_dir().split('/')
+build_root = meson.global_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=/prefix/to/hide=')
+  add_project_arguments(
+    '-fmacro-prefix-map=@0@='.format(relative_dir),
+    language: 'c',
+  )
+else
+  add_project_arguments(
+    '-D_DS_REL_SRC_DIR="@0@"'.format(relative_dir),
+    language: 'c',
+  )
+endif
+
 libds_tizen_version = meson.project_version()
 version_arr = libds_tizen_version.split('.')
 libds_tizen_version_major = version_arr[0]