mbed library sources. Supersedes mbed-src.

Fork of mbed by teralytic

Committer:
rodriguise
Date:
Mon Oct 17 18:47:01 2016 +0000
Revision:
148:4802eb17e82b
Parent:
144:ef7eb2e8f9f7
backup

Who changed what in which revision?

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