Fix compiler warning for GCC >= 11.3

- GCC version 12 generates a warnings for certain pointer
references.  Apparently this is to decect invalid offsets.  To properly
compiler, the recommended remedy is to add the compiler option
"--param=min-pagesize=0" to the flags.  This option was introduced in
version 11.3, so we need to check the compiler version and only add for
>11.3.

- Moved setting of compiler flags to a new function c_toolchain_flags in
the toolchain file "generic-gcc-avr.cmake".  This function is now called
from the CMakeLists.txt file in the src directory.  This allows the test
for the compiler version to be specified in the toolchain file, but not
executed until called by the src subdir CMakeLists.txt.  Delaying
evaluation of the function ensures that the CMAKE_C_VERSION variable is
properly set when the function is called.

- Moving the compiler flags out of the source dir CMakeLists.txt file
also improves portability by moving architecture-specific compiler
details from the source tree to the toolchain file.
This commit is contained in:
Dave 2022-09-02 00:00:55 -05:00
parent 18e451d8a6
commit 9aa3bf4681
2 changed files with 40 additions and 26 deletions

View File

@ -151,6 +151,45 @@ else(WITH_MCU)
set(MCU_TYPE_FOR_FILENAME "")
endif(WITH_MCU)
function(c_toolchain_flags)
# fix array base indexing beginning in AVR-GCC 12:
list(APPEND TOOLCHAIN_FLAGS
-std=c99
# -Wa,-adhln
-Wall
-funsigned-char
-funsigned-bitfields
-ffunction-sections
-fdata-sections
-fpack-struct
-fshort-enums
-O2
-Wall
-Wextra
-Wpointer-arith
-Wcast-align
-Wwrite-strings
-Wswitch-default
-Wunreachable-code
-Winit-self
-Wmissing-field-initializers
-Wno-unknown-pragmas
-Wstrict-prototypes
-Wundef
-Wold-style-definition
)
if(CMAKE_C_COMPILER_VERSION GREATER_EQUAL "11.3")
message(STATUS "Appending page size fix for GCC >= 11.3")
list(APPEND TOOLCHAIN_FLAGS --param=min-pagesize=0)
endif()
set(CFLAGS ${TOOLCHAIN_FLAGS} PARENT_SCOPE)
endfunction(c_toolchain_flags)
##########################################################################
# add_avr_executable
# - IN_VAR: EXECUTABLE_NAME

View File

@ -52,32 +52,7 @@ configure_file(${ASDF_SRC_DIR}/asdf_keymap_setup.c.in ${CMAKE_CURRENT_BINARY_DI
configure_file(${ASDF_SRC_DIR}/asdf_keymap_setup.h.in ${CMAKE_CURRENT_BINARY_DIR}/asdf_keymap_setup.h)
list(APPEND CFLAGS
-std=c99
# -Wa,-adhln
-Wall
-funsigned-char
-funsigned-bitfields
-ffunction-sections
-fdata-sections
-fpack-struct
-fshort-enums
-O2
-Wall
-Wextra
-Wpointer-arith
-Wcast-align
-Wwrite-strings
-Wswitch-default
-Wunreachable-code
-Winit-self
-Wmissing-field-initializers
-Wno-unknown-pragmas
-Wstrict-prototypes
-Wundef
-Wold-style-definition
)
c_toolchain_flags()
list (APPEND SOURCES
asdf.c