-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
147 lines (128 loc) · 4.07 KB
/
CMakeLists.txt
File metadata and controls
147 lines (128 loc) · 4.07 KB
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
cmake_minimum_required(VERSION 3.13)
# Choose the target platform (must be set before project())
set(PLATFORM "mock" CACHE STRING "Platform implementation (mock, pico, stm32)")
# Default to Pico 1
if(PLATFORM STREQUAL "pico" AND NOT DEFINED PICO_BOARD_TYPE)
set(PICO_BOARD_TYPE "pico")
message(STATUS "PICO_BOARD_TYPE unspecified, defaulting to 'pico'")
endif()
# Disallow bad combinations
if(NOT PLATFORM STREQUAL "pico" AND NOT "${PICO_BOARD_TYPE}" STREQUAL "")
message(FATAL_ERROR "PICO_BOARD_TYPE should only be set when PLATFORM=pico")
endif()
# Block native.cmake for embedded platforms
if ((NOT PLATFORM STREQUAL "mock") AND (CMAKE_TOOLCHAIN_FILE MATCHES "native.cmake"))
message(FATAL_ERROR
"The 'native.cmake' toolchain is only valid for PLATFORM=mock.\n"
"Please remove -DCMAKE_TOOLCHAIN_FILE or use the correct embedded toolchain.")
endif()
# Automatically selects native toolchain for mock builds.
# Do NOT set CMAKE_TOOLCHAIN_FILE manually from the build script.
if(PLATFORM STREQUAL "mock")
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE OR CMAKE_TOOLCHAIN_FILE STREQUAL "")
message(STATUS "Using native toolchain for mock platform")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/toolchain/native.cmake" CACHE FILEPATH "Toolchain file for mock" FORCE)
endif()
endif()
# Only include Pico SDK if platform is Pico
if(PLATFORM STREQUAL "pico")
include(pico_sdk_import.cmake)
endif()
project(TinyGCalc C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
message(STATUS "Target platform: ${PLATFORM}")
if(PLATFORM STREQUAL "pico")
message(STATUS "Pico board type: ${PICO_BOARD_TYPE}")
endif()
# Core application sources
set(SRC_FILES
src/main.c
src/core/eqlist.c
src/core/font6x8.c
src/core/plotter.c
src/core/repl.c
src/core/ui/eqedit.c
src/core/ui/plot.c
src/core/ui/text.c
src/core/ui/settings.c
src/core/utils/display.c
src/core/utils/graph.c
src/core/utils/trig.c
lib/tinyexpr/tinyexpr.c
)
# Platform-specific sources and config
if(PLATFORM STREQUAL "pico")
set(PICO_BOARD ${PICO_BOARD_TYPE})
set(PICO_DEFAULT_BOOT_STAGE2_FILE "${PICO_SDK_PATH}/src/rp2040/boot_stage2/boot2_w25q080.S")
pico_sdk_init()
list(APPEND SRC_FILES
#src/platform/pico/hal_display_st7789.c
src/platform/pico/hal_display_sh1106.c
src/platform/pico/hal_input.c
src/platform/pico/hal_time.c
src/platform/pico/hal_serial.c
)
elseif(PLATFORM STREQUAL "stm32")
list(APPEND SRC_FILES
src/platform/stm32/hal_display.c
)
elseif(PLATFORM STREQUAL "mock")
list(APPEND SRC_FILES
src/platform/mock/hal_display.c
src/platform/mock/hal_input.c
src/platform/mock/hal_time.c
src/platform/mock/hal_serial.c
)
set(SDL2_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/lib/SDL2")
list(APPEND EXTRA_LIBS SDL2)
else()
message(FATAL_ERROR "Unknown platform: ${PLATFORM}")
endif()
# Define the target
add_executable(tinygcalc ${SRC_FILES})
# Stop shortening enums on the mock platform so SDL2 doesn't break
if(PLATFORM STREQUAL "mock")
target_compile_options(tinygcalc PRIVATE
$<$<STREQUAL:${PLATFORM},mock>:-fno-short-enums>
)
endif()
# Target-specific includes
target_include_directories(tinygcalc PRIVATE
src
src/core
src/hal
lib/tinyexpr
src/platform/${PLATFORM}
)
# Link platform-specific libraries
if(PLATFORM STREQUAL "pico")
target_link_libraries(tinygcalc
pico_stdlib
pico_time
pico_stdio_usb
# pico_stdio_uart
hardware_spi
hardware_i2c
hardware_gpio
hardware_dma
)
pico_add_extra_outputs(tinygcalc)
if (PICOTOOL_EXECUTABLE)
# Create UF2 from ELF using system-installed picotool
add_custom_command(
TARGET tinygcalc POST_BUILD
COMMAND ${PICOTOOL_EXECUTABLE} uf2 convert $<TARGET_FILE:tinygcalc>
$<TARGET_FILE_DIR:tinygcalc>/tinygcalc.uf2
COMMENT "Generating tinygcalc.uf2 using system picotool"
)
# Add it as a build target so it appears in IDEs or ALL builds
add_custom_target(tinygcalc_uf2 ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tinygcalc.uf2
)
endif()
elseif(DEFINED EXTRA_LIBS)
target_include_directories(tinygcalc PRIVATE "${SDL2_ROOT}/include")
target_link_directories(tinygcalc PRIVATE "${SDL2_ROOT}/lib")
target_link_libraries(tinygcalc ${EXTRA_LIBS})
endif()