#
# CMake4Mbed
# https://github.com/grbd/GBD.Embedded.CMake4Mbed

# TODO Eventually this file will be auto generated by the Visual Studio project files
# via an app I've yet to write

# All Project specific values are below

# I think we need another project earler on for the linker script assembler -> object
# then link it into this project

# The name of the project
project (HelloWorld-LPC)

# A macro to collect local sources into ${SRCS}.
# This variable gets propagated to the parent scope and is ultimately used in
# the top-level CMakeLists.txt to define the dependencies for the build target.
#
# Files within this list are relative to the current folder.
# Please also note that this macro must be used at all CMakeLists.txt files at
# intermediate levels even if the list is empty--this is due to the Cmake magic
# involved in propagating variables to only the parent scope.
add_sources(
    src/main.cpp
	src/gcc4mbed.cpp
)

# TODO can we move some of the below into a function of some kind?

# Device independent cfags setup
# TODO extract from gcc4make / mbed
mbed_common_flags()

# Loop over all the mbed targets we need to build for
foreach(MBED_USER_TARGET ${MBED_USER_TARGETS})
	message(STATUS "Mbed Target: ${MBED_USER_TARGET}")

    # Set the cmake target name to <ProjectName>-<MBED_USER_TARGET>.elf file
	set(PROJECT_DEST "${PROJECT_NAME}-${MBED_USER_TARGET}.elf")

    # Add the exe / sources for the cmake target
	add_executable(${PROJECT_DEST} ${SRCS})
	
	# Set the output directory for the cmake target
	set_target_properties(${PROJECT_DEST} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${MBED_USER_TARGET}")

	message(STATUS "Elf Destination: ${PROJECT_DEST}")

	# Add the mbed build command pre build of the target
	mbed_buildcmd(${PROJECT_DEST} ${MBED_USER_TARGET})

	# TODO link project to mbed object
	# TODO Device specific CFlags for main project

	# Output .hex / .bin files from the .elf
	# TODO - see util script

endforeach()
