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