Generic-SDCC-C.cmake 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. set(CMAKE_STATIC_LIBRARY_PREFIX "")
  9. set(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
  10. set(CMAKE_SHARED_LIBRARY_PREFIX "") # lib
  11. set(CMAKE_SHARED_LIBRARY_SUFFIX ".lib") # .so
  12. set(CMAKE_IMPORT_LIBRARY_PREFIX )
  13. set(CMAKE_IMPORT_LIBRARY_SUFFIX )
  14. set(CMAKE_EXECUTABLE_SUFFIX ".ihx") # intel hex file
  15. set(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
  16. set(CMAKE_DL_LIBS "")
  17. set(CMAKE_C_OUTPUT_EXTENSION ".rel")
  18. # find sdcclib as CMAKE_AR
  19. # since cmake may already have searched for "ar", sdcclib has to
  20. # be searched with a different variable name (SDCCLIB_EXECUTABLE)
  21. # and must then be forced into the cache
  22. get_filename_component(SDCC_LOCATION "${CMAKE_C_COMPILER}" PATH)
  23. find_program(SDCCLIB_EXECUTABLE sdcclib PATHS "${SDCC_LOCATION}" NO_DEFAULT_PATH)
  24. find_program(SDCCLIB_EXECUTABLE sdcclib)
  25. set(CMAKE_AR "${SDCCLIB_EXECUTABLE}" CACHE FILEPATH "The sdcc librarian" FORCE)
  26. # CMAKE_C_FLAGS_INIT and CMAKE_EXE_LINKER_FLAGS_INIT should be set in a CMAKE_SYSTEM_PROCESSOR file
  27. if(NOT DEFINED CMAKE_C_FLAGS_INIT)
  28. string(APPEND CMAKE_C_FLAGS_INIT " -mmcs51 --model-small")
  29. endif()
  30. if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
  31. set (CMAKE_EXE_LINKER_FLAGS_INIT --model-small)
  32. endif()
  33. set(CMAKE_C_LINKER_WRAPPER_FLAG "-Wl" ",")
  34. # compile a C file into an object file
  35. set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
  36. # link object files to an executable
  37. set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")
  38. # needs sdcc 2.7.0 + sddclib from cvs
  39. set(CMAKE_C_CREATE_STATIC_LIBRARY
  40. "\"${CMAKE_COMMAND}\" -E remove <TARGET>"
  41. "<CMAKE_AR> -a <TARGET> <LINK_FLAGS> <OBJECTS> ")
  42. # not supported by sdcc
  43. set(CMAKE_C_CREATE_SHARED_LIBRARY "")
  44. set(CMAKE_C_CREATE_MODULE_LIBRARY "")