Detect Build Profile in code

Is there a way to detect in the code which Build Profile is selected (Debug, Release, Develop).
So i can printf(“Debug Build active”);

Thanks fo helping out, been looking everywhere, cannot find one define 8-(

Hello Hans,

You can test the NDEBUG macro to figure out whether the application is being built with the debug profile:

#if !defined(NDEBUG)
    printf(“Debug Build active”);
    printf(“Debug Build not active”);

If you need to turn on debug messages only in the debug profile then a more convenient option is to use the debug function rather then the printf one since the former has such test built-in.
When you call

debug("Debug Build active”);

then the message is printed only when the application was built with the debug profile.

Best regards, Zoltan

Hi Zoltan,

Thanks, you have pushed me into the right direction. I found the NDEBUG defined in the release.json file (mbed-os/tools/profiles). The debug.json files has the MBED_DEBUG defined. The develop build profile does not have any defined.

Beste regards, Hans.