2006-04-23 16:08:46 +04:00
|
|
|
# - This module defines variables and macros required to build eCos application.
|
|
|
|
# This file contains the following macros:
|
|
|
|
# ECOS_ADD_INCLUDE_DIRECTORIES() - add the eCos include dirs
|
2006-08-24 02:11:51 +04: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:
|
2006-04-23 16:08:46 +04:00
|
|
|
# ECOS_USE_ARM_ELF_TOOLS() - enable the ARM ELF toolchain for the directory where it is called
|
2006-08-24 02:11:51 +04:00
|
|
|
# ECOS_USE_I386_ELF_TOOLS() - enable the i386 ELF toolchain for the directory where it is called
|
2006-04-23 16:08:46 +04:00
|
|
|
# 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
|
2007-01-17 21:45:28 +03:00
|
|
|
# ECOS_CONFIG_FILE - defaults to ecos.ecc, if your eCos configuration file has a different name, adjust this variable
|
2006-04-23 16:08:46 +04:00
|
|
|
# for internal use only:
|
|
|
|
# ECOS_ADD_TARGET_LIB
|
|
|
|
|
2007-01-17 21:45:28 +03:00
|
|
|
# first check that ecosconfig is available
|
2006-04-23 16:08:46 +04: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.")
|
|
|
|
ELSE(NOT ECOSCONFIG_EXECUTABLE)
|
|
|
|
MESSAGE(STATUS "Found ecosconfig: ${ECOSCONFIG_EXECUTABLE}")
|
|
|
|
ENDIF(NOT ECOSCONFIG_EXECUTABLE)
|
|
|
|
|
2007-01-17 21:45:28 +03:00
|
|
|
# check that ECOS_REPOSITORY is set correctly
|
2006-04-23 16:08:46 +04: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")
|
|
|
|
ELSE (NOT EXISTS $ENV{ECOS_REPOSITORY}/ecos.db)
|
|
|
|
MESSAGE(STATUS "ECOS_REPOSITORY is set to $ENV{ECOS_REPOSITORY}")
|
|
|
|
ENDIF (NOT EXISTS $ENV{ECOS_REPOSITORY}/ecos.db)
|
|
|
|
|
2007-01-17 21:45:28 +03:00
|
|
|
# check that tclsh (coming with TCL) is available, otherwise ecosconfig doesn't work
|
|
|
|
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.")
|
|
|
|
ELSE (NOT TCL_TCLSH)
|
|
|
|
MESSAGE(STATUS "tlcsh found: ${TCL_TCLSH}")
|
|
|
|
ENDIF (NOT TCL_TCLSH)
|
2006-04-23 16:08:46 +04:00
|
|
|
|
|
|
|
#add the globale include-diretories
|
|
|
|
#usage: ECOS_ADD_INCLUDE_DIRECTORIES()
|
|
|
|
MACRO(ECOS_ADD_INCLUDE_DIRECTORIES)
|
|
|
|
#check for ProjectSources.txt one level higher
|
|
|
|
IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../ProjectSources.txt)
|
|
|
|
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
|
|
|
|
ELSE (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../ProjectSources.txt)
|
|
|
|
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/)
|
|
|
|
ENDIF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../ProjectSources.txt)
|
|
|
|
|
|
|
|
#the ecos include directory
|
2007-01-17 22:06:18 +03:00
|
|
|
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/ecos/install/include/)
|
2006-04-23 16:08:46 +04:00
|
|
|
|
|
|
|
ENDMACRO(ECOS_ADD_INCLUDE_DIRECTORIES)
|
|
|
|
|
|
|
|
|
|
|
|
#we want to compile for the xscale processor, in this case the following macro has to be called
|
|
|
|
#usage: ECOS_USE_ARM_ELF_TOOLS()
|
|
|
|
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")
|
|
|
|
#for linking
|
|
|
|
SET(ECOS_LD_MCPU "-mcpu=xscale")
|
|
|
|
#for compiling
|
|
|
|
ADD_DEFINITIONS(-mcpu=xscale -mapcs-frame)
|
|
|
|
#for the obj-tools
|
|
|
|
SET(ECOS_ARCH_PREFIX "arm-elf-")
|
|
|
|
ENDMACRO (ECOS_USE_ARM_ELF_TOOLS)
|
|
|
|
|
|
|
|
#usage: ECOS_USE_PPC_EABI_TOOLS()
|
|
|
|
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")
|
|
|
|
#for linking
|
|
|
|
SET(ECOS_LD_MCPU "")
|
|
|
|
#for compiling
|
|
|
|
ADD_DEFINITIONS()
|
|
|
|
#for the obj-tools
|
|
|
|
SET(ECOS_ARCH_PREFIX "powerpc-eabi-")
|
|
|
|
ENDMACRO (ECOS_USE_PPC_EABI_TOOLS)
|
|
|
|
|
2006-08-24 02:11:51 +04:00
|
|
|
#usage: ECOS_USE_I386_ELF_TOOLS()
|
|
|
|
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")
|
|
|
|
#for linking
|
|
|
|
SET(ECOS_LD_MCPU "")
|
|
|
|
#for compiling
|
|
|
|
ADD_DEFINITIONS()
|
|
|
|
#for the obj-tools
|
|
|
|
SET(ECOS_ARCH_PREFIX "i386-elf-")
|
|
|
|
ENDMACRO (ECOS_USE_I386_ELF_TOOLS)
|
|
|
|
|
2006-04-23 16:08:46 +04: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})
|
|
|
|
MACRO(ECOS_ADJUST_DIRECTORY _target_FILES )
|
|
|
|
FOREACH (_current_FILE ${ARGN})
|
2007-01-23 21:29:44 +03:00
|
|
|
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)
|
|
|
|
ENDIF (NOT ${_abs_FILE} STREQUAL ${_current_FILE})
|
|
|
|
LIST(APPEND ${_target_FILES} ${_abs_FILE})
|
2006-04-23 16:08:46 +04:00
|
|
|
ENDFOREACH (_current_FILE)
|
|
|
|
ENDMACRO(ECOS_ADJUST_DIRECTORY)
|
|
|
|
|
2007-01-17 21:45:28 +03:00
|
|
|
# the default ecos config file name
|
|
|
|
# maybe in the future also out-of-source builds may be possible
|
|
|
|
SET(ECOS_CONFIG_FILE ecos.ecc)
|
|
|
|
|
2006-04-23 16:08:46 +04:00
|
|
|
#creates the dependancy from all source files on the ecos target.ld,
|
2007-01-23 21:29:44 +03:00
|
|
|
#adds the command for compiling ecos
|
2006-04-23 16:08:46 +04:00
|
|
|
MACRO(ECOS_ADD_TARGET_LIB)
|
2007-01-17 21:57:34 +03:00
|
|
|
# when building out-of-source, create the ecos/ subdir
|
|
|
|
IF(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/ecos)
|
|
|
|
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ecos)
|
|
|
|
ENDIF(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/ecos)
|
|
|
|
|
2006-04-23 16:08:46 +04:00
|
|
|
#sources depend on target.ld
|
2007-01-23 21:29:44 +03:00
|
|
|
SET_SOURCE_FILES_PROPERTIES(
|
|
|
|
${ARGN}
|
2006-04-23 16:08:46 +04:00
|
|
|
PROPERTIES
|
2007-01-23 21:29:44 +03:00
|
|
|
OBJECT_DEPENDS
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld
|
|
|
|
)
|
2006-04-23 16:08:46 +04:00
|
|
|
|
2007-01-17 21:57:34 +03:00
|
|
|
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ecos/install/lib/target.ld
|
2007-01-23 21:29:44 +03: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 21:57:34 +03:00
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ecos/makefile
|
2006-04-23 16:08:46 +04:00
|
|
|
)
|
|
|
|
|
2007-01-17 21:57:34 +03:00
|
|
|
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ecos/makefile
|
2007-01-23 21:29:44 +03: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 21:45:28 +03:00
|
|
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ecos/${ECOS_CONFIG_FILE}
|
2006-04-23 16:08:46 +04:00
|
|
|
)
|
|
|
|
|
2007-01-17 21:57:34 +03:00
|
|
|
ADD_CUSTOM_TARGET( ecos make -C ${CMAKE_CURRENT_BINARY_DIR}/ecos/ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ecos/makefile )
|
2006-04-23 16:08:46 +04:00
|
|
|
ENDMACRO(ECOS_ADD_TARGET_LIB)
|
|
|
|
|
|
|
|
|
|
|
|
#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})
|
|
|
|
MACRO(ECOS_ADD_EXECUTABLE _exe_NAME )
|
|
|
|
#definitions, valid for all ecos projects
|
|
|
|
#the optimization and "-g" for debugging has to be enabled
|
|
|
|
#in the project-specific CMakeLists.txt
|
|
|
|
ADD_DEFINITIONS(-D__ECOS__=1 -D__ECOS=1)
|
|
|
|
SET(ECOS_DEFINITIONS -Wall -Wno-long-long -pipe -fno-builtin)
|
|
|
|
|
|
|
|
#the executable depends on ecos target.ld
|
|
|
|
ECOS_ADD_TARGET_LIB(${ARGN})
|
|
|
|
|
2007-01-23 21:29:44 +03:00
|
|
|
# when using nmake makefiles, the custom buildtype supresses the default cl.exe flags
|
|
|
|
# and the rules for creating objects are adjusted for gcc
|
|
|
|
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>")
|
|
|
|
# special link commands for ecos-executables
|
2007-01-17 21:57:34 +03: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}")
|
2007-01-23 21:29:44 +03:00
|
|
|
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 21:41:35 +03:00
|
|
|
# some strict compiler flags
|
2007-01-23 21:29:44 +03: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 16:08:46 +04:00
|
|
|
|
|
|
|
ADD_EXECUTABLE(${_exe_NAME} ${ARGN})
|
2006-08-23 02:33:49 +04:00
|
|
|
SET_TARGET_PROPERTIES(${_exe_NAME} PROPERTIES SUFFIX ".elf")
|
2006-04-23 16:08:46 +04:00
|
|
|
|
|
|
|
#create a binary file
|
|
|
|
ADD_CUSTOM_COMMAND(
|
|
|
|
TARGET ${_exe_NAME}
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${ECOS_ARCH_PREFIX}objcopy
|
2007-01-23 21:29:44 +03:00
|
|
|
ARGS -O binary ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.bin
|
2006-04-23 16:08:46 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
#and an srec file
|
|
|
|
ADD_CUSTOM_COMMAND(
|
|
|
|
TARGET ${_exe_NAME}
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${ECOS_ARCH_PREFIX}objcopy
|
2007-01-23 21:29:44 +03:00
|
|
|
ARGS -O srec ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.elf ${CMAKE_CURRENT_BINARY_DIR}/${_exe_NAME}.srec
|
2006-04-23 16:08:46 +04:00
|
|
|
)
|
|
|
|
|
2007-01-23 21:29:44 +03:00
|
|
|
#add the created files to the clean-files
|
2006-04-23 16:08:46 +04:00
|
|
|
SET_DIRECTORY_PROPERTIES(
|
|
|
|
PROPERTIES
|
2007-01-23 21:29:44 +03: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 16:08:46 +04:00
|
|
|
)
|
|
|
|
|
2007-01-17 21:45:28 +03:00
|
|
|
#cd $1; ls -a | grep --invert-match -e "\(.*CVS\)\|\(.*ecos\.ecc\)" | xargs rm -rf; touch ecos.ecc
|
2007-01-17 21:57:34 +03:00
|
|
|
ADD_CUSTOM_TARGET(ecosclean sh -c \"cd ${CMAKE_CURRENT_BINARY_DIR}/ecos\; ls | grep --invert-match -e \\\"\\\(.*CVS\\\)\\|\\\(.*ecos\\.ecc\\\)\\\" |xargs rm -rf\; touch ${ECOS_CONFIG_FILE} \")
|
|
|
|
ADD_CUSTOM_TARGET(normalclean ${CMAKE_MAKE_PROGRAM} clean -C ${CMAKE_CURRENT_BINARY_DIR})
|
2006-04-23 16:08:46 +04:00
|
|
|
ADD_DEPENDENCIES (ecosclean normalclean)
|
|
|
|
|
|
|
|
ADD_DEPENDENCIES(ecosclean clean)
|
|
|
|
|
|
|
|
|
|
|
|
ADD_CUSTOM_TARGET( listing
|
2007-01-23 21:29:44 +03: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 16:08:46 +04:00
|
|
|
|
|
|
|
ENDMACRO(ECOS_ADD_EXECUTABLE)
|
|
|
|
|