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