-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathCMakeLists.txt
180 lines (159 loc) · 6.03 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
cmake_minimum_required(VERSION 3.5)
set(srcs
src/md5_hash.c
src/esp_loader.c
)
set(defs)
# Regular CMake builds are expected to set OPTION_NAME, while ESP-IDF's Kconfig system sets
# CONFIG_OPTION_NAME.
# This macro handles these differences and also a default value if neither is set
macro(add_option option_name default_value)
if (DEFINED CONFIG_${option_name})
# Handle Kconfig booleans in a special manner
if (CONFIG_${option_name} STREQUAL "")
list(APPEND defs ${option_name}=false)
elseif(CONFIG_${option_name} STREQUAL "y")
list(APPEND defs ${option_name}=true)
else()
list(APPEND defs ${option_name}=${CONFIG_${option_name}})
endif()
elseif (DEFINED ${option_name})
list(APPEND defs ${option_name}=${${option_name}})
else()
list(APPEND defs ${option_name}=${default_value})
endif()
endmacro()
add_option(SERIAL_FLASHER_DEBUG_TRACE false)
add_option(SERIAL_FLASHER_RESET_HOLD_TIME_MS 100)
add_option(SERIAL_FLASHER_BOOT_HOLD_TIME_MS 50)
add_option(SERIAL_FLASHER_WRITE_BLOCK_RETRIES 3)
# Enforce default interface for non-ESP ports.
# This doesn't need to be done for the ESP port as the Kconfig system handles the default.
if (NOT DEFINED ESP_PLATFORM AND
NOT DEFINED SERIAL_FLASHER_INTERFACE_UART AND
NOT DEFINED SERIAL_FLASHER_INTERFACE_SPI AND
NOT DEFINED SERIAL_FLASHER_INTERFACE_USB AND
NOT DEFINED SERIAL_FLASHER_INTERFACE_SDIO)
set(SERIAL_FLASHER_INTERFACE_UART true)
endif()
if (DEFINED SERIAL_FLASHER_INTERFACE_UART OR CONFIG_SERIAL_FLASHER_INTERFACE_UART STREQUAL "y")
list(APPEND srcs
src/esp_targets.c
src/esp_stubs.c
src/protocol_serial.c
src/protocol_uart.c
src/slip.c
)
list(APPEND defs
SERIAL_FLASHER_INTERFACE_UART
)
if (DEFINED MD5_ENABLED OR CONFIG_SERIAL_FLASHER_MD5_ENABLED)
list(APPEND defs MD5_ENABLED=1)
endif()
add_option(SERIAL_FLASHER_RESET_INVERT false)
add_option(SERIAL_FLASHER_BOOT_INVERT false)
elseif(DEFINED SERIAL_FLASHER_INTERFACE_USB OR CONFIG_SERIAL_FLASHER_INTERFACE_USB STREQUAL "y")
list(APPEND srcs
src/esp_targets.c
src/esp_stubs.c
src/protocol_serial.c
src/protocol_uart.c
src/slip.c
)
list(APPEND defs
SERIAL_FLASHER_INTERFACE_USB
)
if (DEFINED MD5_ENABLED OR CONFIG_SERIAL_FLASHER_MD5_ENABLED)
list(APPEND defs MD5_ENABLED=1)
endif()
elseif(DEFINED SERIAL_FLASHER_INTERFACE_SPI OR CONFIG_SERIAL_FLASHER_INTERFACE_SPI STREQUAL "y")
list(APPEND srcs
src/esp_targets.c
src/protocol_serial.c
src/protocol_spi.c
)
list(APPEND defs
SERIAL_FLASHER_INTERFACE_SPI
)
elseif(DEFINED SERIAL_FLASHER_INTERFACE_SDIO OR CONFIG_SERIAL_FLASHER_INTERFACE_SDIO STREQUAL "y")
list(APPEND srcs
src/protocol_sdio.c
)
list(APPEND defs
SERIAL_FLASHER_INTERFACE_SDIO
)
endif()
if (DEFINED ESP_PLATFORM)
if (${CONFIG_SERIAL_FLASHER_INTERFACE_UART})
list(APPEND srcs
port/esp32_port.c
)
elseif (${CONFIG_SERIAL_FLASHER_INTERFACE_SPI})
list(APPEND srcs
port/esp32_spi_port.c
)
elseif (${CONFIG_SERIAL_FLASHER_INTERFACE_USB})
list(APPEND srcs
port/esp32_usb_cdc_acm_port.c
)
elseif (${CONFIG_SERIAL_FLASHER_INTERFACE_SDIO})
list(APPEND srcs
port/esp32_sdio_port.c
)
endif()
# Register component to esp-idf build system
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS include port
PRIV_INCLUDE_DIRS private_include
PRIV_REQUIRES driver esp_timer sdmmc)
if (${CONFIG_SERIAL_FLASHER_INTERFACE_USB})
idf_component_set_property(${COMPONENT_NAME} PRIV_REQUIRES usb APPEND)
endif()
set(target ${COMPONENT_LIB})
component_compile_options(-Wstrict-prototypes)
else()
# Create traditional CMake target
add_library(flasher ${srcs})
target_include_directories(flasher PUBLIC include port PRIVATE private_include)
if (NOT DEFINED PORT)
message(WARNING "No port selected, default to user-defined")
set(PORT "USER_DEFINED")
elseif(PORT STREQUAL "USER_DEFINED")
# The user has to manually link their port with the flasher target
elseif(PORT STREQUAL "STM32")
stm32_get_chip_info(${STM32_CHIP} FAMILY DEVICE_FAMILY DEVICE DEVICE_CODE)
if(DEFINED CORE_USED)
string(APPEND DEVICE_FAMILY ::${CORE_USED})
string(APPEND DEVICE_CODE ::${CORE_USED})
endif()
target_link_libraries(flasher PRIVATE
HAL::STM32::${DEVICE_FAMILY}::GPIO
HAL::STM32::${DEVICE_FAMILY}::UART
CMSIS::STM32::${DEVICE_CODE}
)
target_sources(flasher PRIVATE port/stm32_port.c)
elseif(PORT STREQUAL "RASPBERRY_PI")
find_library(pigpio_LIB pigpio)
target_link_libraries(flasher PUBLIC ${pigpio_LIB})
target_sources(flasher PRIVATE port/raspberry_port.c)
elseif(PORT STREQUAL "PI_PICO")
target_link_libraries(flasher PUBLIC pico_stdlib)
target_sources(flasher PRIVATE port/pi_pico_port.c)
else()
message(FATAL_ERROR "Selected port is not supported")
endif()
set(target flasher)
endif()
target_compile_definitions(${target} PUBLIC ${defs})
# This segment pulls the flasher stubs at a specified version at wish, and generates the
# esp_stubs.c/h files, overwriting the library provided ones.
# It is also possible to override stub generation to use a custom url or a local folder.
# Please check if the license under which the custom stub sources are released fits your usecase.
if (DEFINED SERIAL_FLASHER_STUB_PULL_VERSION OR DEFINED SERIAL_FLASHER_STUB_PULL_OVERRIDE_PATH)
include(cmake/serial_flasher_pull_stubs.cmake)
serial_flasher_pull_stubs(
VERSION ${SERIAL_FLASHER_STUB_PULL_VERSION}
SOURCE ${SERIAL_FLASHER_STUB_PULL_SOURCE}
PATH_OVERRIDE ${SERIAL_FLASHER_STUB_PULL_OVERRIDE_PATH}
)
endif()