++

Fork of mbed-stm32l0/l1-src by lzbp li

Committer:
lzbpli
Date:
Thu Sep 22 02:11:40 2016 +0000
Revision:
638:e94dc43c7733
Parent:
581:39197bcd20f2
jianjianjian

Who changed what in which revision?

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