mbed library sources. Supersedes mbed-src. GR-PEACH runs on RAM.

Fork of mbed-dev by mbed official

Committer:
1050186
Date:
Wed Mar 30 11:41:25 2016 +0000
Revision:
103:493a29d2d4d7
Parent:
0:9b334a45a8ff
GR-PEACH runs on RAM.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 0:9b334a45a8ff 1 #
bogdanm 0:9b334a45a8ff 2 # mbed-2 yotta-compatible build system
bogdanm 0:9b334a45a8ff 3 #
bogdanm 0:9b334a45a8ff 4
bogdanm 0:9b334a45a8ff 5 # make sure necessary features are enabled:
bogdanm 0:9b334a45a8ff 6 project(mbed-classic)
bogdanm 0:9b334a45a8ff 7 enable_language(ASM)
bogdanm 0:9b334a45a8ff 8
bogdanm 0:9b334a45a8ff 9 # override compilation flags:
bogdanm 0:9b334a45a8ff 10 if(CMAKE_C_COMPILER_ID MATCHES GNU)
bogdanm 0:9b334a45a8ff 11 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
bogdanm 0:9b334a45a8ff 12 endif()
bogdanm 0:9b334a45a8ff 13
bogdanm 0:9b334a45a8ff 14 # the mbed.a library is built from two sets of source files + include
bogdanm 0:9b334a45a8ff 15 # directories:
bogdanm 0:9b334a45a8ff 16 #
bogdanm 0:9b334a45a8ff 17 # MBED_COMMON_SOURCES: the source files that are the same for all targets,
bogdanm 0:9b334a45a8ff 18 # these are easily found by globbing:
bogdanm 0:9b334a45a8ff 19 #
bogdanm 0:9b334a45a8ff 20 file(GLOB MBED_COMMON_SOURCES "common/*.cpp" "common/*.c")
bogdanm 0:9b334a45a8ff 21 #
bogdanm 0:9b334a45a8ff 22 # (always include the hal header directory, too)
bogdanm 0:9b334a45a8ff 23 set(MBED_COMMON_INCLUDE_DIRS "hal")
bogdanm 0:9b334a45a8ff 24
bogdanm 0:9b334a45a8ff 25 # and MBED_TARGET_SOURCES: these depend on which target we are building for. To
bogdanm 0:9b334a45a8ff 26 # find these we need to walk the directories in targets/, and wherever we see a
bogdanm 0:9b334a45a8ff 27 # TARGET_<something> name, recurse only if <something> matches what we're
bogdanm 0:9b334a45a8ff 28 # currently building for
bogdanm 0:9b334a45a8ff 29 macro(mbed_find_target_dirs PARENT_DIRECTORY SOURCES_LIST INCLUDES_LIST)
bogdanm 0:9b334a45a8ff 30 # append this directory to the search path:
bogdanm 0:9b334a45a8ff 31 list(APPEND ${INCLUDES_LIST} "${PARENT_DIRECTORY}")
bogdanm 0:9b334a45a8ff 32 # add all source files in this directory to the sources list:
bogdanm 0:9b334a45a8ff 33 file(GLOB sources "${PARENT_DIRECTORY}/*.cpp" "${PARENT_DIRECTORY}/*.c" "${PARENT_DIRECTORY}/*.s" "${PARENT_DIRECTORY}/*.S" )
bogdanm 0:9b334a45a8ff 34 list(APPEND ${SOURCES_LIST} ${sources})
bogdanm 0:9b334a45a8ff 35
bogdanm 0:9b334a45a8ff 36 # get a list of all subdirectories that we want to recurse into:
bogdanm 0:9b334a45a8ff 37 file(GLOB dir_children RELATIVE "${PARENT_DIRECTORY}" "${PARENT_DIRECTORY}/*")
bogdanm 0:9b334a45a8ff 38 set(matching_subdirs "")
bogdanm 0:9b334a45a8ff 39 foreach(child ${dir_children})
bogdanm 0:9b334a45a8ff 40 if(IS_DIRECTORY "${PARENT_DIRECTORY}/${child}")
bogdanm 0:9b334a45a8ff 41 # is this directory name a magic one?
bogdanm 0:9b334a45a8ff 42 if("${child}" MATCHES "^TARGET_")
bogdanm 0:9b334a45a8ff 43 # target-magic: recurse if the MBED_LEGACY_TARGET_DEFINITIONS **list**
bogdanm 0:9b334a45a8ff 44 # contains a matching value:
bogdanm 0:9b334a45a8ff 45 foreach(legacy_magic_def ${MBED_LEGACY_TARGET_DEFINITIONS})
bogdanm 0:9b334a45a8ff 46 # we could probably unroll the list into a single regex if
bogdanm 0:9b334a45a8ff 47 # this is a performance problem:
bogdanm 0:9b334a45a8ff 48 if("${child}" MATCHES "^TARGET_${legacy_magic_def}$")
bogdanm 0:9b334a45a8ff 49 list(APPEND matching_subdirs ${child})
bogdanm 0:9b334a45a8ff 50 break()
bogdanm 0:9b334a45a8ff 51 endif()
bogdanm 0:9b334a45a8ff 52 endforeach()
bogdanm 0:9b334a45a8ff 53 elseif("${child}" MATCHES "^TOOLCHAIN_")
bogdanm 0:9b334a45a8ff 54 # toolchain-magic: (recurse if the MBED_LEGACY_TOOLCHAIN matches
bogdanm 0:9b334a45a8ff 55 # this name)
bogdanm 0:9b334a45a8ff 56 if("${child}" MATCHES "^TOOLCHAIN_${MBED_LEGACY_TOOLCHAIN}$")
bogdanm 0:9b334a45a8ff 57 list(APPEND matching_subdirs "${child}")
bogdanm 0:9b334a45a8ff 58 endif()
bogdanm 0:9b334a45a8ff 59 else()
bogdanm 0:9b334a45a8ff 60 # not special: always recurse into this directory
bogdanm 0:9b334a45a8ff 61 list(APPEND matching_subdirs "${child}")
bogdanm 0:9b334a45a8ff 62 endif()
bogdanm 0:9b334a45a8ff 63 endif()
bogdanm 0:9b334a45a8ff 64 endforeach()
bogdanm 0:9b334a45a8ff 65 #message("matching_subdirs: ${matching_subdirs}")
bogdanm 0:9b334a45a8ff 66
bogdanm 0:9b334a45a8ff 67 # recurse:
bogdanm 0:9b334a45a8ff 68 foreach(subdir ${matching_subdirs})
bogdanm 0:9b334a45a8ff 69 mbed_find_target_dirs("${PARENT_DIRECTORY}/${subdir}" ${SOURCES_LIST} ${INCLUDES_LIST})
bogdanm 0:9b334a45a8ff 70 endforeach()
bogdanm 0:9b334a45a8ff 71 endmacro()
bogdanm 0:9b334a45a8ff 72
bogdanm 0:9b334a45a8ff 73 set(MBED_TARGET_SOURCES "")
bogdanm 0:9b334a45a8ff 74 set(MBED_TARGET_INCLUDE_DIRS "")
bogdanm 0:9b334a45a8ff 75 mbed_find_target_dirs("${CMAKE_CURRENT_SOURCE_DIR}/targets" MBED_TARGET_SOURCES MBED_TARGET_INCLUDE_DIRS)
bogdanm 0:9b334a45a8ff 76 #message("found target sources: ${MBED_TARGET_SOURCES}")
bogdanm 0:9b334a45a8ff 77 #message("found target include dirs: ${MBED_TARGET_INCLUDE_DIRS}")
bogdanm 0:9b334a45a8ff 78
bogdanm 0:9b334a45a8ff 79 # unfortunately, for ARMCC, the startup code needs to be provided as an object
bogdanm 0:9b334a45a8ff 80 # on the command line (not as part of an archive). To do this we override the
bogdanm 0:9b334a45a8ff 81 # CMake add_executable command.
bogdanm 0:9b334a45a8ff 82 if(CMAKE_C_COMPILER_ID STREQUAL "ARMCC")
bogdanm 0:9b334a45a8ff 83 set(MBED_TARGET_STARTUP_CODE_SOURCES "")
bogdanm 0:9b334a45a8ff 84 foreach(src ${MBED_TARGET_SOURCES})
bogdanm 0:9b334a45a8ff 85 if("${src}" MATCHES .*startup_.*\\.[sS])
bogdanm 0:9b334a45a8ff 86 LIST(APPEND MBED_TARGET_STARTUP_CODE_SOURCES "${src}")
bogdanm 0:9b334a45a8ff 87 endif()
bogdanm 0:9b334a45a8ff 88 endforeach()
bogdanm 0:9b334a45a8ff 89 add_library(mbed_classic_startupcod OBJECT ${MBED_TARGET_STARTUP_CODE_SOURCES})
bogdanm 0:9b334a45a8ff 90 macro (add_executable _name)
bogdanm 0:9b334a45a8ff 91 _add_executable(${ARGV} $<TARGET_OBJECTS:mbed_classic_startupcod>)
bogdanm 0:9b334a45a8ff 92 endmacro()
bogdanm 0:9b334a45a8ff 93 endif()
bogdanm 0:9b334a45a8ff 94
bogdanm 0:9b334a45a8ff 95 # we have to append any target-specific include dirs to the global include dirs
bogdanm 0:9b334a45a8ff 96 # list, so that any indirect includes (e.g. via mbed.h) of files in those
bogdanm 0:9b334a45a8ff 97 # directories will work:
bogdanm 0:9b334a45a8ff 98 # (non-target-specific include dirs are listed in extraIncludes in module.json)
bogdanm 0:9b334a45a8ff 99 foreach(dir ${MBED_TARGET_INCLUDE_DIRS})
bogdanm 0:9b334a45a8ff 100 set_property(GLOBAL APPEND PROPERTY YOTTA_GLOBAL_INCLUDE_DIRS ${dir})
bogdanm 0:9b334a45a8ff 101 endforeach()
bogdanm 0:9b334a45a8ff 102
bogdanm 0:9b334a45a8ff 103 # finally, we can construct a library using the determined set of include paths
bogdanm 0:9b334a45a8ff 104 # + source files. Note that the library name must match the name of the yotta
bogdanm 0:9b334a45a8ff 105 # module (defined in module.json) for this module to link properly with other
bogdanm 0:9b334a45a8ff 106 # yotta modules.
bogdanm 0:9b334a45a8ff 107 include_directories(${MBED_COMMON_INCLUDE_DIRS})
bogdanm 0:9b334a45a8ff 108 include_directories(${MBED_TARGET_INCLUDE_DIRS})
bogdanm 0:9b334a45a8ff 109 add_library(mbed-classic
bogdanm 0:9b334a45a8ff 110 ${MBED_COMMON_SOURCES}
bogdanm 0:9b334a45a8ff 111 ${MBED_TARGET_SOURCES}
bogdanm 0:9b334a45a8ff 112 )