
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")

set(LIBEZS_DIR "${PROJECT_SOURCE_DIR}/../libEZS")
set(EZS_DRIVERS_DIR "${PROJECT_SOURCE_DIR}/../drivers")

include_directories(
	${LIBEZS_DIR}/include
	${EZS_DRIVERS_DIR}/include
	)

set(LIBEZS_SOURCES
	${LIBEZS_DIR}/src/ezs_common.c
	${LIBEZS_DIR}/src/ezs_equalizer.c
	${LIBEZS_DIR}/src/ezs_fft.c ${LIBEZS_DIR}/src/ezs_window.c
	${LIBEZS_DIR}/src/ezs_interpolation.c ${LIBEZS_DIR}/src/ezs_gcd.c
	${LIBEZS_DIR}/src/ezs_plot.c ${LIBEZS_DIR}/src/ezs_plot_pds.c
	${LIBEZS_DIR}/src/ezs_stopwatch.c
	${LIBEZS_DIR}/src/ezs_wave.c
	${LIBEZS_DIR}/src/ezs_tracer.cpp
	)

set(HW_PLATFORM i386)

set(DRIVERS_SOURCES
	${EZS_DRIVERS_DIR}/${HW_PLATFORM}/ezs_counter.c
	${EZS_DRIVERS_DIR}/${HW_PLATFORM}/ezs_dma.c
	${EZS_DRIVERS_DIR}/${HW_PLATFORM}/ezs_fb.c
	${EZS_DRIVERS_DIR}/${HW_PLATFORM}/ezs_sb16.c
	)

# 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
SET(SRC_LIST
	app.c
	${LIBEZS_SOURCES}
	${DRIVERS_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)

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

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

add_custom_target( gdb
		DEPENDS sampleapp
		COMMAND ${PROJECT_BINARY_DIR}/qrun.sh ${fatimage} gdb
		COMMENT "Debugging in Qemu"
)
