Skip to content

Commit

Permalink
Start on adding Arduino Giga support
Browse files Browse the repository at this point in the history
  • Loading branch information
multiplemonomials committed Jun 22, 2024
1 parent 182829f commit 8e24e3c
Show file tree
Hide file tree
Showing 35 changed files with 220,351 additions and 300 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-cores.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- ARDUINO_NANO33BLE
- RASPBERRY_PI_PICO
- ARDUINO_NICLA_SENSE_ME
- ARDUINO_GIGA_CM7
cmake_build_type:
- Debug
- Release
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/publish-release-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ on:
permissions:
contents: write


# This workflow run fires whenever a tag is created, and downloads all compiled cores and publishes them
# as part of the release.
# It does have one limitation: you have to manually ensure this workflow gets run after all the build-core
# workflow runs are completed. I couldn't find a way to make it wait automatically.

jobs:
release:
name: Create Release with Artifacts
Expand Down
137 changes: 19 additions & 118 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ elseif("RASPBERRY_PI_PICO" IN_LIST MBED_TARGET_LABELS)
set(ARDUINO_VARIANT_NAME "RASPBERRY_PI_PICO")
elseif("ARDUINO_NICLA_SENSE_ME" IN_LIST MBED_TARGET_LABELS)
set(ARDUINO_VARIANT_NAME "ARDUINO_NICLA_SENSE_ME")
elseif("ARDUINO_GIGA" IN_LIST MBED_TARGET_LABELS)
set(ARDUINO_VARIANT_NAME "ARDUINO_GIGA")
else()
message(FATAL_ERROR "This MBED_TARGET is currently not supported by the arduino core!")
endif()
Expand Down Expand Up @@ -80,8 +82,8 @@ endif()

if("FEATURE_BLE=1" IN_LIST MBED_TARGET_DEFINITIONS)

# Note: There are circular dependencies between the BLE libraries, so we have to list some of them twice.
list(APPEND MBED_LIBS_TO_INSTALL
# Note: There are circular dependencies between the BLE libraries, so we have to list some of them multiple times.
set(BLE_LIBRARIES
mbed-ble
mbed-ble-cordio_ll
mbed-ble-cordio
Expand All @@ -91,6 +93,20 @@ if("FEATURE_BLE=1" IN_LIST MBED_TARGET_DEFINITIONS)
mbed-ble
mbed-ble-cordio_ll
mbed-ble-cordio)

# filter out any Cordio libraries that don't exist for the current target
foreach(LIBRARY ${BLE_LIBRARIES})
if(NOT TARGET ${LIBRARY})
list(REMOVE_ITEM BLE_LIBRARIES ${LIBRARY})
endif()
endforeach()

list(APPEND MBED_LIBS_TO_INSTALL ${BLE_LIBRARIES})
endif()

if("COMPONENT_QSPIF=1" IN_LIST MBED_TARGET_DEFINITIONS)
list(APPEND MBED_LIBS_TO_INSTALL
mbed-storage-qspif)
endif()

# We also need to know about any precompiled .a files
Expand All @@ -115,122 +131,7 @@ install(TARGETS ${MBED_UNIQUE_LIBS_TO_INSTALL} DESTINATION "variants/${ARDUINO_V

# Generate compile option files for Arduino IDE
# ---------------------------------------------------------

# Iterate though the Mbed main build target and the optional targets and collect include dirs / defines / etc.
set(TARGETS_TO_SCAN mbed-os ${MBED_UNIQUE_LIBS_TO_INSTALL})
set(SCANNED_INCLUDE_DIRS "")
set(SCANNED_DEFINES "")
foreach(TARGET ${TARGETS_TO_SCAN})
get_property(TARGET_INCLUDE_DIRS TARGET ${TARGET} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(TARGET_COMPILE_DEFINITIONS TARGET ${TARGET} PROPERTY INTERFACE_COMPILE_DEFINITIONS)

# For include dirs, if the include dir points to generated-headers, that's in the bin dir so we will handle it separately.
foreach(INCLUDE_DIR ${TARGET_INCLUDE_DIRS})
if(NOT "${INCLUDE_DIR}" MATCHES "generated-headers")
list(APPEND SCANNED_INCLUDE_DIRS ${INCLUDE_DIR})
endif()
endforeach()

# Defines can just be passed through
list(APPEND SCANNED_DEFINES ${TARGET_COMPILE_DEFINITIONS})
endforeach()

# Generate defines file.
# TODO do we need to escape defines with spaces?
set(DEFINES_TXT_CONTENTS "")
foreach(DEFINE ${SCANNED_DEFINES})
string(APPEND DEFINES_TXT_CONTENTS "-D${DEFINE}\n")
endforeach()
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/defines.txt CONTENT ${DEFINES_TXT_CONTENTS})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/defines.txt DESTINATION "variants/${ARDUINO_VARIANT_NAME}")

# Generate includes file.
set(INCLUDES_TXT_CONTENTS "")
foreach(INCLUDE_DIR ${SCANNED_INCLUDE_DIRS})

# Make each include path relative to the current source dir
# (so it starts with the first path component after mbed-os/)
cmake_path(RELATIVE_PATH INCLUDE_DIR BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os OUTPUT_VARIABLE REL_INCLUDE_DIR)

string(APPEND INCLUDES_TXT_CONTENTS "-iwithprefixbefore/mbed/${REL_INCLUDE_DIR}\n")
endforeach()
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/includes.txt CONTENT ${INCLUDES_TXT_CONTENTS})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/includes.txt DESTINATION "variants/${ARDUINO_VARIANT_NAME}")

