Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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