Is it possible to detect if code is executing at compile time?

Yes, sorry, I did not make this clear in my question. I’m interested to know if the code is being called during compilation, not necessarily at some mythical ‘compile time’.

Given that, I think your suggestion should work! Thank you.