# Generate compile options files.
foreach(LANG C CXX)

# The profile-specific compile options are set as a property on the mbed-core-flags
# target so they get applied everywhere.
# (see e.g. profiles/develop.cmake)
get_property(MBED_${LANG}_PROFILE_COMPILE_FLAGS TARGET mbed-core-flags PROPERTY INTERFACE_COMPILE_OPTIONS)

# Slightly janky, but we need to simulate expanding the generator expressions in this property.
# Use a regex to replace the generator expressions for the language we want, and then
# use another regex to get rid of the genexes for the other languages.
string(REGEX REPLACE
"\\$<\\$<COMPILE_LANGUAGE:${LANG}>:([^>]+)>" "\\1"
MBED_${LANG}_PROFILE_COMPILE_FLAGS "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}")
string(GENEX_STRIP "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}" MBED_${LANG}_PROFILE_COMPILE_FLAGS)

# For the profile flags, we want to strip out the "-include;xxx/mbed-target-config.h" flag
# as it contains a path specific to the build machine and isn't needed by Arduino anyway.
# So, remove "-include" and the option after it.
string(REGEX REPLACE
"-include;[^;]+" ""
MBED_${LANG}_PROFILE_COMPILE_FLAGS "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}")

# for the toolchain flags (processor target, warnings, etc) those get put in CMAKE_<LANG>_FLAGS
# by the app.cmake toolchain file.
separate_arguments(CMAKE_${LANG}_FLAGS_LIST NATIVE_COMMAND ${CMAKE_${LANG}_FLAGS})

# Annoyingly, the "--std" argument won't be in these lists because it's added by CMake.
# We'll have to do that ourselves.
if(${LANG} STREQUAL "C")
set(C_STD_ARGUMENT --std=gnu${CMAKE_C_STANDARD})
else() # CXX
set(CXX_STD_ARGUMENT --std=gnu++${CMAKE_CXX_STANDARD})
endif()

set(MBED_${LANG}_COMPILE_FLAGS
${MBED_${LANG}_PROFILE_COMPILE_FLAGS}
${CMAKE_${LANG}_FLAGS_LIST}
${${LANG}_STD_ARGUMENT})

# Write list to a file, with one element on each line
list(JOIN MBED_${LANG}_COMPILE_FLAGS "\n" ${LANG}_FLAG_FILE_CONTENTS)
string(TOLOWER "${LANG}flags.txt" ${LANG}_FLAG_FILE_NAME)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FLAG_FILE_NAME}
CONTENT "${${LANG}_FLAG_FILE_CONTENTS}")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FLAG_FILE_NAME}
DESTINATION variants/${ARDUINO_VARIANT_NAME})
endforeach()

# Generate linker options file

