0

I need to pass a compiler flag -D__DEBUG_FILE__="src.cpp" to g++ while compiling source file src.cpp. How can I achieve this in meson? I am aware of the cpp_args built-in option, but not able to figure out how to pass the file name in it.

I am aware that in make file you can write similar to below to achieve this: I am looking for a way to replicate this in meson build.

test.o : test.cpp     
g++ -D__MY_FILE__=\"$<\" -c $< -o $@
Clinten Gomez
  • 148
  • 1
  • 9

1 Answers1

1

As a workaround, I have arrived at the below:

trimprefix = run_command(['python', '-c', 'import sys, os; print(os.path.relpath(sys.argv[1], sys.argv[2]))', meson.current_source_dir(), meson.build_root()]).stdout().strip()

cpp_args : [ '-fmacro-prefix-map=@0@/='.format(trimprefix) ]

There are 2 problems still:

  1. I still need to use __FILE__, I cannot define my own macro like __MY_FILE__
  2. I need to compute "trimprefix" once for each sub directory

An in built option to use @INPUT@, @BASENAME@ inside cpp_args could save a lot of this jugglery! I have raised an issue in meson-build #7485 to address this - please up vote if you need this too.

Clinten Gomez
  • 148
  • 1
  • 9