RP@040: rework CMake for compiler warnings

This commit is contained in:
graham sanderson
2022-07-12 12:58:30 -05:00
parent 1a8c3a863b
commit fc1a27b6c9
27 changed files with 85 additions and 132 deletions

View File

@@ -79,6 +79,43 @@ if (NOT TARGET _family_support_marker)
endif()
endfunction()
function(family_add_default_example_warnings TARGET)
target_compile_options(${TARGET} PUBLIC
-Wall
-Wextra
-Werror
-Wfatal-errors
-Wdouble-promotion
-Wfloat-equal
-Wshadow
-Wwrite-strings
-Wsign-compare
-Wmissing-format-attribute
-Wunreachable-code
-Wcast-align
-Wcast-qual
-Wnull-dereference
-Wuninitialized
-Wunused
-Wredundant-decls
#-Wstrict-prototypes
#-Werror-implicit-function-declaration
#-Wundef
)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
# GCC 10
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
target_compile_options(${TARGET} PUBLIC -Wconversion)
endif()
# GCC 8
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
target_compile_options(${TARGET} PUBLIC -Wcast-function-type -Wstrict-overflow)
endif()
endif()
endfunction()
# configure an executable target to link to tinyusb in device mode, and add the board implementation
function(family_configure_device_example TARGET)
# default implentation is empty, the function should be redefined in the FAMILY/family.cmake

View File

@@ -147,16 +147,23 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
target_link_libraries(${TARGET} PUBLIC pico_stdlib pico_bootsel_via_double_reset tinyusb_board tinyusb_additions)
endfunction()
function(rp2040_family_configure_example_warnings TARGET)
if (NOT PICO_TINYUSB_NO_EXAMPLE_WARNINGS)
family_add_default_example_warnings(${TARGET})
endif()
suppress_tinyusb_warnings()
endfunction()
function(family_configure_device_example TARGET)
family_configure_target(${TARGET})
target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device)
suppress_tinyusb_warnings()
rp2040_family_configure_example_warnings(${TARGET})
endfunction()
function(family_configure_host_example TARGET)
family_configure_target(${TARGET})
target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_host)
suppress_tinyusb_warnings()
rp2040_family_configure_example_warnings(${TARGET})
endfunction()
function(family_add_pico_pio_usb TARGET)
@@ -167,7 +174,7 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
family_configure_target(${TARGET})
# require tinyusb_pico_pio_usb
target_link_libraries(${TARGET} PUBLIC pico_stdlib tinyusb_device tinyusb_host tinyusb_pico_pio_usb )
suppress_tinyusb_warnings()
rp2040_family_configure_example_warnings(${TARGET})
endfunction()
function(check_and_add_pico_pio_usb_support)
@@ -236,30 +243,38 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
# This method must be called from the project scope to suppress known warnings in TinyUSB source files
function(suppress_tinyusb_warnings)
# some of these are pretty silly warnings only occurring in some older GCC versions 9 or prior
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
set(CONVERSION_WARNING_FILES
${PICO_TINYUSB_PATH}/src/tusb.c
${PICO_TINYUSB_PATH}/src/common/tusb_fifo.c
${PICO_TINYUSB_PATH}/src/device/usbd.c
${PICO_TINYUSB_PATH}/src/device/usbd_control.c
${PICO_TINYUSB_PATH}/src/host/usbh.c
${PICO_TINYUSB_PATH}/src/class/cdc/cdc_device.c
${PICO_TINYUSB_PATH}/src/class/cdc/cdc_host.c
${PICO_TINYUSB_PATH}/src/class/hid/hid_device.c
${PICO_TINYUSB_PATH}/src/class/hid/hid_host.c
${PICO_TINYUSB_PATH}/src/class/audio/audio_device.c
${PICO_TINYUSB_PATH}/src/class/dfu/dfu_device.c
${PICO_TINYUSB_PATH}/src/class/dfu/dfu_rt_device.c
${PICO_TINYUSB_PATH}/src/class/midi/midi_device.c
${PICO_TINYUSB_PATH}/src/class/usbtmc/usbtmc_device.c
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/hcd_rp2040.c
)
foreach(SOURCE_FILE IN LISTS CONVERSION_WARNING_FILES)
set_source_files_properties(
${SOURCE_FILE}
PROPERTIES
COMPILE_FLAGS "-Wno-conversion")
endforeach()
endif()
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 10.0)
set(CONVERSION_WARNING_FILES
${PICO_TINYUSB_PATH}/src/tusb.c
${PICO_TINYUSB_PATH}/src/common/tusb_fifo.c
${PICO_TINYUSB_PATH}/src/device/usbd.c
${PICO_TINYUSB_PATH}/src/device/usbd_control.c
${PICO_TINYUSB_PATH}/src/host/usbh.c
${PICO_TINYUSB_PATH}/src/class/cdc/cdc_device.c
${PICO_TINYUSB_PATH}/src/class/cdc/cdc_host.c
${PICO_TINYUSB_PATH}/src/class/hid/hid_device.c
${PICO_TINYUSB_PATH}/src/class/hid/hid_host.c
${PICO_TINYUSB_PATH}/src/class/audio/audio_device.c
${PICO_TINYUSB_PATH}/src/class/dfu/dfu_device.c
${PICO_TINYUSB_PATH}/src/class/dfu/dfu_rt_device.c
${PICO_TINYUSB_PATH}/src/class/midi/midi_device.c
${PICO_TINYUSB_PATH}/src/class/usbtmc/usbtmc_device.c
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/hcd_rp2040.c
)
foreach(SOURCE_FILE IN LISTS CONVERSION_WARNING_FILES)
set_source_files_properties(
${SOURCE_FILE}
PROPERTIES
COMPILE_FLAGS "-Wno-conversion")
endforeach()
endif()
if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
set_source_files_properties(
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/rp2040_usb.c
PROPERTIES
COMPILE_FLAGS "-Wno-stringop-overflow -Wno-array-bounds")
endif()
endif()
endfunction()
endif()