Skip to content

Commit 280efe1

Browse files
authored
Merge pull request #1776 from massonal/cmake_dev
undefined
2 parents 618610d + 9283782 commit 280efe1

File tree

568 files changed

+123684
-0
lines changed

Some content is hidden

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

568 files changed

+123684
-0
lines changed

Diff for: .github/workflows/Cmake.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CMake config and build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
jobs:
11+
cmake:
12+
name: Check CMake usage
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@main
18+
19+
- name: Get latest CMake and Ninja
20+
uses: lukka/get-cmake@latest
21+
22+
- name: Configure
23+
run: |
24+
mkdir build
25+
cmake -S CI/build/examples/BareMinimum -B ./build -G Ninja
26+
27+
- name: Build example
28+
working-directory: '${{ github.workspace }}/build'
29+
run: ninja

Diff for: CI/build/examples/BareMinimum/CMakeLists.txt

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This file was autogenerated by cmake\scripts\cmake_easy_setup.py.
2+
# Use it in your CMake configuration by `include()`'ing it.
3+
# You can also copy it in your sketch's folder and edit it to fit your project.
4+
5+
cmake_minimum_required(VERSION 3.21)
6+
7+
# STEP 1: set up bases of environment
8+
# -----------------------------------------------------------------------------
9+
10+
file(REAL_PATH "../../../../" CORE_PATH EXPAND_TILDE)
11+
file(TO_CMAKE_PATH "${CORE_PATH}" CORE_PATH)
12+
13+
set(BOARDNAME "NUCLEO_F103RB")
14+
15+
list(APPEND CMAKE_MODULE_PATH ${CORE_PATH}/cmake)
16+
set(CMAKE_TOOLCHAIN_FILE toolchain)
17+
18+
19+
# You may remove this block when using this file as the sketch's CMakeLists.txt
20+
if (NOT ${CMAKE_PARENT_LIST_FILE} STREQUAL ${CMAKE_CURRENT_LIST_FILE})
21+
# When we are imported from the main CMakeLists.txt, we should stop here
22+
# not to interfere with the true build config.
23+
return()
24+
endif()
25+
26+
project("BareMinimum_project")
27+
28+
# STEP 2: configure the build
29+
# -----------------------------------------------------------------------------
30+
include(set_board)
31+
set_board("${BOARDNAME}")
32+
33+
include(overall_settings)
34+
overall_settings()
35+
36+
include(build_sketch)
37+
build_sketch(TARGET "BareMinimum"
38+
SOURCES
39+
BareMinimum.ino
40+
DEPENDS
41+
CMSIS_DSP
42+
EEPROM
43+
IWatchdog
44+
Servo
45+
SoftwareSerial
46+
SPI
47+
Wire
48+
)

