From 8c8cbb65b08fe7ef8e595209de9443c3d601cc35 Mon Sep 17 00:00:00 2001 From: James Crosby Date: Fri, 19 Jun 2015 12:20:06 +0100 Subject: [PATCH 1/8] initial hard-coded cmake build system for mbed.a --- libraries/mbed/CMakeLists.txt | 84 +++++++++++++++++++++++++++++++++++ libraries/mbed/module.json | 27 +++++++++++ 2 files changed, 111 insertions(+) create mode 100644 libraries/mbed/CMakeLists.txt create mode 100644 libraries/mbed/module.json diff --git a/libraries/mbed/CMakeLists.txt b/libraries/mbed/CMakeLists.txt new file mode 100644 index 0000000000..5b64338653 --- /dev/null +++ b/libraries/mbed/CMakeLists.txt @@ -0,0 +1,84 @@ +#!!! TODO stuff in this pre-amble will be defined by the target description, +#hard-coding for now... + +set(MBED_LEGACY_TARGET_DEFINITIONS "NORDIC" "NRF51822_MKIT" "MCU_NRF51822" "MCU_NORDIC_16K") +set(MBED_LEGACY_TOOLCHAIN "GCC_ARM") +add_definitions("-DNRF51") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") + +# mbed-2 yotta-compatible build system: +# the mbed.a library is built from two sets of source files + include +# directories: +# +# MBED_COMMON_SOURCES: the source files that are the same for all targets, +# these are easily found by globbing: +# +file(GLOB MBED_COMMON_SOURCES "common/*.cpp" "common/*.c") +# +# (always include the hal header directory, too) +set(MBED_COMMON_INCLUDE_DIRS "hal") + +# and MBED_TARGET_SOURCES: these depend on which target we are building for. To +# find these we need to walk the directories in targets/, and wherever we see a +# TARGET_ name, recurse only if matches what we're +# currently building for +macro(mbed_find_target_dirs PARENT_DIRECTORY SOURCES_LIST INCLUDES_LIST) + # append this directory to the search path: + list(APPEND ${INCLUDES_LIST} "${PARENT_DIRECTORY}") + # add all source files in this directory to the sources list: + file(GLOB sources "${PARENT_DIRECTORY}/*.cpp" "${PARENT_DIRECTORY}/*.c") + list(APPEND ${SOURCES_LIST} ${sources}) + + # get a list of all subdirectories that we want to recurse into: + file(GLOB dir_children RELATIVE "${PARENT_DIRECTORY}" "${PARENT_DIRECTORY}/*") + set(matching_subdirs "") + foreach(child ${dir_children}) + if(IS_DIRECTORY "${PARENT_DIRECTORY}/${child}") + # is this directory name a magic one? + if(${child} MATCHES "^TARGET_") + # target-magic: recurse if the MBED_LEGACY_TARGET_DEFINITIONS **list** + # contains a matching value: + foreach(legacy_magic_def ${MBED_LEGACY_TARGET_DEFINITIONS}) + # we could probably unroll the list into a single regex if + # this is a performance problem: + if(${child} MATCHES "^TARGET_${legacy_magic_def}$") + list(APPEND matching_subdirs ${child}) + break() + endif() + endforeach() + elseif(${child} MATCHES "^TOOLCHAIN_") + if(${child} MATCHES "^TOOLCHAIN_${MBED_LEGACY_TOOLCHAIN}$") + # toolchain-magic: (recurse if the MBED_LEGACY_TOOLCHAIN matches + # this name) + list(APPEND matching_subdirs ${child}) + endif() + else() + # not special: always recurse into this directory + list(APPEND matching_subdirs ${child}) + endif() + endif() + endforeach() + #message("matching_subdirs: ${matching_subdirs}") + + # recurse: + foreach(subdir ${matching_subdirs}) + mbed_find_target_dirs("${PARENT_DIRECTORY}/${subdir}" ${SOURCES_LIST} ${INCLUDES_LIST}) + endforeach() +endmacro() + +set(MBED_TARGET_SOURCES "") +set(MBED_TARGET_INCLUDE_DIRS "") +mbed_find_target_dirs("${CMAKE_CURRENT_SOURCE_DIR}/targets" MBED_TARGET_SOURCES MBED_TARGET_INCLUDE_DIRS) +#message("found target sources: ${MBED_TARGET_SOURCES}") +#message("found target include dirs: ${MBED_TARGET_INCLUDE_DIRS}") + +# finally, we can construct a library using the determined set of include paths +# + source files. Note that the library name must match the name of the yotta +# module (defined in module.json) for this module to link properly with other +# yotta modules. +include_directories(${MBED_COMMON_INCLUDE_DIRS}) +include_directories(${MBED_TARGET_INCLUDE_DIRS}) +add_library(mbed + ${MBED_COMMON_SOURCES} + ${MBED_TARGET_SOURCES} +) diff --git a/libraries/mbed/module.json b/libraries/mbed/module.json new file mode 100644 index 0000000000..37a5e33d98 --- /dev/null +++ b/libraries/mbed/module.json @@ -0,0 +1,27 @@ +{ + "name": "mbed", + "version": "2.0.0-a0", + "description": "mbed SDK (for mbed 2.0)", + "keywords": [ + "mbed" + ], + "author": "Bogdan Marinescu ", + "repository": { + "url": "git@github.com:mbedmicro/mbed.git", + "type": "git" + }, + "homepage": "https://github.com/mbedmicro/mbed", + "licenses": [ + { + "url": "https://spdx.org/licenses/Apache-2.0", + "type": "Apache-2.0" + } + ], + "extraIncludes": [ + "api" + ], + "dependencies": { + }, + "targetDependencies": { + } +} From 616be98175045a7e8486bea5420c0693737d144e Mon Sep 17 00:00:00 2001 From: James Crosby Date: Fri, 19 Jun 2015 13:21:42 +0100 Subject: [PATCH 2/8] make sure assembly files are included --- libraries/mbed/CMakeLists.txt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libraries/mbed/CMakeLists.txt b/libraries/mbed/CMakeLists.txt index 5b64338653..76866ced2e 100644 --- a/libraries/mbed/CMakeLists.txt +++ b/libraries/mbed/CMakeLists.txt @@ -6,7 +6,15 @@ set(MBED_LEGACY_TOOLCHAIN "GCC_ARM") add_definitions("-DNRF51") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") -# mbed-2 yotta-compatible build system: +# +# mbed-2 yotta-compatible build system +# + +# make sure necessary features are enabled: +project(mbed) +enable_language(ASM) + + # the mbed.a library is built from two sets of source files + include # directories: # @@ -26,7 +34,7 @@ macro(mbed_find_target_dirs PARENT_DIRECTORY SOURCES_LIST INCLUDES_LIST) # append this directory to the search path: list(APPEND ${INCLUDES_LIST} "${PARENT_DIRECTORY}") # add all source files in this directory to the sources list: - file(GLOB sources "${PARENT_DIRECTORY}/*.cpp" "${PARENT_DIRECTORY}/*.c") + file(GLOB sources "${PARENT_DIRECTORY}/*.cpp" "${PARENT_DIRECTORY}/*.c" "${PARENT_DIRECTORY}/*.s" "${PARENT_DIRECTORY}/*.S" ) list(APPEND ${SOURCES_LIST} ${sources}) # get a list of all subdirectories that we want to recurse into: @@ -47,9 +55,9 @@ macro(mbed_find_target_dirs PARENT_DIRECTORY SOURCES_LIST INCLUDES_LIST) endif() endforeach() elseif(${child} MATCHES "^TOOLCHAIN_") + # toolchain-magic: (recurse if the MBED_LEGACY_TOOLCHAIN matches + # this name) if(${child} MATCHES "^TOOLCHAIN_${MBED_LEGACY_TOOLCHAIN}$") - # toolchain-magic: (recurse if the MBED_LEGACY_TOOLCHAIN matches - # this name) list(APPEND matching_subdirs ${child}) endif() else() From 79492c0b71407f45ceebbdb13080f24ee8263243 Mon Sep 17 00:00:00 2001 From: James Crosby Date: Fri, 19 Jun 2015 13:23:44 +0100 Subject: [PATCH 3/8] child could in theory have spaces, so quote it --- libraries/mbed/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/mbed/CMakeLists.txt b/libraries/mbed/CMakeLists.txt index 76866ced2e..8befb60760 100644 --- a/libraries/mbed/CMakeLists.txt +++ b/libraries/mbed/CMakeLists.txt @@ -43,26 +43,26 @@ macro(mbed_find_target_dirs PARENT_DIRECTORY SOURCES_LIST INCLUDES_LIST) foreach(child ${dir_children}) if(IS_DIRECTORY "${PARENT_DIRECTORY}/${child}") # is this directory name a magic one? - if(${child} MATCHES "^TARGET_") + if("${child}" MATCHES "^TARGET_") # target-magic: recurse if the MBED_LEGACY_TARGET_DEFINITIONS **list** # contains a matching value: foreach(legacy_magic_def ${MBED_LEGACY_TARGET_DEFINITIONS}) # we could probably unroll the list into a single regex if # this is a performance problem: - if(${child} MATCHES "^TARGET_${legacy_magic_def}$") + if("${child}" MATCHES "^TARGET_${legacy_magic_def}$") list(APPEND matching_subdirs ${child}) break() endif() endforeach() - elseif(${child} MATCHES "^TOOLCHAIN_") + elseif("${child}" MATCHES "^TOOLCHAIN_") # toolchain-magic: (recurse if the MBED_LEGACY_TOOLCHAIN matches # this name) - if(${child} MATCHES "^TOOLCHAIN_${MBED_LEGACY_TOOLCHAIN}$") - list(APPEND matching_subdirs ${child}) + if("${child}" MATCHES "^TOOLCHAIN_${MBED_LEGACY_TOOLCHAIN}$") + list(APPEND matching_subdirs "${child}") endif() else() # not special: always recurse into this directory - list(APPEND matching_subdirs ${child}) + list(APPEND matching_subdirs "${child}") endif() endif() endforeach() From 07f200e9187494488153d64bd6e329017c47ff01 Mon Sep 17 00:00:00 2001 From: James Crosby Date: Mon, 22 Jun 2015 11:41:10 +0100 Subject: [PATCH 4/8] rename module to mbed-classic --- libraries/mbed/module.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/mbed/module.json b/libraries/mbed/module.json index 37a5e33d98..f548728fa4 100644 --- a/libraries/mbed/module.json +++ b/libraries/mbed/module.json @@ -1,7 +1,7 @@ { - "name": "mbed", - "version": "2.0.0-a0", - "description": "mbed SDK (for mbed 2.0)", + "name": "mbed-classic", + "version": "0.0.1", + "description": "mbed core SDK (for mbed 2.0, *not* mbedOS)", "keywords": [ "mbed" ], From 3ba321b25952d781249a9f601391c4e3f43de8e4 Mon Sep 17 00:00:00 2001 From: James Crosby Date: Mon, 22 Jun 2015 12:38:09 +0100 Subject: [PATCH 5/8] necessary definitions for backwards-compatibility build system have been added to target descriptions now, remove them from the CMakeLists.txt here --- libraries/mbed/CMakeLists.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/libraries/mbed/CMakeLists.txt b/libraries/mbed/CMakeLists.txt index 8befb60760..cbba0a754e 100644 --- a/libraries/mbed/CMakeLists.txt +++ b/libraries/mbed/CMakeLists.txt @@ -1,11 +1,3 @@ -#!!! TODO stuff in this pre-amble will be defined by the target description, -#hard-coding for now... - -set(MBED_LEGACY_TARGET_DEFINITIONS "NORDIC" "NRF51822_MKIT" "MCU_NRF51822" "MCU_NORDIC_16K") -set(MBED_LEGACY_TOOLCHAIN "GCC_ARM") -add_definitions("-DNRF51") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") - # # mbed-2 yotta-compatible build system # @@ -14,6 +6,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") project(mbed) enable_language(ASM) +# override compilation flags: +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") # the mbed.a library is built from two sets of source files + include # directories: From 3cf18be9ee753b88b09df2d7e4effcdd83f5d1ab Mon Sep 17 00:00:00 2001 From: James Crosby Date: Tue, 23 Jun 2015 16:29:04 +0100 Subject: [PATCH 6/8] use mbed-classic as the module name; use YOTTA_GLOBAL_INCLUDE_DIRS --- libraries/mbed/CMakeLists.txt | 12 ++++++++++-- libraries/mbed/module.json | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/mbed/CMakeLists.txt b/libraries/mbed/CMakeLists.txt index cbba0a754e..bdc3649675 100644 --- a/libraries/mbed/CMakeLists.txt +++ b/libraries/mbed/CMakeLists.txt @@ -3,7 +3,7 @@ # # make sure necessary features are enabled: -project(mbed) +project(mbed-classic) enable_language(ASM) # override compilation flags: @@ -74,13 +74,21 @@ mbed_find_target_dirs("${CMAKE_CURRENT_SOURCE_DIR}/targets" MBED_TARGET_SOURCES #message("found target sources: ${MBED_TARGET_SOURCES}") #message("found target include dirs: ${MBED_TARGET_INCLUDE_DIRS}") +# we have to append any target-specific include dirs to the global include dirs +# list, so that any indirect includes (e.g. via mbed.h) of files in those +# directories will work: +# (non-target-specific include dirs are listed in extraIncludes in module.json) +foreach(dir ${MBED_TARGET_INCLUDE_DIRS}) + set_property(GLOBAL APPEND PROPERTY YOTTA_GLOBAL_INCLUDE_DIRS ${dir}) +endforeach() + # finally, we can construct a library using the determined set of include paths # + source files. Note that the library name must match the name of the yotta # module (defined in module.json) for this module to link properly with other # yotta modules. include_directories(${MBED_COMMON_INCLUDE_DIRS}) include_directories(${MBED_TARGET_INCLUDE_DIRS}) -add_library(mbed +add_library(mbed-classic ${MBED_COMMON_SOURCES} ${MBED_TARGET_SOURCES} ) diff --git a/libraries/mbed/module.json b/libraries/mbed/module.json index f548728fa4..d98a54a260 100644 --- a/libraries/mbed/module.json +++ b/libraries/mbed/module.json @@ -18,7 +18,10 @@ } ], "extraIncludes": [ - "api" + "api", + "hal", + "targets/hal", + "targets/cmsis" ], "dependencies": { }, From ca3e1315263c71873150c10dad01cade2524902f Mon Sep 17 00:00:00 2001 From: James Crosby Date: Fri, 26 Jun 2015 16:27:23 +0100 Subject: [PATCH 7/8] only set -std=gnu99 if we're compiling with a GNU compiler --- libraries/mbed/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/mbed/CMakeLists.txt b/libraries/mbed/CMakeLists.txt index bdc3649675..19ae33fe61 100644 --- a/libraries/mbed/CMakeLists.txt +++ b/libraries/mbed/CMakeLists.txt @@ -7,7 +7,9 @@ project(mbed-classic) enable_language(ASM) # override compilation flags: -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") +if(CMAKE_C_COMPILER_ID MATCHES GNU) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") +endif() # the mbed.a library is built from two sets of source files + include # directories: From 9e87f22dfedb63413fe8f9b2745ec5a083485e7c Mon Sep 17 00:00:00 2001 From: James Crosby Date: Fri, 26 Jun 2015 18:42:12 +0100 Subject: [PATCH 8/8] ensure startup code is included when building for armcc --- libraries/mbed/CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libraries/mbed/CMakeLists.txt b/libraries/mbed/CMakeLists.txt index 19ae33fe61..6e42617341 100644 --- a/libraries/mbed/CMakeLists.txt +++ b/libraries/mbed/CMakeLists.txt @@ -76,6 +76,22 @@ mbed_find_target_dirs("${CMAKE_CURRENT_SOURCE_DIR}/targets" MBED_TARGET_SOURCES #message("found target sources: ${MBED_TARGET_SOURCES}") #message("found target include dirs: ${MBED_TARGET_INCLUDE_DIRS}") +# unfortunately, for ARMCC, the startup code needs to be provided as an object +# on the command line (not as part of an archive). To do this we override the +# CMake add_executable command. +if(CMAKE_C_COMPILER_ID STREQUAL "ARMCC") + set(MBED_TARGET_STARTUP_CODE_SOURCES "") + foreach(src ${MBED_TARGET_SOURCES}) + if("${src}" MATCHES .*startup_.*\\.[sS]) + LIST(APPEND MBED_TARGET_STARTUP_CODE_SOURCES "${src}") + endif() + endforeach() + add_library(mbed_classic_startupcod OBJECT ${MBED_TARGET_STARTUP_CODE_SOURCES}) + macro (add_executable _name) + _add_executable(${ARGV} $) + endmacro() +endif() + # we have to append any target-specific include dirs to the global include dirs # list, so that any indirect includes (e.g. via mbed.h) of files in those # directories will work: