Skip to content

Commit

Permalink
Add support for including ChibiOS-Contrib repo in build (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Jan 24, 2019
1 parent 476e484 commit 7c91268
Show file tree
Hide file tree
Showing 54 changed files with 272 additions and 71 deletions.
20 changes: 20 additions & 0 deletions CMake/ChibiOS-Contrib.CMakeLists.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 2.8.2)

project(ChibiOS-Contrib-download NONE)

include(ExternalProject)

# download ChibiOS Community contributions source from GitHub repo
ExternalProject_Add(
ChibiOS-Contrib
PREFIX ChibiOS-Contrib
SOURCE_DIR ${CMAKE_BINARY_DIR}/ChibiOS-Contrib_Source
GIT_REPOSITORY https://github.com/ChibiOS/ChibiOS-Contrib
GIT_SHALLOW 1 # download only the tip of the branch, not the complete history
TIMEOUT 10
LOG_DOWNLOAD 1
# Disable all other steps
INSTALL_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)
5 changes: 5 additions & 0 deletions CMake/Modules/FindCHIBIOS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ext/CMSIS/include)
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ext/CMSIS/ST/${TARGET_SERIES})

# append dummy include directory when not using ChibiOS-Contrib
if(NOT CHIBIOS_CONTRIB_REQUIRED)
list(APPEND CHIBIOS_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/include/dummy_includes")
endif()

# append include directory for boards in the nanoFramework ChibiOS 'overlay'
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/boards/${CHIBIOS_BOARD})

Expand Down
33 changes: 33 additions & 0 deletions CMake/Modules/FindChibiOS-Contrib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Copyright (c) 2017 The nanoFramework project contributors
# See LICENSE file in the project root for full license information.
#

# set include directories for ChibiOS-Contrib

list(APPEND CHIBIOS_CONTRIB_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS-Contrib_Source/os/hal/include/)

####################################################################################
# WHEN ADDING A NEW ChibiOS-Contrib component add the include directory(ies) bellow
####################################################################################
# component IMACOMPONENT
#list(APPEND CHIBIOS_CONTRIB_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS-Contrib_Source/os/hal/include/IMACOMPONENT)


#######################################################################################################################################
# Because we've "hacked" ChibiOS overlay mechanism used by the community contributions we can't add the "official" hal_community.c
# Instead we have to add the requried and equivalent calls existing in the official source file
# in our hal_community.c @ targets\CMSIS-OS\ChibiOS\nf-overlay\os\hal\src\hal_community.c
#########################################################################################################################


####################################################################################################
# WHEN ADDING A NEW ChibiOS-Contrib component add the source file(s) specific to it bellow
####################################################################################################
# component IMACOMPONENT
# list(APPEND CHIBIOS_CONTRIB_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/IMACOMPONENT/source-file-1.c)
# list(APPEND CHIBIOS_CONTRIB_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/IMACOMPONENT/source-file-2.c)
# list(APPEND CHIBIOS_CONTRIB_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/IMACOMPONENT/source-file-3.c)

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CHIBIOS_CONTRIB DEFAULT_MSG CHIBIOS_CONTRIB_INCLUDE_DIRS CHIBIOS_CONTRIB_SOURCES)
6 changes: 4 additions & 2 deletions CMake/toolchain.ChibiOS.GCC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ endfunction()

function(NF_SET_COMPILER_DEFINITIONS TARGET)

# definition for platform (always ARM here)
target_compile_definitions(${TARGET} PUBLIC "-DPLATFORM_ARM ")
# definition for platform
# (always ARM here)
# ChibiOS HAL community always include (nanoFramework overlay and official community contributions optionally)
target_compile_definitions(${TARGET} PUBLIC "-DPLATFORM_ARM -DHAL_USE_COMMUNITY")

# build types that have debugging capabilities AND are NOT RTM have to have the define 'NANOCLR_ENABLE_SOURCELEVELDEBUGGING'
if((NOT NF_BUILD_RTM) OR NF_FEATURE_DEBUGGER)
Expand Down
100 changes: 100 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ if(RTOS_CHIBIOS_CHECK)
endif()

