1# This file implements basic support for sdcc (http://sdcc.sourceforge.net/)
2# a free C compiler for 8 and 16 bit microcontrollers.
3# To use it either a toolchain file is required or cmake has to be run like this:
4# cmake -DCMAKE_C_COMPILER=sdcc -DCMAKE_SYSTEM_NAME=Generic <dir...>
5# Since sdcc doesn't support C++, C++ support should be disabled in the
6# CMakeLists.txt using the project() command:
7# project(my_project C)
8
9set(CMAKE_STATIC_LIBRARY_PREFIX "")
10set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
11set(CMAKE_SHARED_LIBRARY_PREFIX "")          # lib
12set(CMAKE_SHARED_LIBRARY_SUFFIX ".lib")          # .so
13set(CMAKE_IMPORT_LIBRARY_PREFIX )
14set(CMAKE_IMPORT_LIBRARY_SUFFIX )
15set(CMAKE_EXECUTABLE_SUFFIX ".ihx")          # intel hex file
16set(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
17set(CMAKE_DL_LIBS "")
18
19set(CMAKE_C_OUTPUT_EXTENSION ".rel")
20
21# find sdar/sdcclib as CMAKE_AR
22# since cmake may already have searched for "ar", sdar has to
23# be searched with a different variable name (SDCCAR_EXECUTABLE)
24# and must then be forced into the cache.
25# sdcclib has been deprecated in SDCC 3.2.0 and removed in 3.8.6
26# so we first look for sdar
27get_filename_component(SDCC_LOCATION "${CMAKE_C_COMPILER}" PATH)
28find_program(SDCCAR_EXECUTABLE sdar NAMES sdcclib PATHS "${SDCC_LOCATION}" NO_DEFAULT_PATH)
29find_program(SDCCAR_EXECUTABLE sdar NAMES sdcclib)
30# for compatibility, in case SDCCLIB_EXECUTABLE is set, we use it
31if(DEFINED SDCCLIB_EXECUTABLE)
32  set(CMAKE_AR "${SDCCLIB_EXECUTABLE}" CACHE FILEPATH "The sdcc librarian" FORCE)
33else()
34  set(CMAKE_AR "${SDCCAR_EXECUTABLE}" CACHE FILEPATH "The sdcc librarian" FORCE)
35endif()
36
37if("${SDCCAR_EXECUTABLE}" MATCHES "sdcclib")
38  set(CMAKE_AR_OPTIONS "-a")
39else()
40  set(CMAKE_AR_OPTIONS "-rc")
41endif()
42
43set(CMAKE_C_LINKER_WRAPPER_FLAG "-Wl" ",")
44
45# compile a C file into an object file
46set(CMAKE_C_COMPILE_OBJECT  "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
47
48# link object files to an executable
49set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")
50
51# needs sdcc + sdar/sdcclib
52set(CMAKE_C_CREATE_STATIC_LIBRARY
53      "\"${CMAKE_COMMAND}\" -E remove <TARGET>"
54      "<CMAKE_AR> ${CMAKE_AR_OPTIONS} <TARGET> <LINK_FLAGS> <OBJECTS> ")
55
56# not supported by sdcc
57set(CMAKE_C_CREATE_SHARED_LIBRARY "")
58set(CMAKE_C_CREATE_MODULE_LIBRARY "")
59