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

ladislas/feature/clean up cmake #403

Merged
merged 19 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0a76530
:fire: (cmake): Remove CODE_ANALYSIS
ladislas Dec 30, 2021
c96fc14
:adhesive_bandage: (targets): Fix device names with good values from …
ladislas Jan 7, 2022
572ea08
:wastebasket: (targets): Remove old unused dev hardware targets
ladislas Jan 7, 2022
51cbd43
:recycle: (cmake): Move mcuboot compile definitions to bootutil target
ladislas Jan 7, 2022
1d391f5
:truck: (cmake): Move & rename mbed cmake templates
ladislas Jan 7, 2022
e2dc6d2
:truck: (cmake): Move & rename mcuboot cmake templates
ladislas Jan 7, 2022
be59abe
:green_heart: (cache): Pull extern deps when hash of template files h…
ladislas Jan 7, 2022
eb47455
:green_heart: (workflows): Curl extern deps if cache hit is false
ladislas Jan 7, 2022
004d441
:fire: (cmake): Delete MbedUnitTests related code/files
ladislas Jan 7, 2022
8bd9f7c
:fire: (cmake): Delete unused USCRPL/mbed-cmake files
ladislas Jan 8, 2022
c40150e
:fire: (cmake): Delete unused ArmClang toolchain files
ladislas Jan 8, 2022
b5f34e3
:fire: (cmake): Remove ArmClang code and branches
ladislas Jan 8, 2022
6e94d17
:lipstick: (cmake): Clean up main CMakeLists.txt
ladislas Jan 8, 2022
98b5780
:lipstick: (cmake): Clean up unit tests CMakeLists.txt
ladislas Jan 8, 2022
4e69ee9
:hammer: (make): Add bootloader make target
ladislas Jan 8, 2022
71e6eaf
:recycle: (scripts): Clean up firmware scripts
ladislas Jan 8, 2022
e302d67
:wrench: (cmake/vscode): Fix build dirs + combine compilation databases
ladislas Jan 8, 2022
31273c3
:hammer: (make): Add pull_deps target to clone mbed & mcuboot
ladislas Jan 9, 2022
202a6b1
:memo: (docs): Update & clean up install/how-to documentation
ladislas Jan 9, 2022
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
20 changes: 8 additions & 12 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ runs:
path: |
extern/mbed-os
extern/mcuboot
key: ${{ runner.os }}-global_cache-extern_dependencies-${{ hashFiles('.mbed_version', '.mbed_git_url', '.mcuboot_version') }}
key: ${{ runner.os }}-global_cache-extern_dependencies-${{ hashFiles('.mbed_version', '.mbed_git_url', '.mcuboot_version', 'cmake/templates/**') }}

- name: Pull extern dependencies
if: steps.global_cache-extern_dependencies.outputs.cache-hit != 'true'
shell: bash
run: |
make mbed_curl
make mcuboot_clone

- name: Cache ccache
id: global_cache-ccache
Expand Down Expand Up @@ -133,14 +140,3 @@ runs:
mbed-cli --help
mbed-tools --help
imgtool --help

#
# Mark: - Extern dependencies
#

- name: Pull extern dependencies
if: steps.global_cache-extern_dependencies.outputs.cache-hit != 'true'
shell: bash
run: |
make mbed_curl
make mcuboot_clone
11 changes: 5 additions & 6 deletions .github/workflows/ci-code_analysis-compare_bin_map_files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Setup CI
id: setup_ci
uses: ./.github/actions/setup
with:
ccache_name: code_analysis-compare_files
Expand All @@ -44,9 +45,8 @@ jobs:
run: |
git checkout ${{ env.BASE_REF }}
make deep_clean
if [[ "$BASE_MBED_VERSION" != "$HEAD_MBED_VERSION" ]]; then
make mbed_curl VERSION=${{ env.BASE_MBED_VERSION }}
fi
make mbed_curl VERSION=${{ env.BASE_MBED_VERSION }}
make mcuboot_clone
make config ${{ matrix.enable_log_debug }}
make

Expand All @@ -61,9 +61,8 @@ jobs:
run: |
git checkout ${{ env.HEAD_REF }}
make deep_clean
if [[ "$BASE_MBED_VERSION" != "$HEAD_MBED_VERSION" ]]; then
make mbed_curl VERSION=${{ env.HEAD_MBED_VERSION }}
fi
make mbed_curl VERSION=${{ env.HEAD_MBED_VERSION }}
make mcuboot_clone
ladislas marked this conversation as resolved.
Show resolved Hide resolved
make config ${{ matrix.enable_log_debug }}
make