# The profile-specific linker options are set as a property on the mbed-core-flags
# target so they get applied everywhere.
# (see e.g. profiles/develop.cmake)
get_property(MBED_PROFILE_LINKER_FLAGS TARGET mbed-core-flags PROPERTY INTERFACE_LINK_OPTIONS)

# for the toolchain flags (processor target, warnings, etc) those get put in CMAKE_<LANG>_FLAGS
# by the app.cmake toolchain file.
separate_arguments(CMAKE_EXE_LINKER_FLAGS_LIST NATIVE_COMMAND ${CMAKE_EXE_LINKER_FLAGS})

set(MBED_LINKER_FLAGS
${MBED_PROFILE_LINKER_FLAGS}
${CMAKE_EXE_LINKER_FLAGS_LIST})

# Write list to a file, with one element on each line
list(JOIN MBED_LINKER_FLAGS "\n" LD_FLAG_FILE_CONTENTS)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ldflags.txt
CONTENT "${LD_FLAG_FILE_CONTENTS}")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/ldflags.txt
DESTINATION variants/${ARDUINO_VARIANT_NAME})
include(GenerateArduinoIDEFlagTxtFiles.cmake)

# Copy sources and headers into the install dir as needed
# ---------------------------------------------------------
Expand Down
120 changes: 120 additions & 0 deletions GenerateArduinoIDEFlagTxtFiles.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
##
## This script scans the Mbed CMake targets and collects lists of compiler options.
## It then writes those lists out to text files for the Arduino IDE ot use
##

# Iterate though the Mbed main build target and the optional targets and collect include dirs / defines / etc.
set(TARGETS_TO_SCAN mbed-os ${MBED_UNIQUE_LIBS_TO_INSTALL})
set(SCANNED_INCLUDE_DIRS "")
set(SCANNED_DEFINES "")
foreach(TARGET ${TARGETS_TO_SCAN})
get_property(TARGET_INCLUDE_DIRS TARGET ${TARGET} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(TARGET_COMPILE_DEFINITIONS TARGET ${TARGET} PROPERTY INTERFACE_COMPILE_DEFINITIONS)

# For include dirs, if the include dir points to generated-headers, that's in the bin dir so we will handle it separately.
foreach(INCLUDE_DIR ${TARGET_INCLUDE_DIRS})
if(NOT "${INCLUDE_DIR}" MATCHES "generated-headers")
list(APPEND SCANNED_INCLUDE_DIRS ${INCLUDE_DIR})
endif()
endforeach()

# Defines can just be passed through
list(APPEND SCANNED_DEFINES ${TARGET_COMPILE_DEFINITIONS})
endforeach()

# Generate defines file (defines.txt)
# TODO do we need to escape defines with spaces?
set(DEFINES_TXT_CONTENTS "")
foreach(DEFINE ${SCANNED_DEFINES})
string(APPEND DEFINES_TXT_CONTENTS "-D${DEFINE}\n")
endforeach()
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/defines.txt CONTENT ${DEFINES_TXT_CONTENTS})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/defines.txt DESTINATION "variants/${ARDUINO_VARIANT_NAME}")

# Generate includes file (includes.txt)
set(INCLUDES_TXT_CONTENTS "")
foreach(INCLUDE_DIR ${SCANNED_INCLUDE_DIRS})

# Make each include path relative to the current source dir
# (so it starts with the first path component after mbed-os/)
cmake_path(RELATIVE_PATH INCLUDE_DIR BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os OUTPUT_VARIABLE REL_INCLUDE_DIR)

string(APPEND INCLUDES_TXT_CONTENTS "-iwithprefixbefore/mbed/${REL_INCLUDE_DIR}\n")
endforeach()
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/includes.txt CONTENT ${INCLUDES_TXT_CONTENTS})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/includes.txt DESTINATION "variants/${ARDUINO_VARIANT_NAME}")

# Generate compile options files (cflags.txt and cxxflags.txt)
foreach(LANG C CXX)

# The profile-specific compile options are set as a property on the mbed-core-flags
# target so they get applied everywhere.
# (see e.g. profiles/develop.cmake)
get_property(MBED_${LANG}_PROFILE_COMPILE_FLAGS TARGET mbed-core-flags PROPERTY INTERFACE_COMPILE_OPTIONS)

