cmake release builds don't disable assertions (NDEBUG)

Michael Gmelin freebsd at
Mon Feb 6 22:53:34 UTC 2017

On Mon, 06 Feb 2017 22:27:01 +0100
Raphael Kubo da Costa <rakuco at> wrote:

> Michael Gmelin <freebsd at> writes:
> > While debugging an unexpected assertion problem, I noticed that
> > ports using cmake don't set -NDEBUG, even when building in Release
> > mode.
> >
> > Is this intentional?  
> Is it the software you're porting that checks for DEBUG or some
> library it uses?
> CMake code should check for CMAKE_BUILD_TYPE and adjust the compiler
> flags accordingly (if at all); so if the software itself is checking
> for DEBUG but not passing (or omitting it) I'd say the bug is there,
> not in Mk/Uses/

Well, overwrites the meaning of CMAKE_CXX_FLAGS_RELEASE with
the content of CXXFLAGS, are you sure that doing this is the right
thing to do?

I sampled a couple of smaller projects that use cmake in the ports tree
and it seems like many projects don't do anything special to prevent
assertions or debug code when built using CMAKE_BUILD_TYPE=Release,
which makes me think that the authors depend on the default behaviour
of cmake, which includes "-NDEBUG" in Release mode (AFAIK default flags
for build types are also compiler and platform dependent, so it kind of
makes sense to rely on the defaults, doesn't it?).


Michael Gmelin

More information about the freebsd-ports mailing list