Skip to content

Commit a64532e

Browse files
committed
cmake: disable optimization on debug builds
While our debug builds on MSVC platforms already tune the code optimizer to aid debugging code, all the other platforms still use the default optimization level. This makes it hard for developers on these platforms to actually debug code while maintaining his sanity due to optimizations like inlined code, elided variables etc. To help this common use case, we can simply follow the MSVC example and turn off code optimization with "-O0" for debug builds. While it would be preferable to instead use "-Og" supported by more modern compilers, we cannot guarantee that this level is available on all supported platforms.
1 parent 6139995 commit a64532e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ ELSE ()
478478
SET(CMAKE_C_FLAGS "-std=c99 -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
479479
ENDIF()
480480

481-
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
481+
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0")
482482

483483
IF (MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to
484484
STRING(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")

0 commit comments

Comments
 (0)