PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Dependents:   Sensitive

Fork of PokittoLib by Jonne Valola

Committer:
Pokitto
Date:
Wed Oct 11 20:35:27 2017 +0000
Revision:
6:ea7377f3d1af
Fixed PokittoLib. Includes a working custom mbed-src

Who changed what in which revision?

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