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