- change to use CMAKE_SYSTEM_CPU to prevent CMAKE_SYSTEM_PROCESSOR conflict with zephyr

- change tinyusb CMakeLists.txt to function tinyusb_target_add() instead of defining tinyusb lib target
This commit is contained in:
hathach
2025-01-22 22:31:08 +07:00
parent 91214b4614
commit 6080f89f3d
67 changed files with 171 additions and 239 deletions

View File

@@ -1,11 +1,10 @@
# TODO more docs and example on how to use this file
# Usage: requires target tinyusb_config which expose tusb_config.h file
# TINYUSB_TARGET_PREFIX and TINYUSB_TARGET_SUFFIX can be used to change the name of the target
cmake_minimum_required(VERSION 3.20)
# Add tinyusb to a target, if user don't want to compile tinyusb as a library
function(add_tinyusb TARGET)
# Add tinyusb to a existing target
function(tinyusb_target_add TARGET)
target_sources(${TARGET} PRIVATE
# common
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/tusb.c
@@ -40,68 +39,36 @@ function(add_tinyusb TARGET)
# TODO for net driver, should be removed/changed
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../lib/networking
)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
target_compile_options(${TARGET} PRIVATE
-Wall
-Wextra
#-Werror
-Wfatal-errors
-Wdouble-promotion
-Wstrict-prototypes
-Wstrict-overflow
-Werror-implicit-function-declaration
-Wfloat-equal
-Wundef
-Wshadow
-Wwrite-strings
-Wsign-compare
-Wmissing-format-attribute
-Wunreachable-code
-Wcast-align
-Wcast-function-type
-Wcast-qual
-Wnull-dereference
-Wuninitialized
-Wunused
-Wunused-function
-Wreturn-type
-Wredundant-decls
-Wmissing-prototypes
)
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
endif ()
endfunction()
#------------------------------------
# TinyUSB as library target
#------------------------------------
if (NOT DEFINED TINYUSB_TARGET)
set(TINYUSB_TARGET "tinyusb")
endif ()
set(TINYUSB_CONFIG_TARGET "${TINYUSB_TARGET}_config")
if (DEFINED TINYUSB_TARGET_PREFIX)
set(TINYUSB_TARGET "${TINYUSB_TARGET_PREFIX}${TINYUSB_TARGET}")
set(TINYUSB_CONFIG_TARGET "${TINYUSB_TARGET_PREFIX}${TINYUSB_CONFIG_TARGET}")
endif ()
if (DEFINED TINYUSB_TARGET_SUFFIX)
set(TINYUSB_TARGET "${TINYUSB_TARGET}${TINYUSB_TARGET_SUFFIX}")
set(TINYUSB_CONFIG_TARGET "${TINYUSB_CONFIG_TARGET}${TINYUSB_TARGET_SUFFIX}")
endif ()
add_library(${TINYUSB_TARGET} STATIC)
add_tinyusb(${TINYUSB_TARGET})
# Check if tinyusb_config target is defined
if (NOT TARGET ${TINYUSB_CONFIG_TARGET})
message(FATAL_ERROR "${TINYUSB_CONFIG_TARGET} target is not defined")
endif()
# Link with tinyusb_config target
target_link_libraries(${TINYUSB_TARGET} PUBLIC
${TINYUSB_CONFIG_TARGET}
)
#if (NOT DEFINED TINYUSB_TARGET)
# set(TINYUSB_TARGET "tinyusb")
#endif ()
#
#set(TINYUSB_CONFIG_TARGET "${TINYUSB_TARGET}_config")
#
#if (DEFINED TINYUSB_TARGET_PREFIX)
# set(TINYUSB_TARGET "${TINYUSB_TARGET_PREFIX}${TINYUSB_TARGET}")
# set(TINYUSB_CONFIG_TARGET "${TINYUSB_TARGET_PREFIX}${TINYUSB_CONFIG_TARGET}")
#endif ()
#
#if (DEFINED TINYUSB_TARGET_SUFFIX)
# set(TINYUSB_TARGET "${TINYUSB_TARGET}${TINYUSB_TARGET_SUFFIX}")
# set(TINYUSB_CONFIG_TARGET "${TINYUSB_CONFIG_TARGET}${TINYUSB_TARGET_SUFFIX}")
#endif ()
#
#add_library(${TINYUSB_TARGET} STATIC)
#tinyusb_target_add(${TINYUSB_TARGET})
#
## Check if tinyusb_config target is defined
#if (NOT TARGET ${TINYUSB_CONFIG_TARGET})
# message(FATAL_ERROR "${TINYUSB_CONFIG_TARGET} target is not defined")
#endif()
#
## Link with tinyusb_config target
#target_link_libraries(${TINYUSB_TARGET} PUBLIC
# ${TINYUSB_CONFIG_TARGET}
# )