Expand Down
15 changes: 11 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,20 @@
".cache": true,
".clangd": true
},
"cmake.ignoreKitEnv": true,
"cmake.configureOnOpen": true,
"cmake.buildDirectory": "${workspaceFolder}/_build_cmake_tools",
"cmake.mergedCompileCommands": "${workspaceFolder}/compile_commands.json",
"cmake.configureArgs": [
"-DTARGET_BOARD=LEKA_V1_2_DEV",
"-DENABLE_LOG_DEBUG=ON",
"-DCMAKE_CONFIG_DIR=${workspaceFolder}/_build_cmake_tools/cmake_config"
"-GNinja",
],
"cmake.configureSettings": {
"TARGET_BOARD": "LEKA_V1_2_DEV",
"ENABLE_LOG_DEBUG": "ON",
"MBED_PATH": "${workspaceFolder}/extern/mbed-os",
"CMAKE_CONFIG_DIR": "${workspaceFolder}/_build_cmake_tools/cmake_config",
"CMAKE_BUILD_TYPE": "Debug"
},
"markdownlint.config": {
"MD002": false,
"MD007": {
Expand All @@ -91,7 +99,6 @@
"MD033": false
},
"editor.formatOnSave": true,
"cmake.configureOnOpen": true,
"clangd.checkUpdates": true,
"clangd.arguments": [
"--query-driver=/usr/local/bin/arm-none-eabi*",
Expand Down
142 changes: 78 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,98 +4,102 @@

cmake_minimum_required(VERSION 3.21)

# Activate ccache if available
#
# MARK: - External tools
#

find_program(CCACHE "ccache")
if(CCACHE)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE}")
endif(CCACHE)

# Activate code analysis
option(ENABLE_CODE_ANALYSIS "Run code analysis" OFF)
message(STATUS "ENABLE_CODE_ANALYSIS --> ${ENABLE_CODE_ANALYSIS}")

if(ENABLE_CODE_ANALYSIS)
find_program(CPPCHECK "cppcheck")
if(CPPCHECK)
set(CMAKE_CXX_CPPCHECK "${CPPCHECK}"
"--platform=${CMAKE_CURRENT_SOURCE_DIR}/tools/config/cppcheck_leka_platform.xml"
"--std=c++17"
"--cppcheck-build-dir=build/cppcheck"
"--enable=all"
"--inconclusive"
"--inline-suppr"
"--quiet"
"--suppress=unmatchedSuppression"
"--suppress=missingIncludeSystem"
"--suppress=*:*extern/mbed-os\*"
"--template=🔥 warning: {id} ({severity}): {message}\\n in {file}:{line}\\n{code}"
# "--check-config"
)
endif(CPPCHECK)
endif(ENABLE_CODE_ANALYSIS)

# Activate LogKit
option(ENABLE_LOG_DEBUG "Enable LogKit output" OFF)
message(STATUS "ENABLE_LOG_DEBUG --> ${ENABLE_LOG_DEBUG}")
if(ENABLE_LOG_DEBUG)
add_definitions(-DENABLE_LOG_DEBUG)
endif(ENABLE_LOG_DEBUG)
# Compile commands database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()

#
# MARK: - Compilation flags/options
#

# Set C/C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS TRUE)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_STANDARD 17)
set(CMAKE_C_EXTENSIONS TRUE)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")

# Add custom flags
add_compile_options(
$<$<COMPILE_LANGUAGE:CXX>:-Wno-register>
$<$<COMPILE_LANGUAGE:CXX>:-Wno-volatile>
-fdiagnostics-color=always
)

# 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(MCUBOOT_DIR ${ROOT_DIR}/extern/mcuboot/boot)
set(MBED_HTTP_DIR ${ROOT_DIR}/extern/mbed-http)

# Bootloader option
# Bootloader
option(BUILD_TARGETS_TO_USE_WITH_BOOTLOADER "Build targets with padding to use with bootloader" OFF)
message(STATUS "Build targets with padding to use with bootloader --> ${BUILD_TARGETS_TO_USE_WITH_BOOTLOADER}")
if (BUILD_TARGETS_TO_USE_WITH_BOOTLOADER)
set(MBED_APP_FLAGS
-DMBED_APP_START=0x08041000
-DMBED_APP_SIZE=0x17E000
)
endif(BUILD_TARGETS_TO_USE_WITH_BOOTLOADER)

# And include mbed-cmake.cmake
include(./mbed-cmake.cmake)
# Logger
option(ENABLE_LOG_DEBUG "Enable LogKit output" OFF)
if(ENABLE_LOG_DEBUG)
add_definitions(-DENABLE_LOG_DEBUG)
endif(ENABLE_LOG_DEBUG)

# Then configure name of the project
project(LekaOS LANGUAGES C CXX ASM)

# Generate compile commands database
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
#
# MARK: - Directories
#

if(CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()
# Before all
set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})

