CMake/Modules/Platform/Generic-SDCC-C.cmake
Brad King a66004bee0 Honor CMAKE_<LANG>_FLAGS[_<CONFIG>]_INIT set in toolchain files
Document these variables.

Change our convention for setting these variables from:

    set(CMAKE_C_FLAGS_INIT "...")

to

    string(APPEND CMAKE_C_FLAGS_INIT " ...")

so that any value previously set by a toolchain file will be used.

Automate the conversion with:

    sed -i 's/set *(\(CMAKE_\(C\|CXX\|Fortran\|RC\|ASM\|${[^}]\+}\)_FLAGS\(_[^_]\+\)\?_INIT \+"\)/string(APPEND \1 /' \
      Modules/Compiler/*.cmake Modules/Platform/*.cmake

and follow up with some manual fixes (e.g. to cases that already
meant to append).  Also revert the automated changes to contexts
that are not protected from running multiple times.
2016-07-06 10:13:31 -04:00

55 lines
2.2 KiB
CMake

# 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
# CMakeLists.txt using the project() command:
# project(my_project C)
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 "")
set(CMAKE_C_OUTPUT_EXTENSION ".rel")
# find sdcclib as CMAKE_AR
# since cmake may already have searched for "ar", sdcclib has to
# be searched with a different variable name (SDCCLIB_EXECUTABLE)
# and must then be forced into the cache
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)
# CMAKE_C_FLAGS_INIT and CMAKE_EXE_LINKER_FLAGS_INIT should be set in a CMAKE_SYSTEM_PROCESSOR file
if(NOT DEFINED CMAKE_C_FLAGS_INIT)
string(APPEND CMAKE_C_FLAGS_INIT " -mmcs51 --model-small")
endif()
if(NOT DEFINED CMAKE_EXE_LINKER_FLAGS_INIT)
set (CMAKE_EXE_LINKER_FLAGS_INIT --model-small)
endif()
# compile a C file into an object file
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
# link object files to an executable
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> --out-fmt-ihx -o <TARGET> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <LINK_LIBRARIES>")
# needs sdcc 2.7.0 + sddclib from cvs
set(CMAKE_C_CREATE_STATIC_LIBRARY
"\"${CMAKE_COMMAND}\" -E remove <TARGET>"
"<CMAKE_AR> -a <TARGET> <LINK_FLAGS> <OBJECTS> ")
# not supported by sdcc
set(CMAKE_C_CREATE_SHARED_LIBRARY "")
set(CMAKE_C_CREATE_MODULE_LIBRARY "")