How to detect DEBUG / RELEASE kind of build ?

chris33
Posts: 9
Joined: Wed Dec 22, 2021 10:35 am

How to detect DEBUG / RELEASE kind of build ?

Postby chris33 » Sun Nov 19, 2023 5:20 pm

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

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to detect DEBUG / RELEASE kind of build ?

Postby MicroController » Sun Nov 19, 2023 9:42 pm

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.

chris33
Posts: 9
Joined: Wed Dec 22, 2021 10:35 am

Re: How to detect DEBUG / RELEASE kind of build ?

Postby chris33 » Mon Nov 20, 2023 4:41 pm

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...

Who is online

Users browsing this forum: Majestic-12 [Bot] and 68 guests