2023-05-19 16:27:07 +07:00
if ( TARGET _family_support_marker )
return ( )
endif ( )
2023-05-06 15:14:54 +07:00
2023-05-19 16:27:07 +07:00
add_library ( _family_support_marker INTERFACE )
2023-04-20 16:55:48 +07:00
2023-05-19 16:27:07 +07:00
include ( CMakePrintHelpers )
2023-04-20 16:55:48 +07:00
2023-05-19 16:27:07 +07:00
# Default to gcc
if ( NOT DEFINED TOOLCHAIN )
set ( TOOLCHAIN gcc )
endif ( )
2021-06-10 10:11:20 -05:00
2023-05-19 16:27:07 +07:00
if ( NOT FAMILY )
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" )
endif ( )
2021-06-10 10:11:20 -05:00
2023-05-19 16:27:07 +07:00
if ( NOT EXISTS ${ CMAKE_CURRENT_LIST_DIR } / ${ FAMILY } /family.cmake )
message ( FATAL_ERROR "Family '${FAMILY}' is not known/supported" )
endif ( )
2022-01-13 13:42:28 +00:00
2023-05-19 16:27:07 +07:00
function ( family_filter RESULT DIR )
get_filename_component ( DIR ${ DIR } ABSOLUTE BASE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
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
foreach ( MCU IN LISTS FAMILY_MCUS )
# For each line in only.txt
foreach ( _line ${ ONLYS_LINES } )
# If mcu:xxx exists for this mcu or board:xxx then include
if ( ${ _line } STREQUAL "mcu:${MCU}" OR ${ _line } STREQUAL "board:${BOARD}" )
set ( ${ RESULT } 1 PARENT_SCOPE )
return ( )
endif ( )
endforeach ( )
endforeach ( )
# 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
foreach ( MCU IN LISTS FAMILY_MCUS )
# 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 ( )
2021-06-10 10:11:20 -05:00
endforeach ( )
2023-05-19 16:27:07 +07:00
endforeach ( )
2022-01-13 13:42:28 +00:00
2023-05-19 16:27:07 +07:00
# Didn't find in skip file so build
set ( ${ RESULT } 1 PARENT_SCOPE )
2022-01-13 13:42:28 +00:00
2023-05-19 16:27:07 +07:00
else ( )
2022-01-13 13:42:28 +00:00
2023-05-19 16:27:07 +07:00
# Didn't find skip or only file so build
set ( ${ RESULT } 1 PARENT_SCOPE )
2022-01-13 13:42:28 +00:00
2023-05-19 16:27:07 +07:00
endif ( )
2022-01-13 13:42:28 +00:00
2023-05-19 16:27:07 +07:00
endfunction ( )
2021-06-10 10:11:20 -05:00
2023-05-19 16:27:07 +07:00
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 ( )
2021-06-10 10:11:20 -05:00
2023-05-19 16:27:07 +07:00
function ( family_initialize_project PROJECT DIR )
family_filter ( ALLOWED "${DIR}" )
if ( NOT ALLOWED )
2021-06-10 10:11:20 -05:00
get_filename_component ( SHORT_NAME ${ DIR } NAME )
2023-05-19 16:27:07 +07:00
message ( FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}" )
endif ( )
endfunction ( )
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" )
if ( CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0 )
target_link_options ( ${ TARGET } PUBLIC "LINKER:--no-warn-rwx-segments" )
2022-07-12 12:58:30 -05:00
endif ( )
2021-06-10 10:11:20 -05:00
2023-05-19 16:27:07 +07:00
# GCC 10
if ( CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0 )
target_compile_options ( ${ TARGET } PUBLIC -Wconversion )
endif ( )
2021-06-10 10:11:20 -05:00
2023-05-19 16:27:07 +07:00
# GCC 8
if ( CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0 )
target_compile_options ( ${ TARGET } PUBLIC -Wcast-function-type -Wstrict-overflow )
endif ( )
2021-06-10 10:11:20 -05:00
2023-05-19 16:27:07 +07:00
# GCC 6
if ( CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0 )
target_compile_options ( ${ TARGET } PUBLIC -Wno-strict-aliasing )
endif ( )
2021-06-10 10:11:20 -05:00
endif ( )
2023-05-19 16:27:07 +07:00
endfunction ( )
2023-05-23 21:45:00 +07:00
# add_custom_command(TARGET ${TARGET} POST_BUILD
# COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${TARGET}> ${TARGET}.hex
# COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${TARGET}> ${TARGET}.bin
# COMMENT "Creating ${TARGET}.hex and ${TARGET}.bin"
# )
2023-05-19 16:27:07 +07:00
# Add flash jlink target
function ( family_flash_jlink TARGET )
if ( NOT DEFINED JLINKEXE )
set ( JLINKEXE JLinkExe )
endif ( )
file ( GENERATE
O U T P U T $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { T A R G E T } . j l i n k
C O N T E N T " h a l t
l o a d f i l e $ < T A R G E T _ F I L E : $ { T A R G E T } >
r
g o
e x i t "
)
add_custom_target ( ${ TARGET } -jlink
D E P E N D S $ { T A R G E T }
C O M M A N D $ { J L I N K E X E } - d e v i c e $ { J L I N K _ D E V I C E } - i f s w d - J T A G C o n f - 1 , - 1 - s p e e d a u t o - C o m m a n d F i l e $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / $ { T A R G E T } . j l i n k
)
endfunction ( )
# Add flash pycod target
function ( family_flash_pyocd TARGET )
if ( NOT DEFINED PYOC )
set ( PYOCD pyocd )
endif ( )
add_custom_target ( ${ TARGET } -pyocd
D E P E N D S $ { T A R G E T }
C O M M A N D $ { P Y O C D } f l a s h - t $ { P Y O C D _ T A R G E T } $ < T A R G E T _ F I L E : $ { T A R G E T } >
)
endfunction ( )
# Add flash using NXP's LinkServer (redserver)
# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER
function ( family_flash_nxplink TARGET )
if ( NOT DEFINED LINKSERVER )
set ( LINKSERVER LinkServer )
endif ( )
# LinkServer has a bug that can only execute with full path otherwise it throws:
# realpath error: No such file or directory
execute_process ( COMMAND which ${ LINKSERVER } OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE )
add_custom_target ( ${ TARGET } -nxplink
D E P E N D S $ { T A R G E T }
C O M M A N D $ { L I N K S E R V E R _ P A T H } f l a s h $ { N X P L I N K _ D E V I C E } l o a d $ < T A R G E T _ F I L E : $ { T A R G E T } >
)
endfunction ( )
# configure an executable target to link to tinyusb in device mode, and add the board implementation
function ( family_configure_device_example TARGET )
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake
endfunction ( )
# configure an executable target to link to tinyusb in host mode, and add the board implementation
function ( family_configure_host_example TARGET )
# default implementation is empty, the function should be redefined in the FAMILY/family.cmake
endfunction ( )
include ( ${ CMAKE_CURRENT_LIST_DIR } / ${ FAMILY } /family.cmake )
if ( NOT FAMILY_MCUS )
set ( FAMILY_MCUS ${ FAMILY } )
2023-03-17 16:12:49 +07:00
endif ( )
2023-05-19 16:27:07 +07:00
# save it in case of re-inclusion
set ( FAMILY_MCUS ${ FAMILY_MCUS } CACHE INTERNAL "" )