What is correct way for out-of-source definitions?

The question mostly about co-working of CLion with CMake.

We have the NDEBUG macro defined for all our release builds (well, somebody have DEBUG for debug, just the opposite, but the question is the same).

In the code they are used as
#ifdef NDEBUG
... // some release-specific code
#endif // NDEBUG

The macro itself originally (when the project was ruled with automake/autotools) was defined via the compiler flag, Namely - as the '-DNDEBUG' insertion into the gcc flags.

Now it was moved to CMake with it's default Release/MinSizeRel/RelWithDebInfo/Debug configurations as this clause:


However I see that CLion ALWAYS fold the code under '#ifndeff NDEBUG' - whenever Release or Debug config selected in CLion itself.
Well, I've tried to add explicit macro into config:

/* Define to make the debug build (will work in IDE apart from external NDEBUG compiler def)

        set (IS_RELEASE_CONFIG 1)
add_definitions (-DHAVE_CONFIG_H)

So, now for Release build the  'NDEBUG" is not just mentioned somewhere in the compiler flags, but explicitly defined or not defined in the included (generated) header. I'd expected the CLion will see the definition in this case... but, again, nothing changed!

So, the question is - how to tell CLion about internal definitions which are diferent between configurations, if it doens't see the difference from CMakeList files?

1 comment
Comment actions Permalink

Alexey, there is a "Context:" popup chooser in the right lower corner of the editor. Please try choosing another resolve context there. You don't need to put defines into headers explicitly, the initial approach with add_definitions should work. Moreover, I think by default CMake adds NDEBUG to every build configuration, so there is no need to do that manually.


Please sign in to leave a comment.