Cannot get rid of NDEBUG compiler flag
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 1.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 33
Description
**Describe the bug**
I am trying to compile a test suite (C++) with assertions enabled but meson always added a compiler flag -DNDEBUG, thus deactivating all assertions. For meson configure, I used options
```-Ddebug=true -Db_ndebug=false``` to no avail. Interestingly, ```meson configure``` does not list the -DNDEBUG flag, even though build.ninja does include it. I found that this only happens when using a HDF5 dependency, in an environment where HDF5 is detected via h5cc and not pkg-config. It seems that the NDEBUG is propagated directly from h5cc output (which does include NDEBUG) into the main compile flags. I can see no other origin, in particular I checked that no environment variables contain any NDEBUG.
**To Reproduce**
Minimal example:
file meson.build
```
project('Bla', ['cpp','c'], default_options : ['cpp_std=c++11'],
version : '1.6', license : 'CC BY-NC-SA 4.0')
#no ill effects from those
dep_boost = dependency('boost')
dep_gsl = dependency('gsl', version : '>=2.0') #found via pkg-config
#this dependency deactivates all assertions
dep_h5 = dependency('hdf5') # found via h5cc
exe_tst = executable('bla', sources : 'bla.cpp', dependencies : [dep_boost, dep_gsl, dep_h5])
```
file bla.cpp
```
#include
int main() {
assert(false);
}
```
building
```
meson setup -Ddebug=true -Db_ndebug=false mbuild
ninja -C mbuild
./mbuild/bla #does not fail with assertion as expected
```
**Expected behavior**
When giving the -Db_ndebug=false option to meson configure, I would expect that it is guaranteed that no -DNDEBUG compiler argument is used, i.e. that the code is compiled with assertions activated. Currently, the b_ndebug parameter seems only to control whether or not meson adds NDEBUG on its own but does not enforce the user choice when NDEBUG propagates from dependencies (I don't know if that propagation is a bug or a feature but this is another topic). More generally, I expect a reliable way to compile code with assertions activated.
**system parameters**
* native builds on latest Arch linux and Debian 10.2.1-6
* Python version 3.10.12
* Meson version 1.2.0
* Ninja version 1.11.1
Contributor guide
Research direction
Reproduce the issue with the minimal meson.build and bla.cpp example, using HDF5 discovered through h5cc. Inspect h5cc output and the generated build.ninja to trace where -DNDEBUG enters the compile flags. Done means -Db_ndebug=false reliably leaves assertions enabled and the generated compile commands contain no -DNDEBUG, including when HDF5 is used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100