This fork captures the mbed lib v125 for ease of integration into older projects.

Fork of mbed-dev by mbed official

Committer:
apluscw
Date:
Fri Jul 20 21:24:42 2018 +0000
Revision:
187:92cbb9eec47b
Mbed library with source code from mbed lib v125. Posted to ease integration with some older projects.

Who changed what in which revision?

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