Skip to content

Commit 798d76c

Browse files
committed
cmake: Add GCC -Og flag fallback to -O0.
The -Og (optimise for debugging) flag is only available for GCC 4.8.0 and above, and specifying it for a GCC version lower than 4.8.0 will result in a compilation error. This commit adds a check for compiler -Og optimisation flag support and a fallback to -O0 (disable optimisation) when -Og flag is unsupported. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 0877064 commit 798d76c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cmake/compiler/gcc/target_optimizations.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ macro(toolchain_cc_optimize_for_no_optimizations_flag dest_var_name)
1515
endmacro()
1616

1717
macro(toolchain_cc_optimize_for_debug_flag dest_var_name)
18-
set_ifndef(${dest_var_name} "-Og")
18+
# -Og optimisation flag is only supported from gcc 4.8.0 and above.
19+
# Fall back to using -O0 flag if running an older gcc version.
20+
if(CMAKE_C_COMPILER_VERSION VERSION_LESS "4.8.0")
21+
set_ifndef(${dest_var_name} "-O0")
22+
else()
23+
set_ifndef(${dest_var_name} "-Og")
24+
endif()
1925
endmacro()
2026

2127
macro(toolchain_cc_optimize_for_speed_flag dest_var_name)

0 commit comments

Comments
 (0)