How to detect DEBUG / RELEASE kind of build ?
Posted: Sun Nov 19, 2023 5:20 pm
by chris33
Hi all ! I stumbled upon this simple problem : how can I detect a DEBUG build ?
Basically I need something like
Code: Select all
#ifdef THERE_MUST_BE_AN_IDF_DEBUG_DEFINED_SOMEWHERE
#define FOO(x) { /* some stuf */ }
#else
#define FOO(x)
#endif
Note : VS Code + ESP IDF extension
Re: How to detect DEBUG / RELEASE kind of build ?
Posted: Sun Nov 19, 2023 9:42 pm
by MicroController
Not sure if the IDF provides something, but you can use cmake to conditionally add defines, see
https://stackoverflow.com/a/64719718
Code: Select all
add_library(foobar)
target_compile_definitions(foobar PRIVATE
$<$<CONFIG:Debug>:
FOOBAR_DEBUG=1
>
)
Or, you can check if
Code: Select all
#ifdef NDEBUG
Non-Debug...
#else
Debug...
#endif
works for you.
Re: How to detect DEBUG / RELEASE kind of build ?
Posted: Mon Nov 20, 2023 4:41 pm
by chris33
Thanks for you answer ! But if there's no DEBUG/RELEASE defined by the ESP-IDF the simplest solution is to have my own global #define somewhere in my code...
I asked because it's a common pattern in IDEs to have a way to detect the current build type through a defined symbol...