2013-10-15 15:17:36 +00:00
|
|
|
#.rst:
|
|
|
|
# UseEcos
|
|
|
|
# -------
|
|
|
|
#
|
|
|
|
# This module defines variables and macros required to build eCos application.
|
|
|
|
#
|
2006-04-23 12:08:46 +00:00
|
|
|
# This file contains the following macros:
|
|
|
|
# ECOS_ADD_INCLUDE_DIRECTORIES() - add the eCos include dirs
|
2013-10-15 15:17:36 +00:00
|
|
|
# ECOS_ADD_EXECUTABLE(name source1 ... sourceN ) - create an eCos
|
|
|
|
# executable ECOS_ADJUST_DIRECTORY(VAR source1 ... sourceN ) - adjusts
|
|
|
|
# the path of the source files and puts the result into VAR
|
|
|
|
#
|
|
|
|
# Macros for selecting the toolchain: ECOS_USE_ARM_ELF_TOOLS() - enable
|
|
|
|
# the ARM ELF toolchain for the directory where it is called
|
|
|
|
# ECOS_USE_I386_ELF_TOOLS() - enable the i386 ELF toolchain for the
|
|
|
|
# directory where it is called ECOS_USE_PPC_EABI_TOOLS() - enable the
|
|
|
|
# PowerPC toolchain for the directory where it is called
|
|
|
|
#
|
|
|
|
# It contains the following variables: ECOS_DEFINITIONS
|
|
|
|
# ECOSCONFIG_EXECUTABLE ECOS_CONFIG_FILE - defaults to ecos.ecc, if your
|
|
|
|
# eCos configuration file has a different name, adjust this variable for
|
|
|
|
# internal use only:
|
2006-08-23 22:11:51 +00:00
|
|
|
#
|
2013-10-15 15:17:36 +00:00
|
|
|
# ::
|
2006-04-23 12:08:46 +00:00
|
|
|
#
|
2013-10-15 15:17:36 +00:00
|
|
|
# ECOS_ADD_TARGET_LIB
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2009-09-28 15:46:51 +00:00
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2006-2009 Kitware, Inc.
|
|
|
|
#
|
|
|
|
# Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
# see accompanying file Copyright.txt for details.
|
|
|
|
#
|
|
|
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the License for more information.
|
|
|
|
#=============================================================================
|
2010-08-07 00:48:47 +00:00
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
2009-09-28 15:46:51 +00:00
|
|
|
# License text for the above reference.)
|
|
|
|
|
2007-01-17 18:45:28 +00:00
|
|
|
# first check that ecosconfig is available
|
2012-08-13 17:47:32 +00:00
|
|
|
find_program(ECOSCONFIG_EXECUTABLE NAMES ecosconfig)
|
|
|
|
if(NOT ECOSCONFIG_EXECUTABLE)
|
|
|
|
message(SEND_ERROR "ecosconfig was not found. Either include it in the system path or set it manually using ccmake.")
|
2012-08-13 17:50:14 +00:00
|
|
|
else()
|
2012-08-13 17:47:32 +00:00
|
|
|
message(STATUS "Found ecosconfig: ${ECOSCONFIG_EXECUTABLE}")
|
2012-08-13 17:50:14 +00:00
|
|
|
endif()
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2007-01-17 18:45:28 +00:00
|
|
|
# check that ECOS_REPOSITORY is set correctly
|
2012-08-13 17:47:32 +00:00
|
|
|
if (NOT EXISTS $ENV{ECOS_REPOSITORY}/ecos.db)
|
|
|
|
message(SEND_ERROR "The environment variable ECOS_REPOSITORY is not set correctly. Set it to the directory which contains the file ecos.db")
|
2012-08-13 17:50:14 +00:00
|
|
|
else ()
|
2012-08-13 17:47:32 +00:00
|
|
|
message(STATUS "ECOS_REPOSITORY is set to $ENV{ECOS_REPOSITORY}")
|
2012-08-13 17:50:14 +00:00
|
|
|
endif ()
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2007-01-17 18:45:28 +00:00
|
|
|
# check that tclsh (coming with TCL) is available, otherwise ecosconfig doesn't work
|
2012-08-13 17:47:32 +00:00
|
|
|
find_package(Tclsh)
|
|
|
|
if (NOT TCL_TCLSH)
|
|
|
|
message(SEND_ERROR "The TCL tclsh was not found. Please install TCL, it is required for building eCos applications.")
|
2012-08-13 17:50:14 +00:00
|
|
|
else ()
|
2012-08-13 17:47:32 +00:00
|
|
|
message(STATUS "tlcsh found: ${TCL_TCLSH}")
|
2012-08-13 17:50:14 +00:00
|
|
|
endif ()
|
2006-04-23 12:08:46 +00:00
|
|
|
|
|
|
|
#add the globale include-diretories
|
|
|
|
#usage: ECOS_ADD_INCLUDE_DIRECTORIES()
|
2012-08-13 17:47:32 +00:00
|
|
|
macro(ECOS_ADD_INCLUDE_DIRECTORIES)
|
2006-04-23 12:08:46 +00:00
|
|
|
#check for ProjectSources.txt one level higher
|
2012-08-13 17:47:32 +00:00
|
|
|
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../ProjectSources.txt)
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
|
2012-08-13 17:50:14 +00:00
|
|
|
else ()
|
2012-08-13 17:47:32 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
|
2012-08-13 17:50:14 +00:00
|
|
|
endif ()
|
2006-04-23 12:08:46 +00:00
|
|
|
|
|
|
|
#the ecos include directory
|
2012-08-13 17:47:32 +00:00
|
|
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/ecos/install/include/)
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2012-08-13 17:50:14 +00:00
|
|
|
endmacro()
|
2006-04-23 12:08:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
#we want to compile for the xscale processor, in this case the following macro has to be called
|
|
|
|
#usage: ECOS_USE_ARM_ELF_TOOLS()
|
2012-08-13 17:47:32 +00:00
|
|
|
macro (ECOS_USE_ARM_ELF_TOOLS)
|
|
|
|
set(CMAKE_CXX_COMPILER "arm-elf-c++")
|
|
|
|
set(CMAKE_COMPILER_IS_GNUCXX 1)
|
|
|
|
set(CMAKE_C_COMPILER "arm-elf-gcc")
|
|
|
|
set(CMAKE_AR "arm-elf-ar")
|
|
|
|
set(CMAKE_RANLIB "arm-elf-ranlib")
|
2006-04-23 12:08:46 +00:00
|
|
|
#for linking
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ECOS_LD_MCPU "-mcpu=xscale")
|
2006-04-23 12:08:46 +00:00
|
|
|
#for compiling
|
2012-08-13 17:47:32 +00:00
|
|
|
add_definitions(-mcpu=xscale -mapcs-frame)
|
2006-04-23 12:08:46 +00:00
|
|
|
#for the obj-tools
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ECOS_ARCH_PREFIX "arm-elf-")
|
2012-08-13 17:50:14 +00:00
|
|
|
endmacro ()
|
2006-04-23 12:08:46 +00:00
|
|
|
|
|
|
|
#usage: ECOS_USE_PPC_EABI_TOOLS()
|
2012-08-13 17:47:32 +00:00
|
|
|
macro (ECOS_USE_PPC_EABI_TOOLS)
|
|
|
|
set(CMAKE_CXX_COMPILER "powerpc-eabi-c++")
|
|
|
|
set(CMAKE_COMPILER_IS_GNUCXX 1)
|
|
|
|
set(CMAKE_C_COMPILER "powerpc-eabi-gcc")
|
|
|
|
set(CMAKE_AR "powerpc-eabi-ar")
|
|
|
|
set(CMAKE_RANLIB "powerpc-eabi-ranlib")
|
2006-04-23 12:08:46 +00:00
|
|
|
#for linking
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ECOS_LD_MCPU "")
|
2006-04-23 12:08:46 +00:00
|
|
|
#for compiling
|
2012-08-13 17:47:32 +00:00
|
|
|
add_definitions()
|
2006-04-23 12:08:46 +00:00
|
|
|
#for the obj-tools
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ECOS_ARCH_PREFIX "powerpc-eabi-")
|
2012-08-13 17:50:14 +00:00
|
|
|
endmacro ()
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2006-08-23 22:11:51 +00:00
|
|
|
#usage: ECOS_USE_I386_ELF_TOOLS()
|
2012-08-13 17:47:32 +00:00
|
|
|
macro (ECOS_USE_I386_ELF_TOOLS)
|
|
|
|
set(CMAKE_CXX_COMPILER "i386-elf-c++")
|
|
|
|
set(CMAKE_COMPILER_IS_GNUCXX 1)
|
|
|
|
set(CMAKE_C_COMPILER "i386-elf-gcc")
|
|
|
|
set(CMAKE_AR "i386-elf-ar")
|
|
|
|
set(CMAKE_RANLIB "i386-elf-ranlib")
|
2006-08-23 22:11:51 +00:00
|
|
|
#for linking
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ECOS_LD_MCPU "")
|
2006-08-23 22:11:51 +00:00
|
|
|
#for compiling
|
2012-08-13 17:47:32 +00:00
|
|
|
add_definitions()
|
2006-08-23 22:11:51 +00:00
|
|
|
#for the obj-tools
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ECOS_ARCH_PREFIX "i386-elf-")
|
2012-08-13 17:50:14 +00:00
|
|
|
endmacro ()
|
2006-08-23 22:11:51 +00:00
|
|
|
|
2006-04-23 12:08:46 +00:00
|
|
|
|
|
|
|
#since the actual sources are located one level upwards
|
|
|
|
#a "../" has to be prepended in front of every source file
|
|
|
|
#call the following macro to achieve this, the first parameter
|
|
|
|
#is the name of the new list of source files with adjusted paths,
|
|
|
|
#followed by all source files
|
|
|
|
#usage: ECOS_ADJUST_DIRECTORY(adjusted_SRCS ${my_srcs})
|
2012-08-13 17:47:32 +00:00
|
|
|
macro(ECOS_ADJUST_DIRECTORY _target_FILES )
|
|
|
|
foreach (_current_FILE ${ARGN})
|
|
|
|
get_filename_component(_abs_FILE ${_current_FILE} ABSOLUTE)
|
|
|
|
if (NOT ${_abs_FILE} STREQUAL ${_current_FILE})
|
|
|
|
get_filename_component(_abs_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../${_current_FILE} ABSOLUTE)
|
2012-08-13 17:50:14 +00:00
|
|
|
endif ()
|
2012-08-13 17:47:32 +00:00
|
|
|
list(APPEND ${_target_FILES} ${_abs_FILE})
|
2012-08-13 17:50:14 +00:00
|
|
|
endforeach ()
|
|
|
|
endmacro()
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2007-01-17 18:45:28 +00:00
|
|
|
# the default ecos config file name
|
2012-11-07 16:13:09 +00:00
|
|
|
# maybe in future also out-of-source builds may be possible
|
2012-08-13 17:47:32 +00:00
|
|
|
set(ECOS_CONFIG_FILE ecos.ecc)
|
2007-01-17 18:45:28 +00:00
|
|
|
|
2012-11-07 16:13:09 +00:00
|
|
|
#creates the dependency from all source files on the ecos target.ld,
|
2007-01-23 18:29:44 +00:00
|
|
|
#adds the command for compiling ecos
|
2012-08-13 17:47:32 +00:00
|
|
|
macro(ECOS_ADD_TARGET_LIB)
|
2007-01-17 18:57:34 +00:00
|
|
|
# when building out-of-source, create the ecos/ subdir
|
2012-08-13 17:47:32 +00:00
|
|
|
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/ecos)
|
|
|
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ecos)
|
2012-08-13 17:50:14 +00:00
|
|
|
endif()
|
2007-01-17 18:57:34 +00:00
|
|
|
|
2006-04-23 12:08:46 +00:00
|
|
|
#sources depend on target.ld
|
2012-08-13 17:47:32 +00:00
|
|
|
set_source_files_properties(
|
2007-01-23 18:29:44 +00:00
|
|
|
${ARGN}
|
2006-04-23 12:08:46 +00:00
|
|
|
PROPERTIES
|
2007-01-23 18:29:44 +00:00
|
|
|
OBJECT_DEPENDS
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld
|
|
|
|
)
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld
|
2007-01-23 18:29:44 +00:00
|
|
|
COMMAND sh -c \"make -C ${CMAKE_CURRENT_BINARY_DIR}/ecos || exit -1\; if [ -e ${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld ] \; then touch ${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld\; fi\"
|
2007-01-17 18:57:34 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ecos/makefile
|
2006-04-23 12:08:46 +00:00
|
|
|
)
|
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ecos/makefile
|
2007-01-23 18:29:44 +00:00
|
|
|
COMMAND sh -c \" cd ${CMAKE_CURRENT_BINARY_DIR}/ecos\; ${ECOSCONFIG_EXECUTABLE} --config=${CMAKE_CURRENT_SOURCE_DIR}/ecos/${ECOS_CONFIG_FILE} tree || exit -1\;\"
|
2007-01-17 18:45:28 +00:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ecos/${ECOS_CONFIG_FILE}
|
2006-04-23 12:08:46 +00:00
|
|
|
)
|
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
add_custom_target( ecos make -C ${CMAKE_CURRENT_BINARY_DIR}/ecos/ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ecos/makefile )
|
2012-08-13 17:50:14 +00:00
|
|
|
endmacro()
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2007-02-07 19:50:45 +00:00
|
|
|
# get the directory of the current file, used later on in the file
|
2012-08-13 17:47:32 +00:00
|
|
|
get_filename_component( ECOS_CMAKE_MODULE_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
|
2006-04-23 12:08:46 +00:00
|
|
|
|
|
|
|
#macro for creating an executable ecos application
|
|
|
|
#the first parameter is the name of the executable,
|
|
|
|
#the second is the list of all source files (where the path
|
|
|
|
#has been adjusted beforehand by calling ECOS_ADJUST_DIRECTORY()
|
|
|
|
#usage: ECOS_ADD_EXECUTABLE(my_app ${adjusted_SRCS})
|
2012-08-13 17:47:32 +00:00
|
|
|
macro(ECOS_ADD_EXECUTABLE _exe_NAME )
|
2006-04-23 12:08:46 +00:00
|
|
|
#definitions, valid for all ecos projects
|
|
|
|
#the optimization and "-g" for debugging has to be enabled
|
|
|
|
#in the project-specific CMakeLists.txt
|
2012-08-13 17:47:32 +00:00
|
|
|
add_definitions(-D__ECOS__=1 -D__ECOS=1)
|
|
|
|
set(ECOS_DEFINITIONS -Wall -Wno-long-long -pipe -fno-builtin)
|
2006-04-23 12:08:46 +00:00
|
|
|
|
|
|
|
#the executable depends on ecos target.ld
|
|
|
|
ECOS_ADD_TARGET_LIB(${ARGN})
|
|
|
|
|
2007-01-23 18:29:44 +00:00
|
|
|
# when using nmake makefiles, the custom buildtype supresses the default cl.exe flags
|
|
|
|
# and the rules for creating objects are adjusted for gcc
|
2012-08-13 17:47:32 +00:00
|
|
|
set(CMAKE_BUILD_TYPE CUSTOM_ECOS_BUILD)
|
|
|
|
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <FLAGS> -o <OBJECT> -c <SOURCE>")
|
|
|
|
set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <FLAGS> -o <OBJECT> -c <SOURCE>")
|
2007-01-23 18:29:44 +00:00
|
|
|
# special link commands for ecos-executables
|
2012-08-13 17:47:32 +00:00
|
|
|
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <OBJECTS> -o <TARGET> ${_ecos_EXTRA_LIBS} -nostdlib -nostartfiles -L${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib -Ttarget.ld ${ECOS_LD_MCPU}")
|
|
|
|
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> <OBJECTS> -o <TARGET> ${_ecos_EXTRA_LIBS} -nostdlib -nostartfiles -L${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib -Ttarget.ld ${ECOS_LD_MCPU}")
|
2007-01-23 18:41:35 +00:00
|
|
|
# some strict compiler flags
|
2012-08-13 17:47:32 +00:00
|
|
|
set (CMAKE_C_FLAGS "-Wstrict-prototypes")
|
|
|
|
set (CMAKE_CXX_FLAGS "-Woverloaded-virtual -fno-rtti -Wctor-dtor-privacy -fno-strict-aliasing -fno-exceptions")
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
add_executable(${_exe_NAME} ${ARGN})
|
|
|
|
set_target_properties(${_exe_NAME} PROPERTIES SUFFIX ".elf")
|
2006-04-23 12:08:46 +00:00
|
|
|
|
|
|
|
#create a binary file
|
2012-08-13 17:47:32 +00:00
|
|
|
add_custom_command(
|
2006-04-23 12:08:46 +00:00
|
|
|
TARGET ${_exe_NAME}
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${ECOS_ARCH_PREFIX}objcopy
|
2007-01-23 18:29:44 +00:00
|
|
|
ARGS -O binary ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.bin
|
2006-04-23 12:08:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
#and an srec file
|
2012-08-13 17:47:32 +00:00
|
|
|
add_custom_command(
|
2006-04-23 12:08:46 +00:00
|
|
|
TARGET ${_exe_NAME}
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${ECOS_ARCH_PREFIX}objcopy
|
2007-01-23 18:29:44 +00:00
|
|
|
ARGS -O srec ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.srec
|
2006-04-23 12:08:46 +00:00
|
|
|
)
|
|
|
|
|
2007-01-23 18:29:44 +00:00
|
|
|
#add the created files to the clean-files
|
2012-08-13 17:47:32 +00:00
|
|
|
set_directory_properties(
|
2006-04-23 12:08:46 +00:00
|
|
|
PROPERTIES
|
2007-01-23 18:29:44 +00:00
|
|
|
ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.bin;${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.srec;${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst;"
|
2006-04-23 12:08:46 +00:00
|
|
|
)
|
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
add_custom_target(ecosclean ${CMAKE_COMMAND} -DECOS_DIR=${CMAKE_CURRENT_BINARY_DIR}/ecos/ -P ${ECOS_CMAKE_MODULE_DIR}/ecos_clean.cmake )
|
|
|
|
add_custom_target(normalclean ${CMAKE_MAKE_PROGRAM} clean WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
add_dependencies (ecosclean normalclean)
|
2006-04-23 12:08:46 +00:00
|
|
|
|
|
|
|
|
2012-08-13 17:47:32 +00:00
|
|
|
add_custom_target( listing
|
2007-01-23 18:29:44 +00:00
|
|
|
COMMAND echo -e \"\\n--- Symbols sorted by address ---\\n\" > ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
|
|
|
|
COMMAND ${ECOS_ARCH_PREFIX}nm -S -C -n ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
|
|
|
|
COMMAND echo -e \"\\n--- Symbols sorted by size ---\\n\" >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
|
|
|
|
COMMAND ${ECOS_ARCH_PREFIX}nm -S -C -r --size-sort ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
|
|
|
|
COMMAND echo -e \"\\n--- Full assembly listing ---\\n\" >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst
|
|
|
|
COMMAND ${ECOS_ARCH_PREFIX}objdump -S -x -d -C ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf >> ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.lst )
|
2006-04-23 12:08:46 +00:00
|
|
|
|
2012-08-13 17:50:14 +00:00
|
|
|
endmacro()
|
2006-04-23 12:08:46 +00:00
|
|
|
|