#################################################################

#################################################################
# enables use of ChibiOS Community contribution
# (default is OFF so ChibiOS Community is NOT included)
option(CHIBIOS_CONTRIB_REQUIRED "option to include ChibiOS Community contributions repository")
#################################################################

endif()

Expand Down Expand Up @@ -561,6 +567,14 @@ if(RTOS_CHIBIOS_CHECK)
endif()
endif()

# check if CHIBIOS-Contrib_SOURCE was specified or if it's empty (default is empty)
set(NO_CHIBIOS_CONTRIB_SOURCE TRUE)
if(CHIBIOS_CONTRIB_SOURCE)
if(NOT "${CHIBIOS_CONTRIB_SOURCE}" STREQUAL "")
set(NO_CHIBIOS_CONTRIB_SOURCE FALSE)
endif()
endif()

if(NO_CHIBIOS_SOURCE)
# no CHIBIOS source specified, download it from it's repo

Expand Down Expand Up @@ -678,6 +692,92 @@ if(RTOS_CHIBIOS_CHECK)

endif()

if(CHIBIOS_CONTRIB_REQUIRED)
if(NO_CHIBIOS_CONTRIB_SOURCE)
# no CHIBIOS_CONTRIB source specified, download it from it's repo

# hack to make the FindGit to work in Windows platforms (check the module comment for details)
include(Hack_SetGitSearchPath)

# check for Git (needed here for advanced warning to user if it's not installed)
find_package(Git)

# check if Git was found, if not report to user and abort
if(NOT GIT_EXECUTABLE)
message(FATAL_ERROR "error: could not find Git, make sure you have it installed.")
endif()

message(STATUS "ChibiOS-Contrib source from GitHub repo")

# need to setup a separate CMake project to download the code from the GitHub repository
# otherwise it won't be available before the actual build step
configure_file("CMake/ChibiOS-Contrib.CMakeLists.cmake.in"
"${CMAKE_BINARY_DIR}/ChibiOS-Contrib_Download/CMakeLists.txt")

# setup CMake project for ChibiOS-Contrib download
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/ChibiOS-Contrib_Download")

# run build on ChibiOS-Contrib download CMake project to perform the download
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/ChibiOS-Contrib_Download")

# add ChibiOS-Contrib as external project
ExternalProject_Add(
ChibiOS-Contrib
PREFIX ChibiOS-Contrib
SOURCE_DIR ${CMAKE_BINARY_DIR}/ChibiOS-Contrib_Source
GIT_REPOSITORY https://github.com/ChibiOS/ChibiOS-Contrib
GIT_SHALLOW 1 # download only the tip of the branch, not the complete history
TIMEOUT 10
LOG_DOWNLOAD 1
# Disable all other steps
INSTALL_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)

# get source dir for ChibiOS-Contrib CMake project
ExternalProject_Get_Property(ChibiOS-Contrib SOURCE_DIR)

else()
# ChibiOS-Contrib source was specified

# sanity check is source path exists
if(EXISTS "${CHIBIOS_CONTRIB_SOURCE}/")
message(STATUS "ChibiOS-Contrib source from: ${CHIBIOS_CONTRIB_SOURCE}")

# check if we already have the sources, no need to copy again
if(NOT EXISTS "${CMAKE_BINARY_DIR}/ChibiOS-Contrib_Source")
file(COPY "${CHIBIOS_CONTRIB_SOURCE}/" DESTINATION "${CMAKE_BINARY_DIR}/ChibiOS-Contrib_Source")
else()
message(STATUS "Using local cache of ChibiOS-Contrib source from ${CHIBIOS_CONTRIB_SOURCE}")
endif()

set(CHIBIOS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/ChibiOS_Source/include)
else()
message(FATAL_ERROR "Couldn't find ChibiOS-Contrib source at ${CHIBIOS_CONTRIB_SOURCE}/")
endif()

