Project(HelloWorld)

cmake_minimum_required(VERSION 2.8)

# use the eCos support coming with CMake
# without this line CMake doesn't know how to build eCos applications
# all functions/macros coming from this file start with "ECOS_"

INCLUDE(UseEcos)

set (SCRIPT_DIR "$ENV{ECOS_REPOSITORY}/../tools/scripts")
set(CMAKE_MODULE_PATH ${SCRIPT_DIR}/..)
INCLUDE(doxygendocu)

# add the ecos/install/include/ directory to the header search path
ECOS_ADD_INCLUDE_DIRECTORIES()
ECOS_USE_I386_ELF_TOOLS()

set(COMMON_FLAGS "-nostartfiles -nostdlib -ffunction-sections -fdata-sections -fno-builtin -Wall -Wpointer-arith  -Wundef -fdata-sections")
set(CMAKE_C_FLAGS "${COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -fno-rtti -fno-exceptions -fno-unwind-tables -Woverloaded-virtual" )

# use ADD_DEFINITIONS() to add the definitions (or switches) you like
add_definitions("-g")

# this is one of the most important lines
# here you list all source files of your application
# you can mix C and C++ files as you like
# you can also add the header files here, but you don't have to
# you can use relative or absolute paths as you like
include_directories(${PROJECT_SOURCE_DIR}/libEZS/include)
set(LIBEZS_SOURCES
	libEZS/src/ezs_sb16.c
	libEZS/src/ezs_common.c
	libEZS/src/ezs_dma.c
	libEZS/src/ezs_fb.c
	)
SET(SRC_LIST
	hello.c
	${LIBEZS_SOURCES}
	)

# this is the most important line:
# tell CMake that we want to create an executable named "sampleapp"
# from the files listed in the variable SRC_LIST
ECOS_ADD_EXECUTABLE(sampleapp ${SRC_LIST})



set(fatimage ${PROJECT_SOURCE_DIR}/image)
set(EXE_ELF "sampleapp.elf")
configure_file(${SCRIPT_DIR}/qrun.sh.in ${PROJECT_BINARY_DIR}/qrun.sh)
configure_file(${SCRIPT_DIR}/findport.pl ${PROJECT_BINARY_DIR}/findport.pl)
# Generate bootable iso image, starting grub, booting sampleapp.elf
add_custom_command(
		OUTPUT grub-ecos.iso
		COMMAND ${SCRIPT_DIR}/build_iso.sh $<TARGET_FILE:sampleapp> ${SCRIPT_DIR}/stage2_eltorito
		DEPENDS sampleapp
)

# Run qemu with the iso image.
add_custom_target( run
		DEPENDS grub-ecos.iso
		COMMAND ${PROJECT_BINARY_DIR}/qrun.sh ${fatimage}
		COMMENT "Starting Qemu"
)


# Start Qemu in Debug mode.
add_custom_target( debug
		DEPENDS grub-ecos.iso
		COMMAND ${PROJECT_BINARY_DIR}/qrun.sh ${fatimage} ddd
		COMMENT "Debugging in Qemu"
)