# Slightly janky, but we need to simulate expanding the generator expressions in this property.
# Use a regex to replace the generator expressions for the language we want, and then
# use another regex to get rid of the genexes for the other languages.
string(REGEX REPLACE
"\\$<\\$<COMPILE_LANGUAGE:${LANG}>:([^>]+)>" "\\1"
MBED_${LANG}_PROFILE_COMPILE_FLAGS "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}")
string(GENEX_STRIP "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}" MBED_${LANG}_PROFILE_COMPILE_FLAGS)

# For the profile flags, we want to strip out the "-include;xxx/mbed-target-config.h" flag
# as it contains a path specific to the build machine and isn't needed by Arduino anyway.
# So, remove "-include" and the option after it.
string(REGEX REPLACE
"-include;[^;]+" ""
MBED_${LANG}_PROFILE_COMPILE_FLAGS "${MBED_${LANG}_PROFILE_COMPILE_FLAGS}")

# for the toolchain flags (processor target, warnings, etc) those get put in CMAKE_<LANG>_FLAGS
# by the app.cmake toolchain file.
separate_arguments(CMAKE_${LANG}_FLAGS_LIST NATIVE_COMMAND ${CMAKE_${LANG}_FLAGS})

# Annoyingly, the "--std" argument won't be in these lists because it's added by CMake.
# We'll have to do that ourselves.
if(${LANG} STREQUAL "C")
set(C_STD_ARGUMENT --std=gnu${CMAKE_C_STANDARD})
else() # CXX
set(CXX_STD_ARGUMENT --std=gnu++${CMAKE_CXX_STANDARD})
endif()

set(MBED_${LANG}_COMPILE_FLAGS
${MBED_${LANG}_PROFILE_COMPILE_FLAGS}
${CMAKE_${LANG}_FLAGS_LIST}
${${LANG}_STD_ARGUMENT})

# Write list to a file, with one element on each line
list(JOIN MBED_${LANG}_COMPILE_FLAGS "\n" ${LANG}_FLAG_FILE_CONTENTS)
string(TOLOWER "${LANG}flags.txt" ${LANG}_FLAG_FILE_NAME)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FLAG_FILE_NAME}
CONTENT "${${LANG}_FLAG_FILE_CONTENTS}")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FLAG_FILE_NAME}
DESTINATION variants/${ARDUINO_VARIANT_NAME})
endforeach()

# Generate linker options file (ldflags.txt)

# The profile-specific linker options are set as a property on the mbed-core-flags
# target so they get applied everywhere.
# (see e.g. profiles/develop.cmake)
get_property(MBED_PROFILE_LINKER_FLAGS TARGET mbed-core-flags PROPERTY INTERFACE_LINK_OPTIONS)

# for the toolchain flags (processor target, warnings, etc) those get put in CMAKE_<LANG>_FLAGS
# by the app.cmake toolchain file.
separate_arguments(CMAKE_EXE_LINKER_FLAGS_LIST NATIVE_COMMAND ${CMAKE_EXE_LINKER_FLAGS})

set(MBED_LINKER_FLAGS
${MBED_PROFILE_LINKER_FLAGS}
${CMAKE_EXE_LINKER_FLAGS_LIST})

# Write list to a file, with one element on each line
list(JOIN MBED_LINKER_FLAGS "\n" LD_FLAG_FILE_CONTENTS)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ldflags.txt
CONTENT "${LD_FLAG_FILE_CONTENTS}")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/ldflags.txt
DESTINATION variants/${ARDUINO_VARIANT_NAME})
2 changes: 2 additions & 0 deletions cores/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ if("RASPBERRY_PI_PICO" IN_LIST MBED_TARGET_LABELS)
target_compile_definitions(arduino-core PUBLIC ARDUINO_ARCH_RP2040)
elseif("ARDUINO_NANO33BLE" IN_LIST MBED_TARGET_LABELS)
target_compile_definitions(arduino-core PUBLIC ARDUINO_ARCH_NRF52840)
elseif("ARDUINO_GIGA" IN_LIST MBED_TARGET_LABELS)
target_compile_definitions(arduino-core PUBLIC ARDUINO_GIGA ARDUINO_ARCH_GIGA GIGA_PINS)
endif()
Loading

0 comments on commit 8e24e3c

Please sign in to comment.