-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
221 lines (192 loc) · 9.08 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# CMake 3.19 is the first to include presets
# (https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html)
cmake_minimum_required(VERSION 3.20)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
# CMP0135: use the time of archive extraction as timestamp for downloaded files.
# introduced 3.26, prior behavior was to keep the timestamps from the
# downloaded archive which could prevent recompilation.
message(STATUS "set version")
cmake_policy(SET CMP0135 NEW)
else()
message(STATUS "no set version")
endif()
if (NOT DEFINED ENV{PRESET_IN_USE})
message(FATAL_ERROR "Use a preset. Use cmake --list-presets to show available presets.")
endif ()
project("OT3Firmware"
LANGUAGES CXX C ASM
DESCRIPTION "Firmware for OT-3 System")
set(CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/cmake"
"${PROJECT_SOURCE_DIR}/cmake/codecov/cmake"
${CMAKE_MODULE_PATH})
set(ROOT_BOARD_FILE_PATH "${PROJECT_SOURCE_DIR}/include/firmware/" ${ROOT_BOARD_FILE_PATH})
if (NOT ${CMAKE_CROSSCOMPILING})
enable_testing()
add_custom_target(build-and-test)
find_package(codecov)
# We can safely ignore test code and stm32-tools imports
list(APPEND LCOV_REMOVE_PATTERNS
"'${PROJECT_SOURCE_DIR}/stm32-tools/*'"
"'${PROJECT_SOURCE_DIR}/**/tests/*.cpp'"
"'${PROJECT_SOURCE_DIR}/**/simulator/*.cpp'")
else()
function(add_coverage TARGET)
endfunction()
function(coverage_evaluate)
endfunction()
add_custom_target(firmware-images)
add_custom_target(firmware-applications)
endif ()
find_package(Clang)
# Set a default build type if none was specified
# From https://blog.kitware.com/cmake-and-the-default-build-type/
set(default_build_type "RelWithDebInfo")
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"RelWithDebInfo" "Debug" "MinSizeRel")
endif ()
message("Build type is ${CMAKE_BUILD_TYPE}")
if (${CMAKE_CROSSCOMPILING})
find_package(CrossGCC)
find_package(OpenOCD)
add_compile_definitions(ENABLE_CCMRAM)
add_compile_definitions(ENABLE_CROSS_ONLY_HEADERS)
configure_file(common/firmware/platform_specific_hal_conf.h.in ${CMAKE_BINARY_DIR}/generated/platform_specific_hal_conf.h)
configure_file(common/firmware/platform_specific_hal.h.in ${CMAKE_BINARY_DIR}/generated/platform_specific_hal.h)
include_directories(${CMAKE_BINARY_DIR}/generated/)
else ()
find_package(Boost 1.71.0)
endif ()
macro(add_subdir_for_archs)
set(_asfa_options)
set(_asfa_onevalue SUBDIR)
set(_asfa_multivalue ARCHS)
cmake_parse_arguments(_asfa "${_asfa_options}" "${_asfa_onevalue}" "${_asfa_multivalue}" ${ARGN})
if (CMAKE_CROSSCOMPILING)
if(ARM_ARCH_TYPE IN_LIST _asfa_ARCHS)
message(STATUS "Adding ${_asfa_SUBDIR} because arch is ${ARM_ARCH_TYPE} and subdir wants ${_asfa_ARCHS}")
add_subdirectory("${_asfa_SUBDIR}")
else()
message(STATUS "Not adding ${_asfa_SUBDIR} because arch is ${ARM_ARCH_TYPE} and subdir wants ${_asfa_ARCHS}")
endif()
else()
message(STATUS "Adding ${_asfa_SUBDIR} because this is host-compilation")
add_subdirectory("${_asfa_SUBDIR}")
endif()
endmacro()
set(LINT_TARGETS "")
# Common subdirs (ones that don't make end executables) should always be included
add_subdirectory(common)
add_subdirectory(can)
add_subdirectory(spi)
add_subdirectory(i2c)
add_subdirectory(motor-control)
add_subdirectory(sensors)
add_subdirectory(eeprom)
# Subdirs that build cross executables should be added iff they support that
# arch
add_subdir_for_archs(SUBDIR bootloader ARCHS cortex-m4 cortex-m33)
add_subdir_for_archs(SUBDIR rear-panel ARCHS cortex-m4)
add_subdir_for_archs(SUBDIR gantry ARCHS cortex-m4)
add_subdir_for_archs(SUBDIR head ARCHS cortex-m4)
add_subdir_for_archs(SUBDIR gripper ARCHS cortex-m4)
add_subdir_for_archs(SUBDIR pipettes ARCHS cortex-m4 cortex-m33)
add_subdir_for_archs(SUBDIR hepa-uv ARCHS cortex-m4)
list(REMOVE_DUPLICATES LINT_TARGETS)
message(VERBOSE "Checking if cross-compiling.")
if(NOT ${CMAKE_CROSSCOMPILING})
message(VERBOSE "Not cross-compiling. Adding state_manager")
find_package(Poetry 1.3.2)
add_subdirectory(state_manager)
else ()
message(VERBOSE "You are cross-compiling. Not adding state_manager")
endif ()
# c++ linting is here but python linting is in the subdir
file(GLOB_RECURSE SOURCES_FOR_FORMAT
./include/*.hpp
./can/*.hpp ./can/*.cpp
./common/*.hpp ./common/*.cpp
./gantry/*.hpp ./gantry/*.cpp
./pipettes/*.hpp ./pipettes/*.cpp
./head/*.hpp ./head/*.cpp
./motor-control/*.hpp ./motor-control/*.cpp
./gripper/*.hpp ./gripper/*.cpp
./bootloader/*.hpp ./bootloader/*.cpp
./i2c/*.hpp ./i2c/*.cpp
./sensors/*.hpp ./sensors/*.cpp
./spi/*.hpp ./spi/*.cpp
./eeprom/*.hpp ./eeprom/*.cpp ./rear-panel/*.hpp
./rear-panel/*.cpp
./hepa-uv/*.cpp
)
# Targets for formatting. These are here rather than in individual target CMakeLists (e.g.
# the ones in tests/ or firmware/) because they don't have semantic reasoning involved and
# can therefore operate on file globs, unlike lint/static analysis
# Target for use during dev - edits files
add_custom_target(
format
ALL
COMMAND ${Clang_CLANGFORMAT_EXECUTABLE} -style=file -i ${SOURCES_FOR_FORMAT}
)
# Target for use in ci - warnings are errors, doesn't edit files
add_custom_target(
format-ci
COMMAND ${Clang_CLANGFORMAT_EXECUTABLE} -style=file -Werror --ferror-limit=0 -n ${SOURCES_FOR_FORMAT}
)
add_custom_target(
lint
ALL
DEPENDS ${LINT_TARGETS})
# any time we're calling python, we need to do it through the shell to rely on
# the shell's location selection, which is where things like pyenv and virtualenvs
# hook (if you just run python directly, cmake will do this on its own and not look
# at shell configuration)
set(SHELL_FOR_PYTHON "/bin/sh" CACHE STRING "shell to use for calling python (supports pyenv)")
# find the constants.py file. if this doesn't find where you've checked out the monorepo, you
# can override the path in the cmake cache
message(CHECK_START "Finding opentrons_hardware python package")
find_path(OPENTRONS_HARDWARE_PATH
opentrons_hardware.cmakefind
DOC "The location of the opentrons_hardware package containing definitions for canbus header generation"
PATHS ${CMAKE_SOURCE_DIR}/../opentrons $ENV{HOME}/opentrons /opentrons
PATH_SUFFIXES hardware/opentrons_hardware
NO_DEFAULT_PATH)
if (NOT OPENTRONS_HARDWARE_PATH)
message(CHECK_FAIL "not found. You will not be able to generate updated CANbus constant "
"headers, but otherwise everything will work. If you want to be able to generate headers, "
"check out the opentrons monorepo as a sibling to this directory or set the cache variable "
"OPENTRONS_HARDARE_PATH (using a CMake cache editor or by passing "
"-DOPENTRONS_HARDWARE_PATH=/path/to/opentrons_hardware the next time you configure)")
else ()
message(CHECK_PASS
"${OPENTRONS_HARDWARE_PATH}. Update CANbus headers by running cmake --build --preset=<any> --target update-headers")
endif ()
# this code builds in generating a firmware manifest to running cmake --install. it needs to stay last,
# or at least later than all the other install commands, because it depends on their presence to find the
# files to build the manifest for.
#
# however, if you run a build and then run cmake --install, you will get a dist/applications that has a
# manifest and is suited to scp'ing in its entirety to a robot's /usr/lib/firmware/ dir.
add_custom_target(update-headers
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
VERBATIM
COMMAND ${SHELL_FOR_PYTHON} -c "python ./generate_header.py ${CMAKE_SOURCE_DIR}/include/can/core/ids.hpp --source-dir=${OPENTRONS_HARDWARE_PATH} --language=c++ --subsystem=can"
COMMAND ${SHELL_FOR_PYTHON} -c "python ./generate_header.py ${CMAKE_SOURCE_DIR}/include/bootloader/core/ids.h --source-dir=${OPENTRONS_HARDWARE_PATH} --language=c --subsystem=can"
COMMAND ${SHELL_FOR_PYTHON} -c "python ./generate_header.py ${CMAKE_SOURCE_DIR}/include/rear-panel/core/bin_msg_ids.hpp --source-dir=${OPENTRONS_HARDWARE_PATH} --language=c++ --subsystem=rearpanel")
set(_install_cmd "execute_process(\
COMMAND ${SHELL_FOR_PYTHON} -c \"python3 ${CMAKE_SOURCE_DIR}/scripts/subsystem_versions.py\
--prefix=${FIRMWARE_DESTINATION_PREFIX}\
--hex-dir=${CMAKE_INSTALL_PREFIX}/applications\
${CMAKE_INSTALL_PREFIX}/applications/opentrons-firmware.json\"\
COMMAND_ECHO STDOUT\
)")
message(VERBOSE "built manifest command: ${_install_cmd}")
install(
CODE ${_install_cmd}
COMPONENT Applications)
coverage_evaluate()