Skip to content

Commit 04cd3fc

Browse files
authored
chore(build): Switch to cmake as a configuration system (#125)
This PR switches away from raw makefiles as a configuration and build system and uses cmake instead. Why? We're about to enter territory that would be remarkably painful to tread upon with make: for upcoming module projects, we'll compile both for the target (probably with gcc) and the host (probably with clang); we'll also use other tools like clang sanitizers. We'll build in testing, which means - for native code projects - compiling different executables. All of this is hard to do in make, and the ways that you work around it typically mean abandoning the places where Make can help you the most. Raw makefiles are pretty good at replacing shell scripts as a build system. They give you dependency management, they give you some built-ins for managing compiler options for compiler options. The farther you go from using them as a replacement for shell scripts, the worse they get. In particular, they really start to drag when the configuration of a build becomes more complex, and especially when there are multiple complex configurations. The typical way to avoid this in raw Make is to start avoiding using Make's builtin rules (so you don't have to, e.g., switch around $CC) or have increasingly complex switches around environment variables. The other route that people take is to use a config system. There are a lot of these: kconfig, buildroot's config which somehow also runs under make in bizarre ways, IDE project configuration (which therefore ties you to an IDE), others. But there's also cmake. Cmake is an ugly (just check out the code!) configuration system to look at, and its overeager attempts to help you out can occasionally get in your way, but it is fundamentally a solid, well-designed, extremely well-documented opinionated multi-platform native code configuration system that is widely used, integrates well with IDEs, and fixes the issues I noted above. OK but why change what works? Well, unfortunately, cmake's core desire is to compute a bunch of configuration and emit... Makefiles. Which means it's very hard to use alongside a different Makefile based system. Also I needed the practice, quite honestly. So what changed? opentrons-modules in this pr uses cmake as a configuration system, generating (currently) makefiles. That means that the logic that used to be in the top-level Makefile is now spread out in the CMakeLists.txt files that exist in the source tree. Each file is responsible for building what is below it, in the parallel builds directory. How do I use this? (Check out the README) The biggest usability downside of cmake is that it has two steps: configure, and build. You can do them both with the cmake command, which is your friend. The specific cmake you want to use is CMake 3.19, which you can find here. We want 3.19, which is the latest release, because of the new "presets" concept which allows much easier (MUCH easier) configuration of things like cross-compilers. So first you configure: cmake . And then you build: cmake --build ./builds You can also use the generated Makefiles to build - cd builds && make. To bundle up all the modules into a specific package, run cmake --install ./builds. When you run the configuration step, cmake will automatically download the arduino IDE and configure it for you.
1 parent eeb62a0 commit 04cd3fc

File tree

407 files changed

+655
-229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

407 files changed

+655
-229
lines changed

Diff for: .gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,9 @@ ENV/
117117
node_modules
118118

119119
releases
120+
121+
CMakeFiles
122+
123+
cmake_install.cmake
124+
125+
arduino_ide

Diff for: .travis.yml

+16-10
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@ git:
55

66
cache:
77
directories:
8-
- ~/arduino_ide
8+
- ./arduino_ide
9+
- ~/.arduino15
910

10-
install:
11-
- make setup
11+
dist: bionic
12+
13+
addons:
14+
apt:
15+
sources:
16+
- sourceline: 'deb https://apt.kitware.com/ubuntu/ bionic main'
17+
key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
18+
packages:
19+
- cmake
1220

1321
# base configs
1422
_deploy_s3: &deploy_s3
@@ -28,17 +36,15 @@ jobs:
2836
- stage: deploy
2937
name: deploy build
3038
script:
31-
- make build
32-
- make zip-all
39+
# https://travis-ci.community/t/install-cmake-using-apt-again/4062 is why this uses
40+
# /usr/local/bin explicitly
41+
- /usr/bin/cmake --preset=arduino .
42+
- /usr/bin/cmake --build ./build --target zip-all
43+
- /usr/bin/cmake --install ./build
3344
before_deploy:
3445
- source ./scripts/set_build_vars.sh
3546
deploy:
3647
- # upload module release artifacts to S3
3748
<<: *deploy_s3
3849
local_dir: $RELEASE_LOCAL_DIR
3950
upload_dir: $RELEASE_UPLOAD_DIR
40-
41-
notifications:
42-
email:
43-
on_success: change
44-
on_failure: change

Diff for: CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# CMake 3.19 is the first to include presets
2+
# (https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html)
3+
cmake_minimum_required(VERSION 3.19)
4+
5+
project("OpentronsModules"
6+
LANGUAGES CXX
7+
DESCRIPTION "Firmware for Opentrons modules")
8+
9+
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
10+
11+
# These subdirectories contain the code for these modules and the
12+
# CMakeLists for them. The MODULE_TYPE variable is set in the arduino preset.
13+
if (${MODULE_TYPE} STREQUAL "arduino")
14+
add_subdirectory(arduino-modules)
15+
endif()

Diff for: CMakePresets.json

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"version": 1,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 19,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "arduino",
11+
"displayName": "Arduino modules",
12+
"description": "Build modules firmwares that use Arduino compilers (tempdeck, magdeck, thermocycler)",
13+
"generator": "Unix Makefiles",
14+
"binaryDir": "${sourceDir}/build/",
15+
"cacheVariables": {
16+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/ArduinoToolchain.cmake",
17+
"ARDUINO_IDE_VERSION": "1.8.10",
18+
"OPENTRONS_BOARDS_VERSION": "1.3.0",
19+
"OPENTRONS_SAMD_BOARDS_VERSION": "1.1.0",
20+
"ARDUINO_SAMD_VESION": "1.6.21",
21+
"CMAKE_FIND_APPBUNDLE": "NEVER",
22+
"TC_DUMMY_BOARD": false,
23+
"TC_LID_WARNING": false,
24+
"TC_HFQ_PWM": false,
25+
"TC_HW_VERSION": "4",
26+
"TC_RGBW_NEO": true,
27+
"TC_VOLUME_DEPENDENCY": true,
28+
"TC_LID_TESTING": false,
29+
"MODULE_TYPE": "arduino",
30+
"CMAKE_INSTALL_PREFIX": "${sourceDir}/dist"
31+
}
32+
}
33+
]
34+
}

Diff for: Makefile

-160
This file was deleted.

Diff for: README.md

+19-54

Diff for: arduino-modules/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Main CMakeLists for the arduino modules
2+
3+
4+
add_subdirectory(mag-deck)
5+
add_subdirectory(temp-deck)
6+
add_subdirectory(thermo-cycler)
7+
8+
add_custom_target(zip-all)
9+
add_dependencies(zip-all magdeck-zip tempdeck-zip thermocycler-zip)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)