# add ChibiOS-Contrib as external project
ExternalProject_Add(
ChibiOS-Contrib
PREFIX ChibiOS-Contrib
SOURCE_DIR ${CMAKE_BINARY_DIR}/ChibiOS-Contrib_Source
# Disable all other steps
INSTALL_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
)

# get source dir for ChibiOS-Contrib CMake project
ExternalProject_Get_Property(ChibiOS-Contrib SOURCE_DIR)

endif()
endif()

# if mbed TLS is enabled add it to the build
if(NF_SECURITY_MBEDTLS)

Expand Down
2 changes: 2 additions & 0 deletions cmake-variants.TEMPLATE.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"SUPPORT_ANY_BASE_CONVERSION" : "<OFF-default-ON-for-adding-support-for-conversion-strings-to-values-on-any-base>",
"RTOS" : "<one-of-valid-rtos-options----CHIBIOS-FREERTOS>",
"CHIBIOS_SOURCE" : "<path-to-chibios-source-mind-the-forward-slash>",
"CHIBIOS_CONTRIB_REQUIRED" : "OFF-default-ON-to-include_ChibiOS-Contrib-repository-in-the-build",
"CHIBIOS_CONTRIB_SOURCE" : "<path-to-local-ChibiOS-contrib-source-mind-the-forward-slash>",
"CHIBIOS_BOARD" : "<valid-chibios-board-name-from-boards-collection>",
"SWO_OUTPUT" : "OFF-default-ON-to-enable-ARM-CortexM-Single-Wire-Output",
"NF_BUILD_RTM" : "OFF-default-ON-to-enable-RTM-build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ch.h>
#include <hal.h>
#include <nanoPAL_BlockStorage.h>
#include <hal_nf_community.h>

