Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to vanilla Mbed OS CMake + Distro Fix #5

Open
wants to merge 6 commits into
base: feature/move-to-vanilla-cmake
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ indent_size = 4
[.ycm_extra_conf.py]
indent_style = space
indent_size = 2

[extern/mbed-os/**]
trim_trailing_whitespace = false
insert_final_newline = false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
extern/mbed-os
_build*
_coverage*
cmake_build
cmake/config/
.mbedbuild
.cache
.clangd
*.ioc.csv
Expand Down
51 changes: 27 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright 2020 Ladislas de Toldi (ladislas [at] detoldi.me)
# SPDX-License-Identifier: Apache-2.0

# mbed-cmake requires at least CMake 3.18
cmake_minimum_required(VERSION 3.19)

# Activate ccache
Expand All @@ -12,38 +11,42 @@ if(CCACHE)
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE})
endif()

# Before all, set ROOT_DIR, MBED_OS_DIR
set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
set(MBED_OS_DIR ${ROOT_DIR}/extern/mbed-os)
# Set ROOT_DIR, MBED_PATH, MBED_CONFIG_PATH
set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
set(MBED_PATH ${ROOT_DIR}/extern/mbed-os CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${ROOT_DIR}/.mbedbuild CACHE INTERNAL "")

# And include mbed-cmake.cmake
include(./mbed-cmake.cmake)

# Then configure name of the project
project("Mbed CMake Template" LANGUAGES C CXX ASM)
# For convenience, define useful variables
set(LIBS_DIR ${ROOT_DIR}/libs)
set(SPIKES_DIR ${ROOT_DIR}/spikes)
set(TARGETS_DIR ${ROOT_DIR}/targets)

# Generate compile commands database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")

# For convenience you can define useful variables
set(LIBS_DIR ${ROOT_DIR}/libs)
set(SPIKES_DIR ${ROOT_DIR}/spikes)
set(TARGETS_DIR ${ROOT_DIR}/targets)
# Include mbed os cmake logic
include(${MBED_PATH}/tools/cmake/app.cmake)

# Add custom target subdirectory
set(AVAILABLE_CUSTOM_TARGETS DISCO_ORIGINAL LEKA_V1_0_DEV LEKA_V1_1_DEV LEKA_V1_2_DEV)
if (${TARGET_BOARD} IN_LIST AVAILABLE_CUSTOM_TARGETS)
add_subdirectory(${TARGETS_DIR}/TARGET_${TARGET_BOARD})
endif()
# Colored output when compiling
add_compile_options(-fdiagnostics-color)

# 💡 Set project name and languages
project("Mbed CMake Template" LANGUAGES C CXX ASM)

# Add mbed-os
add_subdirectory(${MBED_PATH})
include(${ROOT_DIR}/cmake/mbed_create_distro.cmake)
mbed_create_distro(mbed_for_my_app mbed-os)

# Add libraries
add_subdirectory(${LIBS_DIR}/HelloWorld)

# If you use spikes to test features, you can add them here
add_subdirectory(${SPIKES_DIR}/blinky)

# Add the main source files of the project from ./src
# Add executable targets main & blinky (as spike)
# 💡 You can uncomment both lines to make it fail
add_subdirectory(${ROOT_DIR}/src)
add_subdirectory(${SPIKES_DIR}/blinky)

# Finally print the mbed-cmake build report
mbed_cmake_print_build_report()
option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ clean_config:

config_target: mkdir_config
@echo ""
@echo "🏃 Running configuration script for target $(TARGET_BOARD) 📝"
python3 $(CMAKE_DIR)/scripts/configure_cmake_for_target.py $(TARGET_BOARD) -p $(PROJECT_BUILD_DIR)/cmake_config/$(TARGET_BOARD) -a $(ROOT_DIR)/mbed_app.json
@echo "🏃 Running target configuration script 📝"
mbed-tools configure -t GCC_ARM -m $(TARGET_BOARD) --mbed-os-path=./extern/mbed-os

config_cmake: mkdir_build
@echo ""
@echo "🏃 Running cmake configuration script for target $(TARGET_BOARD) 📝"
@cmake -S . -B $(TARGET_BUILD_DIR) -GNinja -DTARGET_BOARD="$(TARGET_BOARD)" -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DENABLE_CODE_ANALYSIS=$(CODE_ANALYSIS)
@cmake -S . -B $(TARGET_BUILD_DIR) -GNinja -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)

#
# MARK: - Tests targets
Expand Down Expand Up @@ -176,7 +176,6 @@ mbed_clone:
@echo "🧬 Cloning Mbed OS 📦"
@rm -rf $(MBED_OS_DIR)
git clone --depth=1 --branch=$(BRANCH) https://github.com/ARMmbed/mbed-os $(MBED_OS_DIR)
@$(MAKE) mbed_symlink_files

mbed_curl:
@echo ""
Expand All @@ -186,7 +185,6 @@ mbed_curl:
curl -O -L https://github.com/ARMmbed/mbed-os/archive/$(VERSION).tar.gz
tar -xzf $(VERSION).tar.gz --strip-components=1 -C extern/mbed-os
rm -rf $(VERSION).tar.gz
@$(MAKE) mbed_symlink_files

mbed_symlink_files:
@echo ""
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
# Mbed CMake Template

## 🚧 WIP - From USCRPL/mbed-cmake to Mbed OS first-party CMake

> ⚠️⚠️⚠️

This branch is a WIP to move from USCRPL/mbed-cmake to Mbed OS first-party CMake.

### Instructions

```shell
# Clone repository & switch branch
git clone https://github.com/ladislas/mbed-cmake-template
cd mbed-cmake-template
git checkout feature/move-to-vanilla-cmake

# Clone mbed-os in `./extern/mbed-os`
# You can select the branch or tag you want
git clone --depth=10 --branch=master https://github.com/ARMmbed/mbed-os ./extern/mbed-os

# Config CMake
make config

# Build the project
make
```

Please note:

- there is no need to run `mbed-tools configure... `, `.mbedbuild` is included in the repository for `DISCO_F769NI`
- `make config` runs `make clean` before configuring CMake
- To chekcout a different branch in `mbed-os`, `cd ./extern/mbed-os` and then `git checkout` or `gh pr checkout {pr_number}`
- To test two `add_executable` targets, you can uncomment line 29-30 from the main `CMakeLists.txt`

> ⚠️⚠️⚠️

**Version: 1.0.0**

## Introduction
Expand Down
71 changes: 0 additions & 71 deletions cmake/MbedUnitTests.cmake

This file was deleted.

88 changes: 0 additions & 88 deletions cmake/ToolchainArmClangBuild.cmake

This file was deleted.

Loading