Please excuse me if this question has been answered before. I have been looking for a way to specify project specific compiler options. I have read the threads where hardware.local.txt and boards.local.txt are discussed, but if I understand correctly, these are all global settings.
As an example, I have a project that needs the following to compile.
There is talk about adding this sort of capability to Arduino CLI, but it is only in the planning stage at this point.
For now, I think your best solution would be to add a build script (or makefile or whatever you like) to the sketch that contains the necessary arduino-cli compile command. That way you don't need to bother with manually adding the right build flags every time you want to compile.