@@ -184,6 +184,43 @@ endif()
184184#------------------------------------
185185# Functions
186186#------------------------------------
187+ function (family_add_default_example_warnings TARGET )
188+ # Apply warnings to all TinyUSB interface library sources as well as examples sources
189+ # we cannot set compile options for target since it will not propagate to INTERFACE sources then picosdk files
190+ foreach (TINYUSB_TARGET IN ITEMS tinyusb_common_base tinyusb_device_base tinyusb_host_base tinyusb_host_max3421 tinyusb_bsp)
191+ get_target_property (TINYUSB_SOURCES ${TINYUSB_TARGET} INTERFACE_SOURCES)
192+ set_source_files_properties (${TINYUSB_SOURCES} PROPERTIES COMPILE_OPTIONS "${WARN_FLAGS_${CMAKE_C_COMPILER_ID} }" )
193+ endforeach ()
194+
195+ # Also apply to example sources, but filter out any source files from lib/ (e.g. fatfs)
196+ get_target_property (EXAMPLE_SOURCES ${TARGET} SOURCES )
197+ set (FILTERED_SOURCES "" )
198+ foreach (SOURCE_FILE IN LISTS EXAMPLE_SOURCES)
199+ string (FIND "${SOURCE_FILE} " "${TOP} /lib" FOUND_POS)
200+ if (FOUND_POS EQUAL -1)
201+ list (APPEND FILTERED_SOURCES ${SOURCE_FILE} )
202+ endif ()
203+ endforeach ()
204+ set_source_files_properties (${FILTERED_SOURCES} PROPERTIES COMPILE_OPTIONS "${WARN_FLAGS_${CMAKE_C_COMPILER_ID} }" )
205+
206+ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" )
207+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 AND NO_WARN_RWX_SEGMENTS_SUPPORTED)
208+ target_link_options (${TARGET} PRIVATE "LINKER:--no-warn-rwx-segments" )
209+ endif ()
210+
211+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
212+ target_compile_options (${TARGET} PRIVATE -Wconversion)
213+ endif ()
214+
215+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
216+ target_compile_options (${TARGET} PRIVATE -Wcast-function-type -Wstrict-overflow)
217+ endif ()
218+
219+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
220+ target_compile_options (${TARGET} PRIVATE -Wno-strict-aliasing)
221+ endif ()
222+ endif ()
223+ endfunction ()
187224
188225function (family_configure_target TARGET RTOS)
189226 if (RTOS STREQUAL noos OR RTOS STREQUAL "" )
@@ -204,7 +241,7 @@ function(family_configure_target TARGET RTOS)
204241 pico_enable_stdio_uart(${TARGET} 1)
205242 target_link_libraries (${TARGET} PUBLIC pico_stdlib tinyusb_board${RTOS_SUFFIX} tinyusb_additions)
206243
207- family_flash_openocd(${TARGET} )
244+ family_flash_openocd(${TARGET} )
208245 family_flash_jlink(${TARGET} )
209246endfunction ()
210247
@@ -359,34 +396,9 @@ function(suppress_tinyusb_warnings)
359396 ${PICO_TINYUSB_PATH} /src/portable/raspberrypi/rp2040/hcd_rp2040.c
360397 )
361398 foreach (SOURCE_FILE IN LISTS CONVERSION_WARNING_FILES)
362- set_source_files_properties (
363- ${SOURCE_FILE}
364- PROPERTIES
365- COMPILE_FLAGS "-Wno-conversion" )
399+ set_source_files_properties (${SOURCE_FILE} PROPERTIES COMPILE_FLAGS "-Wno-conversion" )
366400 endforeach ()
367401 endif ()
368- if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0)
369- set_source_files_properties (
370- ${PICO_TINYUSB_PATH} /lib/fatfs/source /ff.c
371- COMPILE_FLAGS "-Wno-stringop-overflow -Wno-array-bounds" )
372- endif ()
373- set_source_files_properties (
374- ${PICO_TINYUSB_PATH} /lib/fatfs/source /ff.c
375- PROPERTIES
376- COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual" )
377-
378- set_source_files_properties (
379- ${PICO_TINYUSB_PATH} /lib/lwip/src/core/tcp_in.c
380- ${PICO_TINYUSB_PATH} /lib/lwip/src/core/tcp_out.c
381- PROPERTIES
382- COMPILE_FLAGS "-Wno-conversion" )
383-
384- set_source_files_properties (
385- ${PICO_TINYUSB_PATH} /lib/networking/dnserver.c
386- ${PICO_TINYUSB_PATH} /lib/networking/dhserver.c
387- ${PICO_TINYUSB_PATH} /lib/networking/rndis_reports.c
388- PROPERTIES
389- COMPILE_FLAGS "-Wno-conversion -Wno-sign-conversion" )
390402
391403 if (TARGET tinyusb_pico_pio_usb)
392404 set_source_files_properties (
0 commit comments