Failing to build tests when CMAKE_BUILD_TYPE MinSizeRel on Linux
First discovered when building spudlib on Ubuntu.
OS: Linux ubuntu 3.19.0-16-generic #16-Ubuntu SMP Thu Apr 30 16:09:58 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux CC: cc (Ubuntu 4.9.2-10ubuntu13) 4.9.2
Diff to reproduce bug (Sorry about my lack of cmake understanding but cmake .. -DCMAKE_BUILD_TYPE=MinRelSize -Dcoveralls=OFF -Dcoveralls_send=OFF -Dverbose=ON did not provoke the bug)
-if (NOT CMAKE_BUILD_TYPE)
- if ( optimize )
- set ( CMAKE_BUILD_TYPE MinSizeRel )
- set ( coveralls OFF )
- set ( coveralls_send OFF )
- else ()
- set ( CMAKE_BUILD_TYPE Debug )
- endif () -endif() +set ( CMAKE_BUILD_TYPE MinSizeRel ) +set ( coveralls OFF ) +set ( coveralls_send OFF )
+#if (NOT CMAKE_BUILD_TYPE) +# if ( optimize ) +# set ( CMAKE_BUILD_TYPE MinSizeRel ) +# set ( coveralls OFF ) +# set ( coveralls_send OFF ) +# else () +# set ( CMAKE_BUILD_TYPE Debug ) +# endif () +#endif()
Gives following compile warnings: d /home/palmarti/development/cn-cbor/build/test && /usr/bin/cc -Os -DNDEBUG -I/home/palmarti/development/cn-cbor/test/../include -I/home/palmarti/development/cn-cbor/src/../include -std=gnu99 -Wall -Wextra -pedantic -Werror -o CMakeFiles/cbor_test.dir/cbor_test.c.o -c /home/palmarti/development/cn-cbor/test/cbor_test.c /home/palmarti/development/cn-cbor/test/cbor_test.c: In function ‘_ctest_cbor_parse_normalize_run’: /home/palmarti/development/cn-cbor/test/cbor_test.c:168:9: error: iteration 18ul invokes undefined behavior [-Werror=aggressive-loop-optimizations] CTEST_LOG("%s: %s", tests[i], cn_cbor_error_str[err.err]); ^ /home/palmarti/development/cn-cbor/test/cbor_test.c:163:5: note: containing loop for (i=0; i<sizeof(tests)/sizeof(char); ) { ^ cc1: all warnings being treated as errors test/CMakeFiles/cbor_test.dir/build.make:57: recipe for target 'test/CMakeFiles/cbor_test.dir/cbor_test.c.o' failed make[2]: *_* [test/CMakeFiles/cbor_test.dir/cbor_test.c.o] Error 1