A better way is
{$ifopt D+}// + is debug mode - is release mode
That is better because it does not rely on the Lazarus IDE.
This works in other editors too, since it is compiler configuration based.
If you did not know that, it was not solved, but now it is.....
(I can complicate things on request, but that is not the general issue)
It is all about how your fpc.cfg options are defined.
Has nothing to do with Lazarus.