2 # This file implements basic support for sdcc (http://sdcc.sourceforge.net/)
3 # a free C compiler for 8 and 16 bit microcontrollers.
4 # To use it either a toolchain file is required or cmake has to be run like this:
5 # cmake -DCMAKE_C_COMPILER=sdcc -DCMAKE_SYSTEM_NAME=Generic <dir...>
6 # Since sdcc doesn't support C++, C++ support should be disabled in the
7 # CMakeLists.txt using the PROJECT() command:
8 # PROJECT(my_project C)
10 SET(CMAKE_STATIC_LIBRARY_PREFIX "")
11 SET(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
12 SET(CMAKE_SHARED_LIBRARY_PREFIX "") # lib
13 SET(CMAKE_SHARED_LIBRARY_SUFFIX ".lib") # .so
14 SET(CMAKE_IMPORT_LIBRARY_PREFIX )
15 SET(CMAKE_IMPORT_LIBRARY_SUFFIX )
16 SET(CMAKE_EXECUTABLE_SUFFIX ".ihx") # intel hex file
17 SET(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
20 SET(CMAKE_C_OUTPUT_EXTENSION ".rel")
22 # find sdcclib as CMAKE_AR
23 # since cmake may already have searched for "ar", sdcclib has to
24 # be searched with a different variable name (SDCCLIB_EXECUTABLE)
25 # and must then be forced into the cache
26 GET_FILENAME_COMPONENT(SDCC_LOCATION "${CMAKE_C_COMPILER}" PATH)
27 FIND_PROGRAM(SDCCLIB_EXECUTABLE sdcclib PATHS "${SDCC_LOCATION}" NO_DEFAULT_PATH)
28 FIND_PROGRAM(SDCCLIB_EXECUTABLE sdcclib)
29 SET(CMAKE_AR "${SDCCLIB_EXECUTABLE}" CACHE FILEPATH "The sdcc librarian" FORCE)
31 # CMAKE_C_FLAGS_INIT and CMAKE_EXE_LINKER_FLAGS_INIT should be set in a CMAKE_SYSTEM_PROCESSOR file
32 IF(NOT DEFINED CMAKE_C_FLAGS_INIT)
33 SET(CMAKE_C_FLAGS_INIT "-mmcs51 --model-small")
34 ENDIF(NOT DEFINED CMAKE_C_FLAGS_INIT)
36 IF(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
37 SET (CMAKE_EXE_LINKER_FLAGS_INIT --model-small)
38 ENDIF(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
40 # compile a C file into an object file
41 SET(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
43 # link object files to an executable
44 SET(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> --out-fmt-ihx -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")
46 # needs sdcc 2.7.0 + sddclib from cvs
47 SET(CMAKE_C_CREATE_STATIC_LIBRARY
48 "\"${CMAKE_COMMAND}\" -E remove <TARGET>"
49 "<CMAKE_AR> -a <TARGET> <LINK_FLAGS> <OBJECTS> ")
51 # not supported by sdcc
52 SET(CMAKE_C_CREATE_SHARED_LIBRARY "")
53 SET(CMAKE_C_CREATE_MODULE_LIBRARY "")