CMakeLists.txt: don't override the optimization level #847
+5
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
zenoh-pico's CMakeLists.txt has some logic to provide its own compiler optimization level: -O3 for release builds, -O0 for debug builds.
Unfortunately, using add_compile_options() means that those settings take precedence over what the user can pass as custom compiler flags. And this causes issues for example when doing a debug build with _FORTIFY_SOURCE enabled, as _FORTIFY_SOURCE support in glibc is incompatible with unoptimized builds causing this build failure:
/home/thomas/projets/buildroot/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/include/features.h:414:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
414 | # warning _FORTIFY_SOURCE requires compiling with optimization (-O)
| ^~~~~~~
which is a warning, but as zenoh-pico builds with -Werror, it turns into a build failure.
As it is unclear how CMakeLists.txt can pass a default -O level, while allowing it to be overridden by the user, we simply remove those optimization level options.