2021-06-10 17:11:20 +02:00
if ( NOT TARGET _family_support_marker )
add_library ( _family_support_marker INTERFACE )
if ( NOT FAMILY )
2022-02-09 17:19:01 +01:00
message ( FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the cmake command line" )
2021-06-10 17:11:20 +02:00
endif ( )
if ( NOT EXISTS ${ CMAKE_CURRENT_LIST_DIR } / ${ FAMILY } /family.cmake )
message ( FATAL_ERROR "Family '${FAMILY}' is not known/supported" )
endif ( )
function ( family_filter RESULT DIR )
get_filename_component ( DIR ${ DIR } ABSOLUTE BASE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
2022-01-13 14:42:28 +01:00
if ( EXISTS "${DIR}/only.txt" )
file ( READ "${DIR}/only.txt" ONLYS )
# Replace newlines with semicolon so that it is treated as a list by CMake
string ( REPLACE "\n" ";" ONLYS_LINES ${ ONLYS } )
# For each mcu
2021-06-10 17:11:20 +02:00
foreach ( MCU IN LISTS FAMILY_MCUS )
2022-01-13 14:42:28 +01:00
# For each line in only.txt
foreach ( _line ${ ONLYS_LINES } )
# If mcu:xxx exists for this mcu then include
if ( ${ _line } STREQUAL "mcu:${MCU}" )
set ( ${ RESULT } 1 PARENT_SCOPE )
return ( )
endif ( )
endforeach ( )
2021-06-10 17:11:20 +02:00
endforeach ( )
2022-01-13 14:42:28 +01:00
# Didn't find it in only file so don't build
set ( ${ RESULT } 0 PARENT_SCOPE )
elseif ( EXISTS "${DIR}/skip.txt" )
file ( READ "${DIR}/skip.txt" SKIPS )
# Replace newlines with semicolon so that it is treated as a list by CMake
string ( REPLACE "\n" ";" SKIPS_LINES ${ SKIPS } )
# For each mcu
2021-06-10 17:11:20 +02:00
foreach ( MCU IN LISTS FAMILY_MCUS )
2022-01-13 14:42:28 +01:00
# For each line in only.txt
foreach ( _line ${ SKIPS_LINES } )
# If mcu:xxx exists for this mcu then skip
if ( ${ _line } STREQUAL "mcu:${MCU}" )
set ( ${ RESULT } 0 PARENT_SCOPE )
return ( )
endif ( )
endforeach ( )
2021-06-10 17:11:20 +02:00
endforeach ( )
2022-01-13 14:42:28 +01:00
# Didn't find in skip file so build
set ( ${ RESULT } 1 PARENT_SCOPE )
else ( )
# Didn't find skip or only file so build
set ( ${ RESULT } 1 PARENT_SCOPE )
2021-06-10 17:11:20 +02:00
endif ( )
2022-01-13 14:42:28 +01:00
2021-06-10 17:11:20 +02:00
endfunction ( )
function ( family_add_subdirectory DIR )
family_filter ( SHOULD_ADD "${DIR}" )
if ( SHOULD_ADD )
add_subdirectory ( ${ DIR } )
endif ( )
endfunction ( )
function ( family_get_project_name OUTPUT_NAME DIR )
get_filename_component ( SHORT_NAME ${ DIR } NAME )
set ( ${ OUTPUT_NAME } ${ TINYUSB_FAMILY_PROJECT_NAME_PREFIX } ${ SHORT_NAME } PARENT_SCOPE )
endfunction ( )
function ( family_initialize_project PROJECT DIR )
family_filter ( ALLOWED "${DIR}" )
if ( NOT ALLOWED )
get_filename_component ( SHORT_NAME ${ DIR } NAME )
message ( FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}" )
endif ( )
endfunction ( )
2022-07-12 19:58:30 +02:00
function ( family_add_default_example_warnings TARGET )
target_compile_options ( ${ TARGET } PUBLIC
- W a l l
- W e x t r a
- W e r r o r
- W f a t a l - e r r o r s
- W d o u b l e - p r o m o t i o n
- W f l o a t - e q u a l
- W s h a d o w
- W w r i t e - s t r i n g s
- W s i g n - c o m p a r e
- W m i s s i n g - f o r m a t - a t t r i b u t e
- W u n r e a c h a b l e - c o d e
- W c a s t - a l i g n
- W c a s t - q u a l
- W n u l l - d e r e f e r e n c e
- W u n i n i t i a l i z e d
- W u n u s e d
- W r e d u n d a n t - d e c l s
#-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 ( )
2022-07-12 20:29:47 +02:00
# GCC 6
if ( CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0 )
target_compile_options ( ${ TARGET } PUBLIC -Wno-strict-aliasing )
endif ( )
2022-07-12 19:58:30 +02:00
endif ( )
endfunction ( )
2021-06-10 17:11:20 +02:00
# configure an executable target to link to tinyusb in device mode, and add the board implementation
function ( family_configure_device_example TARGET )
2022-12-04 07:58:47 +01:00
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake
2021-06-10 17:11:20 +02:00
endfunction ( )
# configure an executable target to link to tinyusb in host mode, and add the board implementation
function ( family_configure_host_example TARGET )
2022-12-04 07:58:47 +01:00
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake
2021-06-10 17:11:20 +02:00
endfunction ( )
include ( ${ CMAKE_CURRENT_LIST_DIR } / ${ FAMILY } /family.cmake )
if ( NOT FAMILY_MCUS )
set ( FAMILY_MCUS ${ FAMILY } )
endif ( )
# save it in case of re-inclusion
set ( FAMILY_MCUS ${ FAMILY_MCUS } CACHE INTERNAL "" )
2023-03-17 10:12:49 +01:00
endif ( )