-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
177 lines (148 loc) · 4.71 KB
/
CMakeLists.txt
File metadata and controls
177 lines (148 loc) · 4.71 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
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
# -----------------------------------------------------------------------------
# @author Auto-generated by STM32CubeIDE for Visual Studio Code Extension
# -----------------------------------------------------------------------------
# @attention
#
# Copyright (c) 2025 STMicroelectronics.
# All rights reserved.
#
# This software is licensed under terms that can be found in the LICENSE file
# in the root directory of this software component.
# If no LICENSE file comes with this software, it is provided AS-IS.
#
# -----------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.20)
#
# This file is generated only once, and is not re-generated.
#
# User is free to modify the file as much as necessary
#
# Core project settings
project("test32")
enable_language(C CXX ASM)
message("Build type: " ${CMAKE_BUILD_TYPE})
# Set default PROJECT_ORIGINAL_NAME if not provided by preset
if(NOT DEFINED PROJECT_ORIGINAL_NAME)
set(PROJECT_ORIGINAL_NAME "${PROJECT_NAME}")
endif()
# Set default CMSIS variables for STM32F103C8T6 if not provided by preset
if(NOT DEFINED CMSIS_Dcore)
set(CMSIS_Dcore "Cortex-M3")
endif()
if(NOT DEFINED CMSIS_Dendian)
set(CMSIS_Dendian "Little-endian")
endif()
# Setup compiler settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
# Core MCU flags, CPU type, instruction set and FPU setup
set(cpu_PARAMS
# Other parameters
# -mthumb
# -mcpu, -mfloat, -mfloat-abi, ...
)
# Sources
set(sources_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/Src/main.c
)
# Include directories for all compilers
set(include_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/Inc
)
# Include directories for each compiler
set(include_c_DIRS)
set(include_cxx_DIRS)
set(include_asm_DIRS)
# Symbols definition for all compilers
set(symbols_SYMB)
# Symbols definition for each compiler
set(symbols_c_SYMB)
set(symbols_cxx_SYMB)
set(symbols_asm_SYMB)
# Link directories and names of libraries
set(link_DIRS)
set(link_LIBS)
# Linker script
set(linker_script_SRC)
# Compiler options
set(compiler_OPTS)
# Linker options
set(linker_OPTS)
# Now call generated cmake
# This will add script generated
# information to the project
include("cmake/vscode_generated.cmake")
# Link directories setup
# Must be before executable is added
link_directories(${CMAKE_PROJECT_NAME} ${link_DIRS})
# Create an executable object type
add_executable(${CMAKE_PROJECT_NAME})
# Add support for blank char as part of project name
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_ORIGINAL_NAME})
# Add sources to executable
target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${sources_SRCS})
# Add include paths
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
${include_DIRS}
$<$<COMPILE_LANGUAGE:C>: ${include_c_DIRS}>
$<$<COMPILE_LANGUAGE:CXX>: ${include_cxx_DIRS}>
$<$<COMPILE_LANGUAGE:ASM>: ${include_asm_DIRS}>
)
# Add project symbols (macros)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
${symbols_SYMB}
$<$<COMPILE_LANGUAGE:C>: ${symbols_c_SYMB}>
$<$<COMPILE_LANGUAGE:CXX>: ${symbols_cxx_SYMB}>
$<$<COMPILE_LANGUAGE:ASM>: ${symbols_asm_SYMB}>
# Configuration specific
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:Release>: >
)
# Add linked libraries
target_link_libraries(${CMAKE_PROJECT_NAME} ${link_LIBS})
# Compiler options
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
${cpu_PARAMS}
${compiler_OPTS}
-Wall
-Wextra
-Wpedantic
-Wno-unused-parameter
$<$<COMPILE_LANGUAGE:C>: >
$<$<COMPILE_LANGUAGE:CXX>:
# -Wno-volatile
# -Wold-style-cast
# -Wuseless-cast
# -Wsuggest-override
>
$<$<COMPILE_LANGUAGE:ASM>:-x assembler-with-cpp -MMD -MP>
$<$<CONFIG:Debug>:-O0 -g3 -ggdb>
$<$<CONFIG:Release>:-Os>
)
# Linker options
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE
-T${linker_script_SRC}
${cpu_PARAMS}
${linker_OPTS}
-Wl,-Map=${PROJECT_ORIGINAL_NAME}.map
-u _printf_float # STDIO float formatting support (remove if not used)
--specs=nosys.specs
-Wl,--start-group
-lc
-lm
-lstdc++
-lsupc++
-Wl,--end-group
-Wl,-z,max-page-size=8 # Allow good software remapping across address space (with proper GCC section making)
-Wl,--print-memory-usage
)
# Execute post-build to print size, generate hex and bin
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${CMAKE_PROJECT_NAME}>
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${PROJECT_ORIGINAL_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${PROJECT_ORIGINAL_NAME}.bin
)