-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
167 lines (138 loc) · 5.01 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
# Minimum CMake version here is the one that apt installs on the raspberry pi.
cmake_minimum_required(VERSION 3.13.4)
# Project declaration
project(obc_firmware)
# Target options
option(UOS3_TARGET_TOBC "If set the build shall target the TOBC board" OFF)
option(UOS3_TARGET_LAUNCHPAD "If set the build shall target the TM4C Launchpad board" OFF)
# If either of those are set add defines and set the TARGET_TM4C, so that
# there's a simple way of telling if we're running on a TM4C or not
if(${UOS3_TARGET_TOBC})
set(UOS3_TARGET_TM4C ON)
add_definitions(-DTARGET_TM4C_TOBC)
elseif(${UOS3_TARGET_LAUNCHPAD})
set(UOS3_TARGET_TM4C ON)
add_definitions(-DTARGET_TM4C_LAUNCHPAD)
endif()
# Option to enable test building or not
option(UOS3_BUILD_TESTS "If set tests will be built" OFF)
# Include the config file names
include(config/default_config_files.cmake)
# Define a copy of add_executable, which will copy the backup config file to
# the binary's dir. This is required as the linker will look for this file.
function (add_executable _name)
_add_executable(${ARGV})
if (TARGET ${_name})
add_custom_command(TARGET ${_name} PRE_LINK
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${PROJECT_SOURCE_DIR}/config/${UOS3_BACKUP_CONFIG_FILE_NAME}"
"${CMAKE_CURRENT_BINARY_DIR}/backup_cfg_file"
)
endif()
endfunction()
# Export compile commands so VSCode can use the right definitions
set(CMAKE_EXPORT_COMPILE_COMMANDS "1")
# Set C flags to use all warnings and the GNU-99 standard.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}\
-std=gnu99 \
-O0 \
-Wall \
-Wextra \
-Wpedantic \
-Wswitch-default \
-Wswitch-enum \
-Wduplicated-cond \
-Wconversion \
-Wlogical-op \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wmissing-declarations \
-fno-omit-frame-pointer \
")
# Enable address sanitiser
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS}")
#set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG}")
# If building for the TM4C
if(${UOS3_TARGET_TM4C})
message("")
message("OBC Firmware building for: TM4C")
message("")
# Set the executable suffix to be ".elf", this is to differentiate them
# from those that can actually be executed on the host system (".exe") and
# binaries to be flashed onto the TM4C (".bin")
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
# Set the tm4c define which is used by platform dependent code.
add_definitions(-DTARGET_TM4C)
# CMake file for the TM4C123G, used to specify the custom link script
include(${PROJECT_SOURCE_DIR}/src/link/tm4c123g.cmake)
# Include the tivaware files. Must setup the tivaware symbolic link first,
# see readme for info.
set(TIVAWARE_PATH "${PROJECT_SOURCE_DIR}/tivaware")
include_directories(${TIVAWARE_PATH})
# Single TIVAWARE_LIBS var so linking to tivaware is easy
set(TIVAWARE_LIBS
${TIVAWARE_PATH}/driverlib/gcc/libdriver.a
)
# Set the startup source file location. This must be inclued in the source
# list for all executables that should be run on the TM4C, otherwise the
# ResetISR will not be set and the app won't be able to start.
set(STARTUP_SOURCE
${PROJECT_SOURCE_DIR}/src/tm4c_startup_gcc.c
)
# If building on linux
elseif(UNIX)
message("")
message("OBC Firmware building for: UNIX")
message("")
# Set the executable suffix to be ".exe", this is to show that they can be
# executed on the host system.
set(CMAKE_EXECUTABLE_SUFFIX ".exe")
# Set the unix define
add_definitions(-DTARGET_UNIX)
# Set the C/CXX compilers
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
# Set tivaware libs, startup source, and standard link libs as empty, this
# will result in them not being linked.
set(TIVAWARE_PATH "")
set(TIVAWARE_LIBS )
set(STARTUP_SOURCE )
# If anything else throw an error
else()
message(FATAL_ERROR "OBC Firmware only supports Unix and TM4C targets, please recompile on either Linux or cross-compile for the TOBC MCU")
endif()
# Set the standard link set
set(STANDARD_LINK_LIBS
${TIVAWARE_LIBS}
Kernel
Debug
Board
DataPool
EventManager
Eeprom
MemStoreManager
)
# Set src as an include directory
include_directories(src/)
# Set debug mode define if needed
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG_MODE")
# Add subdirectories, each managed by its own CMakeLists.txt.
# The ordering here is important as subdirs which have dependencies on other
# must be added AFTER those dependencies have been made.
add_subdirectory(src/system/kernel)
add_subdirectory(src/system/data_pool)
add_subdirectory(src/util)
add_subdirectory(src/drivers)
add_subdirectory(src/system)
add_subdirectory(src/components)
add_subdirectory(src/applications)
add_subdirectory(src/demo)
add_subdirectory(src/tools)
add_subdirectory(src/obc_firmware)
# Build the tests if required
if(${UOS3_BUILD_TESTS})
message("")
message("OBC Firmware building tests")
message("")
add_subdirectory(src/test)
endif()