2007-06-26 21:19:46 +04:00
|
|
|
|
|
|
|
# This file implements basic support for sdcc (http://sdcc.sourceforge.net/)
|
|
|
|
# a free C compiler for 8 and 16 bit microcontrollers.
|
|
|
|
# To use it either a toolchain file is required or cmake has to be run like this:
|
|
|
|
# cmake -DCMAKE_C_COMPILER=sdcc -DCMAKE_SYSTEM_NAME=Generic <dir...>
|
|
|
|
# Since sdcc doesn't support C++, C++ support should be disabled in the
|
2012-08-13 21:47:32 +04:00
|
|
|
# CMakeLists.txt using the project() command:
|
|
|
|
# project(my_project C)
|
2007-06-26 21:19:46 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_STATIC_LIBRARY_PREFIX "")
|
|
|
|
set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
|
|
|
|
set(CMAKE_SHARED_LIBRARY_PREFIX "") # lib
|
|
|
|
set(CMAKE_SHARED_LIBRARY_SUFFIX ".lib") # .so
|
|
|
|
set(CMAKE_IMPORT_LIBRARY_PREFIX )
|
|
|
|
set(CMAKE_IMPORT_LIBRARY_SUFFIX )
|
|
|
|
set(CMAKE_EXECUTABLE_SUFFIX ".ihx") # intel hex file
|
|
|
|
set(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
|
|
|
|
set(CMAKE_DL_LIBS "")
|
2007-06-26 21:19:46 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_C_OUTPUT_EXTENSION ".rel")
|
2007-06-26 21:19:46 +04:00
|
|
|
|
|
|
|
# find sdcclib as CMAKE_AR
|
2012-08-13 21:42:58 +04:00
|
|
|
# since cmake may already have searched for "ar", sdcclib has to
|
|
|
|
# be searched with a different variable name (SDCCLIB_EXECUTABLE)
|
2007-06-26 21:19:46 +04:00
|
|
|
# and must then be forced into the cache
|
2012-08-13 21:47:32 +04:00
|
|
|
get_filename_component(SDCC_LOCATION "${CMAKE_C_COMPILER}" PATH)
|
|
|
|
find_program(SDCCLIB_EXECUTABLE sdcclib PATHS "${SDCC_LOCATION}" NO_DEFAULT_PATH)
|
|
|
|
find_program(SDCCLIB_EXECUTABLE sdcclib)
|
|
|
|
set(CMAKE_AR "${SDCCLIB_EXECUTABLE}" CACHE FILEPATH "The sdcc librarian" FORCE)
|
2007-06-26 21:19:46 +04:00
|
|
|
|
2007-08-15 22:22:54 +04:00
|
|
|
# CMAKE_C_FLAGS_INIT and CMAKE_EXE_LINKER_FLAGS_INIT should be set in a CMAKE_SYSTEM_PROCESSOR file
|
2012-08-13 21:47:32 +04:00
|
|
|
if(NOT DEFINED CMAKE_C_FLAGS_INIT)
|
|
|
|
set(CMAKE_C_FLAGS_INIT "-mmcs51 --model-small")
|
|
|
|
endif(NOT DEFINED CMAKE_C_FLAGS_INIT)
|
2007-08-15 22:22:54 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
|
|
|
|
set (CMAKE_EXE_LINKER_FLAGS_INIT --model-small)
|
|
|
|
endif(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
|
2007-08-15 22:22:54 +04:00
|
|
|
|
2007-06-26 21:19:46 +04:00
|
|
|
# compile a C file into an object file
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
|
2007-06-26 21:19:46 +04:00
|
|
|
|
|
|
|
# link object files to an executable
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> --out-fmt-ihx -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")
|
2007-06-26 21:19:46 +04:00
|
|
|
|
|
|
|
# needs sdcc 2.7.0 + sddclib from cvs
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_C_CREATE_STATIC_LIBRARY
|
2007-06-26 23:15:52 +04:00
|
|
|
"\"${CMAKE_COMMAND}\" -E remove <TARGET>"
|
2007-06-26 21:19:46 +04:00
|
|
|
"<CMAKE_AR> -a <TARGET> <LINK_FLAGS> <OBJECTS> ")
|
|
|
|
|
|
|
|
# not supported by sdcc
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_C_CREATE_SHARED_LIBRARY "")
|
|
|
|
set(CMAKE_C_CREATE_MODULE_LIBRARY "")
|
2007-06-26 21:19:46 +04:00
|
|
|
|