|
| 1 | +message(STATUS "Using CMake version ${CMAKE_VERSION}") |
| 2 | +cmake_minimum_required(VERSION 3.10...${CMAKE_VERSION}) |
| 3 | + |
| 4 | +SET(InfiniTime_DIR "InfiniTime" CACHE PATH "Path to InfiniTime source path to use for simulator") |
| 5 | + |
| 6 | +if(NOT EXISTS ${InfiniTime_DIR}) |
| 7 | + message(FATAL_ERROR "Can't access folder '${InfiniTime_DIR}'. Try `git submodule update --init --recursive` to initialize the git submodule of InfiniTime") |
| 8 | +endif() |
| 9 | +if(NOT EXISTS ${InfiniTime_DIR}/src/libs/lvgl) |
| 10 | + 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") |
| 11 | +endif() |
| 12 | + |
| 13 | +# try to extract the PineTime project version |
| 14 | +file(READ "${InfiniTime_DIR}/CMakeLists.txt" main_cmake) |
| 15 | +string(REGEX MATCH "project\\(pinetime VERSION ([0-9]*\.[0-9]*\.[0-9]*)" _ ${main_cmake}) |
| 16 | +set(PROJECT_VERSION ${CMAKE_MATCH_1}) |
| 17 | +message(STATUS "InfiniTime PROJECT_VERSION extracted: ${PROJECT_VERSION}") |
| 18 | + |
| 19 | +project(InfiniSim VERSION ${PROJECT_VERSION} LANGUAGES C CXX) |
| 20 | +# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html |
| 21 | +string(COMPARE EQUAL "${CMAKE_CXX_STANDARD}" "" no_cmake_cxx_standard_set) |
| 22 | +if(no_cmake_cxx_standard_set) |
| 23 | + set(CMAKE_CXX_STANDARD 17) |
| 24 | + set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 25 | + set(CMAKE_CXX_EXTENSIONS OFF) |
| 26 | + message(STATUS "Using default C++ standard ${CMAKE_CXX_STANDARD}") |
| 27 | +else() |
| 28 | + message(STATUS "Using user specified C++ standard ${CMAKE_CXX_STANDARD}") |
| 29 | +endif() |
| 30 | +set(CMAKE_C_STANDARD 11)#C11 |
| 31 | + |
| 32 | +file(GLOB_RECURSE INCLUDES "lv_drivers/*.h" "${InfiniTime_DIR}/src/libs/lvgl/src/*.h" "./*.h" ) |
| 33 | +file(GLOB_RECURSE SOURCES "lv_drivers/*.c" "${InfiniTime_DIR}/src/libs/lvgl/src/*.c" ) |
| 34 | + |
| 35 | +add_executable(infinisim main.cpp ${SOURCES} ${INCLUDES}) |
| 36 | + |
| 37 | +# add simulator files |
| 38 | +target_sources(infinisim PUBLIC |
| 39 | + sim/displayapp/LittleVgl.h |
| 40 | + sim/displayapp/LittleVgl.cpp |
| 41 | + sim/displayapp/screens/Missing.h |
| 42 | + sim/displayapp/screens/Missing.cpp |
| 43 | + sim/components/battery/BatteryController.h |
| 44 | + sim/components/battery/BatteryController.cpp |
| 45 | + sim/components/ble/AlertNotificationService.h |
| 46 | + sim/components/ble/AlertNotificationService.cpp |
| 47 | + sim/components/ble/MusicService.h |
| 48 | + sim/components/ble/MusicService.cpp |
| 49 | + sim/components/ble/NavigationService.h |
| 50 | + sim/components/ble/NavigationService.cpp |
| 51 | + sim/components/ble/NimbleController.h |
| 52 | + sim/components/ble/NimbleController.cpp |
| 53 | + sim/components/ble/weather/WeatherService.h |
| 54 | + sim/components/ble/weather/WeatherService.cpp |
| 55 | + sim/components/brightness/BrightnessController.h |
| 56 | + sim/components/brightness/BrightnessController.cpp |
| 57 | + sim/components/firmwarevalidator/FirmwareValidator.h |
| 58 | + sim/components/firmwarevalidator/FirmwareValidator.cpp |
| 59 | + sim/components/fs/FS.h |
| 60 | + sim/components/fs/FS.cpp |
| 61 | + sim/components/heartrate/HeartRateController.h |
| 62 | + sim/components/heartrate/HeartRateController.cpp |
| 63 | + sim/components/motion/MotionController.h |
| 64 | + sim/components/motion/MotionController.cpp |
| 65 | + sim/components/motor/MotorController.h |
| 66 | + sim/components/motor/MotorController.cpp |
| 67 | + sim/drivers/Watchdog.h |
| 68 | + sim/drivers/Watchdog.cpp |
| 69 | + sim/drivers/Bma421.h |
| 70 | + sim/drivers/Bma421.cpp |
| 71 | + sim/drivers/Cst816s.h |
| 72 | + sim/drivers/Cst816s.cpp |
| 73 | + sim/drivers/Hrs3300.h |
| 74 | + sim/drivers/Hrs3300.cpp |
| 75 | + sim/drivers/SpiMaster.h |
| 76 | + sim/drivers/SpiMaster.cpp |
| 77 | + sim/drivers/TwiMaster.h |
| 78 | + sim/drivers/TwiMaster.cpp |
| 79 | + sim/drivers/SpiNorFlash.h |
| 80 | + sim/drivers/SpiNorFlash.cpp |
| 81 | + sim/heartratetask/HeartRateTask.h |
| 82 | + sim/heartratetask/HeartRateTask.cpp |
| 83 | + # FreeRTOS |
| 84 | + sim/FreeRTOS.h |
| 85 | + sim/FreeRTOS.cpp |
| 86 | + sim/task.h |
| 87 | + sim/task.cpp |
| 88 | + sim/timers.h |
| 89 | + sim/timers.cpp |
| 90 | + sim/queue.h |
| 91 | + sim/queue.cpp |
| 92 | + # src/FreeRTOS |
| 93 | + sim/portmacro_cmsis.h |
| 94 | + sim/portmacro_cmsis.cpp |
| 95 | + # nrf |
| 96 | + sim/libraries/log/nrf_log.h |
| 97 | + sim/libraries/delay/nrf_delay.h |
| 98 | + sim/libraries/delay/nrf_delay.cpp |
| 99 | + sim/nrfx/nrfx_log.h |
| 100 | + sim/nrfx/drivers/include/nrfx_twi.h |
| 101 | + sim/nrfx/hal/nrf_gpio.h |
| 102 | + sim/nrfx/hal/nrf_gpio.cpp |
| 103 | + sim/nrfx/hal/nrfx_gpiote.h # includes hal/nrf_gpio.h |
| 104 | + sim/nrfx/hal/nrf_rtc.h |
| 105 | + sim/nrfx/hal/nrf_rtc.cpp |
| 106 | + # nrf/components/libraries/timer |
| 107 | + sim/libraries/timer/app_timer.h |
| 108 | + sim/libraries/timer/app_timer.cpp |
| 109 | + sim/libraries/gpiote/app_gpiote.h # includes hal/nrf_gpio.h |
| 110 | + ) |
| 111 | +target_include_directories(infinisim PRIVATE "sim") |
| 112 | +target_include_directories(infinisim PRIVATE "sim/libraries/log") # for nrf_log.h |
| 113 | +target_include_directories(infinisim PRIVATE "sim/libraries/timer") # for app_timer.h |
| 114 | +target_include_directories(infinisim PRIVATE "sim/nrfx") # for nrfx_log.h and others |
| 115 | +target_include_directories(infinisim PRIVATE "sim/nrfx/hal") # for nrfx_log.h |
| 116 | + |
| 117 | +target_compile_definitions(infinisim PRIVATE LV_CONF_INCLUDE_SIMPLE) |
| 118 | +target_sources(infinisim PUBLIC |
| 119 | + # LVGL Fonts |
| 120 | + ${InfiniTime_DIR}/src/libs/lvgl/src/lv_font/lv_font_montserrat_14.c |
| 121 | + ${InfiniTime_DIR}/src/libs/lvgl/src/lv_font/lv_font_montserrat_18.c |
| 122 | + ${InfiniTime_DIR}/src/libs/lvgl/src/lv_font/lv_font_montserrat_22.c |
| 123 | + ${InfiniTime_DIR}/src/libs/lvgl/src/lv_font/lv_font_montserrat_28.c |
| 124 | + |
| 125 | + ${InfiniTime_DIR}/src/displayapp/fonts/lv_font_navi_80.c |
| 126 | + |
| 127 | + ${InfiniTime_DIR}/src/displayapp/fonts/jetbrains_mono_extrabold_compressed.c |
| 128 | + ${InfiniTime_DIR}/src/displayapp/fonts/jetbrains_mono_bold_20.c |
| 129 | + ${InfiniTime_DIR}/src/displayapp/fonts/jetbrains_mono_76.c |
| 130 | + ${InfiniTime_DIR}/src/displayapp/fonts/jetbrains_mono_42.c |
| 131 | + ${InfiniTime_DIR}/src/displayapp/fonts/lv_font_sys_48.c |
| 132 | + ${InfiniTime_DIR}/src/displayapp/fonts/open_sans_light.c |
| 133 | +) |
| 134 | + |
| 135 | +target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") |
| 136 | +target_include_directories(infinisim PRIVATE "${InfiniTime_DIR}/src/libs") |
| 137 | +target_include_directories(infinisim PRIVATE "lv_drivers") |
| 138 | + |
| 139 | +# add dates library |
| 140 | +target_include_directories(infinisim SYSTEM PRIVATE "${InfiniTime_DIR}/src/libs/date/includes") |
| 141 | + |
| 142 | +# add Screens with a globbing expression, to enable easier CI test-runs for PRs adding new Screens |
| 143 | +file(GLOB InfiniTime_SCREENS |
| 144 | + "${InfiniTime_DIR}/src/displayapp/screens/*.h" |
| 145 | + "${InfiniTime_DIR}/src/displayapp/screens/*.cpp" |
| 146 | + "${InfiniTime_DIR}/src/displayapp/screens/settings/*.h" |
| 147 | + "${InfiniTime_DIR}/src/displayapp/screens/settings/*.cpp" |
| 148 | +) |
| 149 | +target_sources(infinisim PUBLIC ${InfiniTime_SCREENS}) |
| 150 | + |
| 151 | +# add files directly from InfiniTime sources |
| 152 | +target_include_directories(infinisim PRIVATE "${InfiniTime_DIR}/src") |
| 153 | +target_sources(infinisim PUBLIC |
| 154 | + ${InfiniTime_DIR}/src/BootloaderVersion.h |
| 155 | + ${InfiniTime_DIR}/src/BootloaderVersion.cpp |
| 156 | + ${InfiniTime_DIR}/src/displayapp/Colors.h |
| 157 | + ${InfiniTime_DIR}/src/displayapp/Colors.cpp |
| 158 | + ${InfiniTime_DIR}/src/displayapp/DisplayApp.h |
| 159 | + ${InfiniTime_DIR}/src/displayapp/DisplayApp.cpp |
| 160 | + ${InfiniTime_DIR}/src/displayapp/lv_pinetime_theme.h |
| 161 | + ${InfiniTime_DIR}/src/displayapp/lv_pinetime_theme.c |
| 162 | + ${InfiniTime_DIR}/src/displayapp/icons/bg_clock.c # used by WatchFaceAnalog.cpp |
| 163 | + ${InfiniTime_DIR}/src/buttonhandler/ButtonHandler.h |
| 164 | + ${InfiniTime_DIR}/src/buttonhandler/ButtonHandler.cpp |
| 165 | + ${InfiniTime_DIR}/src/components/alarm/AlarmController.h |
| 166 | + ${InfiniTime_DIR}/src/components/alarm/AlarmController.cpp |
| 167 | + ${InfiniTime_DIR}/src/components/ble/BleController.h |
| 168 | + ${InfiniTime_DIR}/src/components/ble/BleController.cpp |
| 169 | + ${InfiniTime_DIR}/src/components/datetime/DateTimeController.h |
| 170 | + ${InfiniTime_DIR}/src/components/datetime/DateTimeController.cpp |
| 171 | + ${InfiniTime_DIR}/src/components/settings/Settings.h |
| 172 | + ${InfiniTime_DIR}/src/components/settings/Settings.cpp |
| 173 | + ${InfiniTime_DIR}/src/components/ble/NotificationManager.h |
| 174 | + ${InfiniTime_DIR}/src/components/ble/NotificationManager.cpp |
| 175 | + ${InfiniTime_DIR}/src/components/timer/TimerController.h |
| 176 | + ${InfiniTime_DIR}/src/components/timer/TimerController.cpp |
| 177 | + ${InfiniTime_DIR}/src/drivers/PinMap.h |
| 178 | + ${InfiniTime_DIR}/src/drivers/Spi.h |
| 179 | + ${InfiniTime_DIR}/src/drivers/Spi.cpp |
| 180 | + ${InfiniTime_DIR}/src/drivers/St7789.h |
| 181 | + ${InfiniTime_DIR}/src/drivers/St7789.cpp |
| 182 | + ${InfiniTime_DIR}/src/touchhandler/TouchHandler.h |
| 183 | + ${InfiniTime_DIR}/src/touchhandler/TouchHandler.cpp |
| 184 | + ${InfiniTime_DIR}/src/systemtask/SystemTask.h |
| 185 | + ${InfiniTime_DIR}/src/systemtask/SystemTask.cpp |
| 186 | +) |
| 187 | + |
| 188 | + |
| 189 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
| 190 | +# Special case for SDL2 dependency, goal is to find a config that exports SDL2::SDL2 target |
| 191 | +# libsdl2-dev has a `sdl2-config.cmake` that doesn't export this, but vcpkg does.. |
| 192 | +find_package(SDL2 CONFIG QUIET) |
| 193 | +if(NOT TARGET SDL2::SDL2) |
| 194 | + find_package(SDL2 MODULE REQUIRED) |
| 195 | +endif() |
| 196 | +target_link_libraries(infinisim PRIVATE SDL2::SDL2) |
| 197 | + |
| 198 | +# Get the latest abbreviated commit hash of the working branch |
| 199 | +execute_process( |
| 200 | + COMMAND ${GIT_EXECUTABLE} log -1 --format=%h |
| 201 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 202 | + OUTPUT_VARIABLE PROJECT_GIT_COMMIT_HASH |
| 203 | + OUTPUT_STRIP_TRAILING_WHITESPACE |
| 204 | +) |
| 205 | +set(VERSION_EDIT_WARNING "// Do not edit this file, it is automatically generated by CMAKE!") |
| 206 | +configure_file("${InfiniTime_DIR}/src/Version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/Version.h") |
| 207 | + |
| 208 | +target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") |
0 commit comments