Diff for: README_CMAKE.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
CMake can now be used to build Arduino sketches with this core.
2+
Examples of use can be found on this repo: [stm32duino/CMake_workspace](https://github.com/stm32duino/CMake_workspace).
3+
4+
This README only provides a quick walk-through.
5+
For all the glorious details, please head over to [the wiki](https://github.com/stm32duino/wiki/wiki/CMake_presentation).
6+
7+
# Prerequisites
8+
9+
- CMake version >= 3.21
10+
- Python3 version >= 3.9
11+
- `make` / `ninja` (prefer `ninja`)
12+
- graphviz layout engines: `dot`, `sfdp` (optional)
13+
- Python modules: `graphviz`, `jinja2`; install them with `pip install ...`
14+
15+
Some additional dependencies (toolchain...) will be downloaded on the first build.
16+
17+
If your system does not provide a recent enough version of CMake, a suitable version may be installed with [`pip`](https://pypi.org/): `pip install cmake`.
18+
19+
# Usage
20+
21+
This section will describe the process of building a sketch "by hand", with a system shell. Other methods, such as with an IDE plug-in, may require adaptations.
22+
23+
Please see [stm32duino/CMake_workspace](https://github.com/stm32duino/CMake_workspace) for some quick examples; more may be added over time.
24+
25+
First of all, there has to be a CMakeLists.txt in the sketch folder.
26+
27+
- easy way: fire `cmake/scripts/cmake_easy_setup.py -b <board> -s <sketch folder>` (this requires arduino-cli and jinja)
28+
- advanced way: write your own by adapting from an example
29+
30+
--------
31+
32+
__Board name__: either through the script or directly in the CMakeLists.txt, the board name is the identifier found in boards.txt. (Yes, CMake is made aware of boards.txt/platform.txt.)
33+
In the following example, the value to retain would be "NUCLEO_F207ZG" (the part after "menu.pnum."):
34+
```
35+
# NUCLEO_F207ZG board
36+
Nucleo_144.menu.pnum.NUCLEO_F207ZG=Nucleo F207ZG
37+
Nucleo_144.menu.pnum.NUCLEO_F207ZG.node=NODE_F207ZG
38+
```
39+
40+
--------
41+
42+
Then CMake can be run to launch the configuration step. This is only needed on the very first time, at the beginning of the project.
43+
```sh
44+
cmake -S [sketch folder] -B [build folder] -G Ninja # "-G Ninja" -> generate ninja files (default = make)
45+
```
46+
The build folder is conventionally located at the root of the sketch folder and named `build`, e.g. :
47+
```
48+
.
49+
|-- Blink/
50+
| |-- Blink.ino
51+
| |-- CMakeLists.txt
52+
| `-- build/
53+
```
54+
55+
Finally, the sketch can be (re-)built with `cmake --build <build folder>`.
56+
This can also be done by invoking the build tool (usually `make` or `ninja`) directly from the build folder.
57+
**This last step is the only one needed in order to rebuild the project, even if some source files, or even the CMakeLists.txt, have changed.**
58+
59+
For more details on how to use CMake, please read the CMake [User Interaction Guide](https://cmake.org/cmake/help/v3.21/guide/user-interaction/index.html).
60+
61+
The official [CMake tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/index.html) may also be useful for users looking to understand all the implementation details.
62+
63+
# Caveats
64+
65+
- The CMake build model makes it hard to auto-detect dependencies between the sketch and the Arduino libraries, and between Arduino libraries. Thus, you have to specify them manually; see the examples to see how.
66+
- Uploading the binaries to the board is not implemented; this step is up to you, using the appropriate tool. If your board supports the "mass storage" method, you can simply copy the .bin file to your board drive in the file explorer.

Diff for: cmake/FindArduinoCtags.cmake

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
cmake_minimum_required(VERSION 3.21)
2+
include(FetchContent)
3+
include(FindPackageHandleStandardArgs)
4+
5+
function(get_ctags)
6+
cmake_host_system_information(
7+
RESULT HOSTINFO
8+
QUERY OS_NAME OS_PLATFORM
9+
)
10+
list(GET HOSTINFO 0 HOST_OS)
11+
list(GET HOSTINFO 1 HOST_ARCH)
12+
13+
unset(CPUCODE)
14+
string(TOUPPER ${HOST_ARCH} HOST_ARCH)
15+
if (${HOST_ARCH} MATCHES "^(AMD64|X86_64|x64)$")
16+
set(CPUCODE "x86_64")
17+
elseif (${HOST_ARCH} MATCHES "^(ARM|ARM64)$")
18+
# not sure there, am I specific enough?
19+
set(CPUCODE "armv6")
20+
elseif (${HOST_ARCH} MATCHES "^(I386|IA32|x86|i686)$")
21+
set(CPUCODE "i686")
22+
endif()
23+
24+
unset(OSCODE)
25+
unset(ARCHIVE_EXT)
26+
if (${HOST_OS} STREQUAL "Linux")
27+
if(${CPUCODE} STREQUAL "armv6")
28+
set(OSCODE "linux-gnueabihf")
29+
# ... I guess? Is there any further check to perform?
30+
else()
31+
set(OSCODE "pc-linux-gnu")
32+
endif()
33+
set(ARCHIVE_EXT ".tar.bz2")
34+
elseif (${HOST_OS} STREQUAL "Windows")
35+
if(${CPUCODE} MATCHES "i686|x86_64")
36+
# ctags supports only 32-bit for Windows
37+
set(CPUCODE "i686")
38+
set(OSCODE "mingw32")
39+
set(ARCHIVE_EXT ".zip")
40+
endif()
41+
elseif (${HOST_OS} STREQUAL "Darwin")
42+
if(${CPUCODE} STREQUAL "x86_64")
43+
set(OSCODE "apple-darwin")
44+
set(ARCHIVE_EXT ".zip")
45+
endif()
46+
endif()
47+
48+
# the SHA512 file is of the form "hash_in_hexa filename"
49+
if(NOT EXISTS ${DL_DIR}/ctags_sha512.txt)
50+
file(DOWNLOAD
51+
"https://github.com/arduino/ctags/releases/download/5.8-arduino11/ctags-5.8-arduino11-${CPUCODE}-${OSCODE}${ARCHIVE_EXT}.sha512"
52+
${DL_DIR}/ctags_sha512.txt
53+
)
54+
endif()
55+
file(READ ${DL_DIR}/ctags_sha512.txt CHECKSUM_FULLTEXT)
56+
string(SUBSTRING "${CHECKSUM_FULLTEXT}" 0 128 CHECKSUM) # keep just the hash; 512 bits make 128 hex characters
57+
58+
FetchContent_Declare(
59+
ctags
60+
SOURCE_DIR ${DL_DIR}/dist/ctags
61+
PREFIX ${DL_DIR}
62+
URL "https://github.com/arduino/ctags/releases/download/5.8-arduino11/ctags-5.8-arduino11-${CPUCODE}-${OSCODE}${ARCHIVE_EXT}"
63+
URL_HASH SHA512=${CHECKSUM}
64+
UPDATE_DISCONNECTED
65+
)
66+
message(STATUS "Downloading Arduino's ctags...")
67+
FetchContent_MakeAvailable(ctags)
68+
message(STATUS "Downloading Arduino's ctags... Done.")
69+
endfunction()
70+
71+
# -------------------------------------------------------------------------------
72+
73+
if(NOT EXISTS ${DL_DIR}/dist/ctags)
74+
get_ctags()
75+
endif()
76+
77+
find_program(ARDUINOCTAGS_EXECUTABLE ctags PATHS ${DL_DIR}/dist/ctags NO_DEFAULT_PATH)
78+
79+
find_package_handle_standard_args(ArduinoCtags DEFAULT_MSG
80+
ARDUINOCTAGS_EXECUTABLE
81+
)

0 commit comments

Comments
 (0)