-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
74 lines (60 loc) · 2.83 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
cmake_minimum_required(VERSION 3.21)
add_library(drivers INTERFACE)
function(add_driver NAME)
if (NOT TARGET driver_${NAME})
# Choosing not to add LIB_HARDWARE_ defines to avoid command line bloat pending a need (they aren't
# super interesting except to determine functionality as they are mostly passive accessors, however
# they could be useful to determine if the header is available.
# pico_add_sdk_impl_library(driver_${NAME})
add_library(driver_${NAME} INTERFACE)
file(GLOB SOURCES ${CMAKE_CURRENT_LIST_DIR}/Src/*)
target_sources(drivers PUBLIC ${SOURCES})
target_include_directories(driver_${NAME} INTERFACE
${CMAKE_CURRENT_LIST_DIR}/Inc)
target_link_libraries(drivers INTERFACE driver_${NAME})
endif()
endfunction()
option(ENABLE_HAL_DRIVER "Enable HAL driver" ON)
option(ENABLE_LL_DRIVER "Enable LL driver" ON)
option(ENABLE_SYSTEM_XXX_C "Enable system_XXX.c" ON)
option(ENABLE_STARTUP_FILE "Enable startup file" ON)
option(ENABLE_LD_SCRIPT "Enable linker script" ON)
option(ENABLE_DEBUG_DEFINE "Enable debug define" ON)
set(MCU_MODEL "PY32F030x6" CACHE STRING "MCU model, like PY32F030x6")
set(MCU_MODEL_LOWER $<LOWER_CASE:${MCU_MODEL}>)
if("${MCU_MODEL}" MATCHES "PY32F002A|PY32F003|PY32F030")
set(MCU_FAMILY "PY32F0xx")
set(MCU_FAMILY_LOWER $<LOWER_CASE:${MCU_FAMILY}>)
endif()
target_include_directories(drivers INTERFACE CMSIS/Include)
if(${ENABLE_SYSTEM_XXX_C})
target_sources(drivers PUBLIC CMSIS/Device/PY32F0xx/Source/system_${MCU_FAMILY_LOWER}.c)
target_include_directories(drivers INTERFACE CMSIS/Device/PY32F0xx/Include)
endif()
if(${ENABLE_HAL_DRIVER})
add_subdirectory(${MCU_FAMILY}_HAL_Driver)
endif()
if(${ENABLE_LL_DRIVER})
add_subdirectory(${MCU_FAMILY}_LL_Driver)
endif()
# Startup file
if(${ENABLE_STARTUP_FILE})
if("${MCU_MODEL}" MATCHES "PY32F002A")
target_sources(drivers PUBLIC ${CMAKE_CURRENT_LIST_DIR}/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f002a.s)
elseif("${MCU_MODEL}" MATCHES "PY32F003")
target_sources(drivers PUBLIC ${CMAKE_CURRENT_LIST_DIR}/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f003.s)
elseif("${MCU_MODEL}" MATCHES "PY32F030")
target_sources(drivers PUBLIC ${CMAKE_CURRENT_LIST_DIR}/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f030.s)
elseif("${MCU_MODEL}" MATCHES "PY32F002B")
target_sources(drivers PUBLIC ${CMAKE_CURRENT_LIST_DIR}/CMSIS/Device/PY32F0xx/Source/gcc/startup_py32f002b.s)
endif()
endif()
# ld_script
if(${ENABLE_STARTUP_FILE})
set(LINKER_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/LDScripts/${MCU_MODEL_LOWER}.ld)
target_link_options(drivers INTERFACE -T ${LINKER_SCRIPT})
endif()
if(${ENABLE_DEBUG_DEFINE})
target_compile_definitions(drivers INTERFACE -DDEBUG)
endif()
target_compile_definitions(drivers INTERFACE -D${MCU_MODEL})