#ifdef __cplusplus
extern "C" {
Expand Down
7 changes: 7 additions & 0 deletions targets/CMSIS-OS/ChibiOS/MBN_QUAIL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ find_package(NF_CoreCLR REQUIRED)
#######################################
# optional

# ChibiOS contrib repo
if(CHIBIOS_CONTRIB_REQUIRED)
find_package(ChibiOS-Contrib REQUIRED)
endif()

# nF feature: debugger
if(NF_FEATURE_DEBUGGER)
find_package(NF_Debugger REQUIRED)
Expand Down Expand Up @@ -98,6 +103,7 @@ add_executable(
${TARGET_CHIBIOS_NANOCLR_SOURCES}

${CHIBIOS_SOURCES}
${CHIBIOS_CONTRIB_SOURCES}
${ChibiOSnfOverlay_SOURCES}

${WireProtocol_SOURCES}
Expand Down Expand Up @@ -127,6 +133,7 @@ include_directories(

${WireProtocol_INCLUDE_DIRS}
${CHIBIOS_INCLUDE_DIRS}
${CHIBIOS_CONTRIB_INCLUDE_DIRS}
${ChibiOSnfOverlay_INCLUDE_DIRS}

${TARGET_CMSIS_COMMON_INCLUDE_DIRS}
Expand Down
5 changes: 0 additions & 5 deletions targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoBooter/halconf_nf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#ifndef _HALCONF_NF_H_
#define _HALCONF_NF_H_

// Enables the ChibiOS community overlay.
#if !defined(HAL_USE_COMMUNITY)
#define HAL_USE_COMMUNITY TRUE
#endif

// enables STM32 Flash driver
#if !defined(HAL_USE_STM32_FLASH)
#define HAL_USE_STM32_FLASH TRUE
Expand Down
5 changes: 0 additions & 5 deletions targets/CMSIS-OS/ChibiOS/MBN_QUAIL/nanoCLR/halconf_nf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#ifndef _HALCONF_NF_H_
#define _HALCONF_NF_H_

// Enables the ChibiOS community overlay.
#if !defined(HAL_USE_COMMUNITY)
#define HAL_USE_COMMUNITY TRUE
#endif

// enables STM32 Flash driver
#if !defined(HAL_USE_STM32_FLASH)
#define HAL_USE_STM32_FLASH TRUE
Expand Down
7 changes: 7 additions & 0 deletions targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ find_package(NF_CoreCLR REQUIRED)
#######################################
# optional

# ChibiOS contrib repo
if(CHIBIOS_CONTRIB_REQUIRED)
find_package(ChibiOS-Contrib REQUIRED)
endif()

# nF feature: debugger
if(NF_FEATURE_DEBUGGER)
find_package(NF_Debugger REQUIRED)
Expand Down Expand Up @@ -98,6 +103,7 @@ add_executable(
${TARGET_CHIBIOS_NANOCLR_SOURCES}

${CHIBIOS_SOURCES}
${CHIBIOS_CONTRIB_SOURCES}
${ChibiOSnfOverlay_SOURCES}

${WireProtocol_SOURCES}
Expand Down Expand Up @@ -127,6 +133,7 @@ include_directories(

${WireProtocol_INCLUDE_DIRS}
${CHIBIOS_INCLUDE_DIRS}
${CHIBIOS_CONTRIB_INCLUDE_DIRS}
${ChibiOSnfOverlay_INCLUDE_DIRS}

${TARGET_CMSIS_COMMON_INCLUDE_DIRS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#ifndef _HALCONF_NF_H_
#define _HALCONF_NF_H_

// Enables the ChibiOS community overlay.
#if !defined(HAL_USE_COMMUNITY)
#define HAL_USE_COMMUNITY TRUE
#endif

// enables STM32 Flash driver
#if !defined(HAL_USE_STM32_FLASH)
#define HAL_USE_STM32_FLASH TRUE
Expand Down
5 changes: 0 additions & 5 deletions targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/nanoCLR/halconf_nf.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#ifndef _HALCONF_NF_H_
#define _HALCONF_NF_H_

// Enables the ChibiOS community overlay.
#if !defined(HAL_USE_COMMUNITY)
#define HAL_USE_COMMUNITY TRUE
#endif

// enables STM32 Flash driver
#if !defined(HAL_USE_STM32_FLASH)
#define HAL_USE_STM32_FLASH TRUE
Expand Down
7 changes: 7 additions & 0 deletions targets/CMSIS-OS/ChibiOS/ST_NUCLEO64_F091RC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ find_package(NF_CoreCLR REQUIRED)
#######################################
# optional

# ChibiOS contrib repo
if(CHIBIOS_CONTRIB_REQUIRED)
find_package(ChibiOS-Contrib REQUIRED)
endif()

# nF feature: debugger
if(NF_FEATURE_DEBUGGER)
find_package(NF_Debugger REQUIRED)
Expand Down Expand Up @@ -99,6 +104,7 @@ add_executable(
${TARGET_CHIBIOS_NANOCLR_SOURCES}

${CHIBIOS_SOURCES}
${CHIBIOS_CONTRIB_SOURCES}
${ChibiOSnfOverlay_SOURCES}

${WireProtocol_SOURCES}
Expand Down Expand Up @@ -128,6 +134,7 @@ include_directories(

${WireProtocol_INCLUDE_DIRS}
${CHIBIOS_INCLUDE_DIRS}
${CHIBIOS_CONTRIB_INCLUDE_DIRS}
${ChibiOSnfOverlay_INCLUDE_DIRS}

${TARGET_CMSIS_COMMON_INCLUDE_DIRS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#ifndef _HALCONF_NF_H_
#define _HALCONF_NF_H_

// Enables the ChibiOS community overlay.
#if !defined(HAL_USE_COMMUNITY)
#define HAL_USE_COMMUNITY TRUE
#endif

// enables STM32 Flash driver
#if !defined(HAL_USE_STM32_FLASH)
#define HAL_USE_STM32_FLASH TRUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#ifndef _HALCONF_NF_H_
#define _HALCONF_NF_H_

// Enables the ChibiOS community overlay.
#if !defined(HAL_USE_COMMUNITY)
#define HAL_USE_COMMUNITY TRUE
#endif

// enables STM32 Flash driver
#if !defined(HAL_USE_STM32_FLASH)
#define HAL_USE_STM32_FLASH TRUE
Expand Down
Loading

0 comments on commit 7c91268

Please sign in to comment.