forked from InfiniTimeOrg/InfiniSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
293 lines (270 loc) · 12.5 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
message(STATUS "Using CMake version ${CMAKE_VERSION}")
cmake_minimum_required(VERSION 3.10...${CMAKE_VERSION})
SET(InfiniTime_DIR "${CMAKE_SOURCE_DIR}/InfiniTime" CACHE PATH "Path to InfiniTime source path to use for simulator")
if(NOT EXISTS ${InfiniTime_DIR})
message(FATAL_ERROR "Can't access folder '${InfiniTime_DIR}'. Try `git submodule update --init --recursive` to initialize the git submodule of InfiniTime")
endif()
if(NOT EXISTS ${InfiniTime_DIR}/src/libs/lvgl)
message(FATAL_ERROR "Can't access folder '${InfiniTime_DIR}/src/libs/lvgl'. Try `git submodule update --init --recursive` to initialize the git submodule of lvgl inside InfiniTime")
endif()
# try to extract the PineTime project version
file(READ "${InfiniTime_DIR}/CMakeLists.txt" main_cmake)
string(REGEX MATCH "project\\(pinetime VERSION ([0-9]*\.[0-9]*\.[0-9]*)" _ ${main_cmake})
set(PROJECT_VERSION ${CMAKE_MATCH_1})
message(STATUS "InfiniTime PROJECT_VERSION extracted: ${PROJECT_VERSION}")
project(InfiniSim VERSION ${PROJECT_VERSION} LANGUAGES C CXX)
# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html
string(COMPARE EQUAL "${CMAKE_CXX_STANDARD}" "" no_cmake_cxx_standard_set)
if(no_cmake_cxx_standard_set)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "Using default C++ standard ${CMAKE_CXX_STANDARD}")
else()
message(STATUS "Using user specified C++ standard ${CMAKE_CXX_STANDARD}")
endif()
set(CMAKE_C_STANDARD 11)#C11
# copy lv_conf.h from InfiniTime project and do little modifications
file(READ "${InfiniTime_DIR}/src/libs/lv_conf.h" lv_conf_main)
# set '#define LV_TICK_CUSTOM 0'
string(REGEX REPLACE "#define[ ]+LV_TICK_CUSTOM[ ]+1" "#define LV_TICK_CUSTOM 0" lv_conf_main "${lv_conf_main}")
# allow more memory in debug mode for the simulator
#define LV_MEM_SIZE (14U * 1024U)
string(REGEX REPLACE "#define[ ]+LV_MEM_SIZE[ ]+\\([^\)]*\\)"
"#ifdef NDEBUG
#define LV_MEM_SIZE (14U * 1024U)
#else // debug mode -> allow more memory
#define LV_MEM_SIZE (28U * 1024U)
#endif"
lv_conf_main "${lv_conf_main}")
# write to temporary file and overwrite file to use only if lv_conf changed to keep useless recompiles
# at a minimum
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/lv_conf_modified.h" "${lv_conf_main}")
configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/lv_conf_modified.h"
"${CMAKE_CURRENT_BINARY_DIR}/lv_conf.h"
COPYONLY)
file(GLOB_RECURSE INCLUDES "lv_drivers/*.h" "${InfiniTime_DIR}/src/libs/lvgl/src/*.h" "./*.h" )
file(GLOB_RECURSE SOURCES "lv_drivers/*.c" "${InfiniTime_DIR}/src/libs/lvgl/src/*.c" )
add_executable(infinisim main.cpp ${SOURCES} ${INCLUDES})
set(MONITOR_ZOOM 1 CACHE STRING "Scale simulator window by this factor")
if(MONITOR_ZOOM MATCHES "^[0-9]\.?[0-9]*")
message(STATUS "Using MONITOR_ZOOM=${MONITOR_ZOOM}")
target_compile_definitions(infinisim PRIVATE MONITOR_ZOOM=${MONITOR_ZOOM})
else()
message(FATAL_ERROR "variable MONITOR_ZOOM=${MONITOR_ZOOM} must be a positive number")
endif()
# include the generated lv_conf.h file before anything else
target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
# add simulator files
target_sources(infinisim PUBLIC
sim/displayapp/LittleVgl.h
sim/displayapp/LittleVgl.cpp
sim/displayapp/screens/Missing.h
sim/displayapp/screens/Missing.cpp
sim/components/battery/BatteryController.h
sim/components/battery/BatteryController.cpp
sim/components/ble/AlertNotificationService.h
sim/components/ble/AlertNotificationService.cpp
sim/components/ble/MusicService.h
sim/components/ble/MusicService.cpp
sim/components/ble/NavigationService.h
sim/components/ble/NavigationService.cpp
sim/components/ble/NimbleController.h
sim/components/ble/NimbleController.cpp
sim/components/ble/weather/WeatherService.h
sim/components/ble/weather/WeatherService.cpp
sim/components/brightness/BrightnessController.h
sim/components/brightness/BrightnessController.cpp
sim/components/firmwarevalidator/FirmwareValidator.h
sim/components/firmwarevalidator/FirmwareValidator.cpp
sim/components/heartrate/HeartRateController.h
sim/components/heartrate/HeartRateController.cpp
sim/components/motion/MotionController.h
sim/components/motion/MotionController.cpp
sim/drivers/Watchdog.h
sim/drivers/Watchdog.cpp
sim/drivers/Bma421.h
sim/drivers/Bma421.cpp
sim/drivers/Cst816s.h
sim/drivers/Cst816s.cpp
sim/drivers/Hrs3300.h
sim/drivers/Hrs3300.cpp
sim/drivers/SpiMaster.h
sim/drivers/SpiMaster.cpp
sim/drivers/TwiMaster.h
sim/drivers/TwiMaster.cpp
sim/drivers/SpiNorFlash.h
sim/drivers/SpiNorFlash.cpp
sim/heartratetask/HeartRateTask.h
sim/heartratetask/HeartRateTask.cpp
# FreeRTOS
sim/FreeRTOS.h
sim/FreeRTOS.cpp
sim/task.h
sim/task.cpp
sim/timers.h
sim/timers.cpp
sim/queue.h
sim/queue.cpp
# src/FreeRTOS
sim/portmacro_cmsis.h
sim/portmacro_cmsis.cpp
# nrf
sim/libraries/log/nrf_log.h
sim/libraries/delay/nrf_delay.h
sim/libraries/delay/nrf_delay.cpp
sim/nrfx/nrfx_log.h
sim/nrfx/drivers/include/nrfx_twi.h
sim/nrfx/hal/nrf_gpio.h
sim/nrfx/hal/nrf_gpio.cpp
sim/nrfx/hal/nrfx_gpiote.h # includes hal/nrf_gpio.h
sim/nrfx/hal/nrf_rtc.h
sim/nrfx/hal/nrf_rtc.cpp
# nrf/components/libraries/timer
sim/libraries/timer/app_timer.h
sim/libraries/timer/app_timer.cpp
sim/libraries/gpiote/app_gpiote.h # includes hal/nrf_gpio.h
)
target_include_directories(infinisim PRIVATE "sim")
target_include_directories(infinisim PRIVATE "sim/libraries/log") # for nrf_log.h
target_include_directories(infinisim PRIVATE "sim/libraries/timer") # for app_timer.h
target_include_directories(infinisim PRIVATE "sim/nrfx") # for nrfx_log.h and others
target_include_directories(infinisim PRIVATE "sim/nrfx/hal") # for nrfx_log.h
target_compile_definitions(infinisim PRIVATE LV_CONF_INCLUDE_SIMPLE)
target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(infinisim PRIVATE "${InfiniTime_DIR}/src/libs")
target_include_directories(infinisim PRIVATE "lv_drivers")
# add dates library
target_include_directories(infinisim SYSTEM PRIVATE "${InfiniTime_DIR}/src/libs/date/includes")
# add Screens, fonts and icons with a globbing expression,
# to enable easier CI test-runs for PRs adding new Screens/Fonts/Icons
file(GLOB InfiniTime_SCREENS
"${InfiniTime_DIR}/src/displayapp/screens/*.h"
"${InfiniTime_DIR}/src/displayapp/screens/*.cpp"
"${InfiniTime_DIR}/src/displayapp/screens/settings/*.h"
"${InfiniTime_DIR}/src/displayapp/screens/settings/*.cpp"
)
file(GLOB InfiniTime_FONTS
"${InfiniTime_DIR}/src/displayapp/fonts/*.c"
)
file(GLOB InfiniTime_ICONS
"${InfiniTime_DIR}/src/displayapp/icons/*.c"
)
file(GLOB InfiniTime_WIDGETS
"${InfiniTime_DIR}/src/displayapp/widgets/*.cpp"
"${InfiniTime_DIR}/src/displayapp/widgets/*.h"
)
set(LITTLEFS_SRC
${InfiniTime_DIR}/src/libs/littlefs/lfs_util.h
${InfiniTime_DIR}/src/libs/littlefs/lfs.h
${InfiniTime_DIR}/src/libs/littlefs/lfs_util.c
${InfiniTime_DIR}/src/libs/littlefs/lfs.c
)
target_sources(infinisim PUBLIC ${InfiniTime_SCREENS})
target_sources(infinisim PUBLIC ${InfiniTime_FONTS})
target_sources(infinisim PUBLIC ${InfiniTime_ICONS})
target_sources(infinisim PUBLIC ${InfiniTime_WIDGETS})
target_sources(infinisim PUBLIC ${LITTLEFS_SRC})
# add files directly from InfiniTime sources
target_include_directories(infinisim PRIVATE "${InfiniTime_DIR}/src")
target_include_directories(infinisim PRIVATE "${InfiniTime_DIR}/src/libs/littlefs")
target_sources(infinisim PUBLIC
${InfiniTime_DIR}/src/BootloaderVersion.h
${InfiniTime_DIR}/src/BootloaderVersion.cpp
${InfiniTime_DIR}/src/displayapp/Colors.h
${InfiniTime_DIR}/src/displayapp/Colors.cpp
${InfiniTime_DIR}/src/displayapp/DisplayApp.h
${InfiniTime_DIR}/src/displayapp/DisplayApp.cpp
${InfiniTime_DIR}/src/displayapp/lv_pinetime_theme.h
${InfiniTime_DIR}/src/displayapp/lv_pinetime_theme.c
${InfiniTime_DIR}/src/displayapp/icons/bg_clock.c # used by WatchFaceAnalog.cpp
${InfiniTime_DIR}/src/buttonhandler/ButtonHandler.h
${InfiniTime_DIR}/src/buttonhandler/ButtonHandler.cpp
${InfiniTime_DIR}/src/components/ctf/CtfController.h
${InfiniTime_DIR}/src/components/ctf/CtfController.cpp
${InfiniTime_DIR}/src/components/alarm/AlarmController.h
${InfiniTime_DIR}/src/components/alarm/AlarmController.cpp
${InfiniTime_DIR}/src/components/ble/BleController.h
${InfiniTime_DIR}/src/components/ble/BleController.cpp
${InfiniTime_DIR}/src/components/datetime/DateTimeController.h
${InfiniTime_DIR}/src/components/datetime/DateTimeController.cpp
${InfiniTime_DIR}/src/components/settings/Settings.h
${InfiniTime_DIR}/src/components/settings/Settings.cpp
${InfiniTime_DIR}/src/components/ble/NotificationManager.h
${InfiniTime_DIR}/src/components/ble/NotificationManager.cpp
${InfiniTime_DIR}/src/components/fs/FS.h
${InfiniTime_DIR}/src/components/fs/FS.cpp
${InfiniTime_DIR}/src/components/motor/MotorController.h
${InfiniTime_DIR}/src/components/motor/MotorController.cpp
${InfiniTime_DIR}/src/components/timer/TimerController.h
${InfiniTime_DIR}/src/components/timer/TimerController.cpp
${InfiniTime_DIR}/src/drivers/PinMap.h
${InfiniTime_DIR}/src/drivers/Spi.h
${InfiniTime_DIR}/src/drivers/Spi.cpp
${InfiniTime_DIR}/src/drivers/St7789.h
${InfiniTime_DIR}/src/drivers/St7789.cpp
${InfiniTime_DIR}/src/touchhandler/TouchHandler.h
${InfiniTime_DIR}/src/touchhandler/TouchHandler.cpp
${InfiniTime_DIR}/src/systemtask/SystemTask.h
${InfiniTime_DIR}/src/systemtask/SystemTask.cpp
${InfiniTime_DIR}/src/systemtask/SystemMonitor.h
${InfiniTime_DIR}/src/systemtask/SystemMonitor.cpp
)
# QCBOR
add_library(QCBOR STATIC
${InfiniTime_DIR}/src/libs/QCBOR/src/ieee754.c
${InfiniTime_DIR}/src/libs/QCBOR/src/qcbor_decode.c
${InfiniTime_DIR}/src/libs/QCBOR/src/qcbor_encode.c
${InfiniTime_DIR}/src/libs/QCBOR/src/qcbor_err_to_str.c
${InfiniTime_DIR}/src/libs/QCBOR/src/UsefulBuf.c)
target_include_directories(QCBOR SYSTEM PUBLIC ${InfiniTime_DIR}/src/libs/QCBOR/inc)
# This is required with the current configuration
target_compile_definitions(QCBOR PUBLIC QCBOR_DISABLE_FLOAT_HW_USE)
# These are for space-saving
target_compile_definitions(QCBOR PUBLIC QCBOR_DISABLE_PREFERRED_FLOAT)
target_compile_definitions(QCBOR PUBLIC QCBOR_DISABLE_EXP_AND_MANTISSA)
target_compile_definitions(QCBOR PUBLIC QCBOR_DISABLE_INDEFINITE_LENGTH_STRINGS)
#target_compile_definitions(QCBOR PUBLIC QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS)
target_compile_definitions(QCBOR PUBLIC QCBOR_DISABLE_UNCOMMON_TAGS)
target_compile_definitions(QCBOR PUBLIC USEFULBUF_CONFIG_LITTLE_ENDIAN)
set_target_properties(QCBOR PROPERTIES LINKER_LANGUAGE C)
#target_compile_options(QCBOR PRIVATE
# $<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -O0 -g3>
# $<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -O3>
# $<$<COMPILE_LANGUAGE:ASM>: -MP -MD -x assembler-with-cpp>
# )
target_link_libraries(infinisim PRIVATE QCBOR)
if(EXISTS ${InfiniTime_DIR}/src/displayapp/fonts/CMakeLists.txt)
# available since https://github.com/InfiniTimeOrg/InfiniTime/pull/1097
message(STATUS "add subdirectory ${InfiniTime_DIR}/src/displayapp/fonts for 'infinitime_fonts' target")
add_subdirectory(${InfiniTime_DIR}/src/displayapp/fonts fonts)
target_link_libraries(infinisim PRIVATE infinitime_fonts)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Special case for SDL2 dependency, goal is to find a config that exports SDL2::SDL2 target
# libsdl2-dev has a `sdl2-config.cmake` that doesn't export this, but vcpkg does..
find_package(SDL2 CONFIG QUIET)
if(NOT TARGET SDL2::SDL2)
find_package(SDL2 MODULE REQUIRED)
endif()
target_link_libraries(infinisim PRIVATE SDL2::SDL2)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PROJECT_GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(VERSION_EDIT_WARNING "// Do not edit this file, it is automatically generated by CMAKE!")
configure_file("${InfiniTime_DIR}/src/Version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/Version.h")
option(WITH_PNG "Compile with libpng support to dump current screen as png" ON)
if(WITH_PNG)
target_compile_definitions(infinisim PRIVATE WITH_PNG)
add_subdirectory(libpng EXCLUDE_FROM_ALL)
target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/libpng")
target_link_libraries(infinisim PRIVATE png_static)
endif()
target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/gif-h")
install(TARGETS infinisim DESTINATION bin)