-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
194 lines (160 loc) · 4.54 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
# SPDX-License-Identifier: GPL-3.0-only
# This file is part of Lazuli.
# Copyright (c) 2020, Remi Andruccioli <[email protected]>
#
# Main CMake file to build the user project.
#
cmake_minimum_required(VERSION 3.12)
set(CMAKE_VERBOSE_MAKEFILE OFF)
add_subdirectory(sys)
# This defines the name of your project as well as its version and the languages
# it uses.
# You are free to change these values according to your project.
project(
LazuliUserProject
LANGUAGES C ASM
VERSION 1.0.0)
# This lists all your source files.
# You are free to add source files according to your project.
set(
LAZULI_USER_SOURCE_FILES
user/main.c)
# This lists the compiler flags used to compile your project.
# You are free to change these flags according to your project.
set(
LAZULI_USER_COMPILE_FLAGS
-Wall
-Wextra
-Werror
-O2
-g
# TODO: Manage this properly
-mmcu=atmega328p)
# The following directives shouldn't be changed by the user
# TODO: maybe think about putting them into another file.
set(
LZ_CONFIG_BUILD_UNIT_TESTS
"null"
CACHE STRING
"Choice of unit tests set to build.")
set_property(
CACHE LZ_CONFIG_BUILD_UNIT_TESTS
PROPERTY STRINGS
"null;unit_tests_1;unit_tests_2;unit_tests_3")
mark_as_advanced(LZ_CONFIG_BUILD_UNIT_TESTS)
set(
LZ_EXAMPLE_PROGRAM
"null"
CACHE STRING
"Choice of example program to build.")
set_property(
CACHE LZ_EXAMPLE_PROGRAM
PROPERTY STRINGS
"null;blink.c;clock24.c;spinlocks.c;mutex.c;mutex_alternating_tasks.c")
if(NOT LZ_CONFIG_BUILD_UNIT_TESTS STREQUAL "null")
set(
LAZULI_USER_SOURCE_FILES
sys/unit-tests/unit_tests_common.c
sys/unit-tests/${LZ_CONFIG_BUILD_UNIT_TESTS}.c)
else()
if(NOT LZ_EXAMPLE_PROGRAM STREQUAL "null")
set(
LAZULI_USER_SOURCE_FILES
example-programs/${LZ_EXAMPLE_PROGRAM})
endif()
endif()
include_directories(
BEFORE
sys/include # For Lazuli headers
sys/libc-headers # For libc headers
sys/libc-headers/arch-dependent/AVR # For arch-specific libc headers
${PROJECT_BINARY_DIR}/sys) # For auto-generated config.h
set(
LAZULI_USER_LINK_FLAGS
-nostartfiles
-nostdlib
-nodefaultlibs
#--gc-sections # This options is invalid when gcc is used as the linker
-T${CMAKE_SOURCE_DIR}/sys/kern/arch/AVR/linker.ld
-T${CMAKE_SOURCE_DIR}/sys/kern/linker.ld)
set(
LAZULI_USER_PROJECT_NAME
${PROJECT_NAME}_${LZ_TARGET_MACHINE_CHOICE}_${CMAKE_PROJECT_VERSION})
add_executable(
${LAZULI_USER_PROJECT_NAME}
${LAZULI_USER_SOURCE_FILES})
set_target_properties(
${LAZULI_USER_PROJECT_NAME}
PROPERTIES LINK_DEPENDS
"${CMAKE_SOURCE_DIR}/sys/kern/arch/AVR/linker.ld;\
${CMAKE_SOURCE_DIR}/sys/kern/linker.ld")
target_link_libraries(
${LAZULI_USER_PROJECT_NAME}
${LAZULI_LIBRARY})
target_compile_options(
${LAZULI_USER_PROJECT_NAME}
PUBLIC
${LAZULI_USER_COMPILE_FLAGS}
-ffreestanding)
target_link_options(
${LAZULI_USER_PROJECT_NAME}
PUBLIC ${LAZULI_USER_LINK_FLAGS})
# Generate disassembly listing.
set(LST_TARGET_NAME lst_output)
add_custom_command(
OUTPUT
${LAZULI_USER_PROJECT_NAME}.lst
COMMAND
${CMAKE_OBJDUMP} -hS ${LAZULI_USER_PROJECT_NAME}
> ${LAZULI_USER_PROJECT_NAME}.lst
DEPENDS
${LAZULI_USER_PROJECT_NAME}
COMMENT "Generating user LST file: ${LAZULI_USER_PROJECT_NAME}.lst"
VERBATIM)
add_custom_target(
${LST_TARGET_NAME}
ALL
DEPENDS ${LAZULI_USER_PROJECT_NAME}.lst)
add_dependencies(${LST_TARGET_NAME} ${LAZULI_USER_PROJECT_NAME})
# Generate HEX output
set(HEX_TARGET_NAME hex_output)
add_custom_command(
OUTPUT
${LAZULI_USER_PROJECT_NAME}.hex
COMMAND
${CMAKE_OBJCOPY}
-j .text
-j .data
-j .rodata
-j .progmem
-O ihex
${LAZULI_USER_PROJECT_NAME}
${LAZULI_USER_PROJECT_NAME}.hex
DEPENDS
${LAZULI_USER_PROJECT_NAME}
COMMENT "Generating user HEX file: ${LAZULI_USER_PROJECT_NAME}.hex"
VERBATIM)
add_custom_target(
${HEX_TARGET_NAME}
ALL
DEPENDS ${LAZULI_USER_PROJECT_NAME}.hex)
add_dependencies(${HEX_TARGET_NAME} ${LAZULI_USER_PROJECT_NAME})
# Extract final binary sections sizes
set(SIZE_TARGET_NAME size_output)
add_custom_command(
OUTPUT
${LAZULI_USER_PROJECT_NAME}.size
COMMAND
${MY_CMAKE_SIZE} -Adt ${LAZULI_USER_PROJECT_NAME}
| ${CMAKE_SOURCE_DIR}/scripts/sizeof_sections.awk
| tee ${LAZULI_USER_PROJECT_NAME}.size
DEPENDS
${LAZULI_USER_PROJECT_NAME}
COMMENT
"Extracting final binary sections sizes: ${LAZULI_USER_PROJECT_NAME}.size"
VERBATIM)
add_custom_target(
${SIZE_TARGET_NAME}
ALL
DEPENDS ${LAZULI_USER_PROJECT_NAME}.size)
add_dependencies(${SIZE_TARGET_NAME} ${LAZULI_USER_PROJECT_NAME})