# extern
set(MBED_OS_DIR ${ROOT_DIR}/extern/mbed-os)
set(MCUBOOT_DIR ${ROOT_DIR}/extern/mcuboot/boot)
set(MBED_HTTP_DIR ${ROOT_DIR}/extern/mbed-http)

# includes
set(LIBS_DIR ${ROOT_DIR}/libs)
set(DRIVERS_DIR ${ROOT_DIR}/drivers)
set(INCLUDE_DIR ${ROOT_DIR}/include)
set(TARGETS_DIR ${ROOT_DIR}/targets)

# For convenience you can define useful variables
# app
set(OS_DIR ${ROOT_DIR}/app/os)
set(LIBS_DIR ${ROOT_DIR}/libs)
set(TESTS_DIR ${ROOT_DIR}/tests)
set(SPIKES_DIR ${ROOT_DIR}/spikes)
set(DRIVERS_DIR ${ROOT_DIR}/drivers)
set(TARGETS_DIR ${ROOT_DIR}/targets)
set(INCLUDE_DIR ${ROOT_DIR}/include)
set(BOOTLOADER_DIR ${ROOT_DIR}/app/bootloader)

# spikes, functional tests
set(SPIKES_DIR ${ROOT_DIR}/spikes)
set(FUNCTIONAL_TESTS_DIR ${ROOT_DIR}/tests/functional)

#
# MARK: - LekaOS Project
#

# And include mbed-cmake.cmake
include(${ROOT_DIR}/mbed-cmake.cmake)

project(LekaOS LANGUAGES C CXX ASM)

# Add custom target subdirectory
set(AVAILABLE_CUSTOM_TARGETS DISCO_ORIGINAL LEKA_V1_0_DEV LEKA_V1_1_DEV LEKA_V1_2_DEV)
set(AVAILABLE_CUSTOM_TARGETS LEKA_DISCO LEKA_V1_2_DEV)
if (${TARGET_BOARD} IN_LIST AVAILABLE_CUSTOM_TARGETS)
message(STATUS "Add subdirectory for hardware target ${TARGET_BOARD}")
add_subdirectory(${TARGETS_DIR}/TARGET_${TARGET_BOARD})
else()
message(FATAL_ERROR "Target ${TARGET_BOARD} is not available.")
endif()

include_directories(BEFORE
Expand All @@ -115,13 +119,6 @@ link_libraries(
CriticalSection
)

# Add external libraries
add_compile_definitions(MCUBOOT_BOOTLOADER_SIZE=0x40000)
add_compile_definitions(MCUBOOT_SCRATCH_SIZE=0x40000)
add_compile_definitions(MCUBOOT_SCRATCH_START_ADDR=0x081C0000)
add_compile_definitions(MCUBOOT_RSA_SIGNATURE_LENGTH=2048)
add_compile_definitions(MCUBOOT_SLOT_SIZE=0x200000-MCUBOOT_BOOTLOADER_SIZE-MCUBOOT_SCRATCH_SIZE)

add_subdirectory(${MCUBOOT_DIR})
add_subdirectory(${MBED_HTTP_DIR})

Expand All @@ -131,7 +128,7 @@ add_subdirectory(${LIBS_DIR})

# Add spikes, functional tests
add_subdirectory(${SPIKES_DIR})
add_subdirectory(${TESTS_DIR}/functional)
add_subdirectory(${FUNCTIONAL_TESTS_DIR})

# Add bootloader
add_subdirectory(${BOOTLOADER_DIR})
Expand All @@ -141,3 +138,20 @@ add_subdirectory(${OS_DIR})

# Finally print the mbed-cmake build report
mbed_cmake_print_build_report()

#
# MARK: - Misc. options
#

option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()

# Print options
message(STATUS "")
message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS --> ${CMAKE_EXPORT_COMPILE_COMMANDS}")
message(STATUS "ENABLE_LOG_DEBUG --> ${ENABLE_LOG_DEBUG}")
message(STATUS "BUILD_TARGETS_FOR_BOOTLOADER --> ${BUILD_TARGETS_TO_USE_WITH_BOOTLOADER}")
message(STATUS "CMAKE_VERBOSE_MAKEFILE --> ${VERBOSE_BUILD}")
message(STATUS "")
Loading