SDCC: ASM support
CMAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION
wrongly defaults to .obj
.
I'm using cmake with SDCC for 8051 and I need to include a pure .asm file to the build. SDCC doesn't have a single 'sdas' assembler program, but different ones for each target architecture. I'm using a toolchain file where I set the following:
set (CMAKE_C_COMPILER sdcc CACHE FILEPATH "target_c" FORCE)
set (CMAKE_CXX_COMPILER sdcc-c++-unsupported CACHE FILEPATH "target_cxx" FORCE)
set (CMAKE_OBJCOPY sdobjcopy CACHE FILEPATH "target_ojbcopy" FORCE)
set (CMAKE_AR sdar CACHE FILEPATH "target_ar" FORCE)
set (CMAKE_NM sdnm CACHE FILEPATH "target_nm" FORCE)
set (CMAKE_RANLIB sdranlib CACHE FILEPATH "target_ranlib" FORCE)
set (CMAKE_ASM_COMPILER sdas8051 CACHE FILEPATH "target_asm" FORCE)
# by default cmake always adds a "-c" before the source files. this works
# when compiling asm files with e.g. gcc. for sdas8051 we don't want that.
set (CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -l -o <OBJECT> <SOURCE>")
set (CMAKE_ASM_COMPILER_ID "sdas8051")
set (CMAKE_ASM_COMPILER_VERSION "")
set (CMAKE_ASM_COMPILER_FORCED TRUE)
This allows including asm files into the project and builds it correctly. However, because of this code in CMakeASMInformation.cmake
if(UNIX)
set(CMAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION .o)
else()
set(CMAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION .obj)
endif()
the output extension is set to .obj, which is wrong for SDCC & friends. The assembler will write the file as .obj but the following ar / linker tools will refuse to use the "unknown extension" files.
For now, my work around is to simply replicate the contents of CMakeASMInformation.cmake in my toolchain file and do a
set (CMAKE_ASM_INFORMATION_LOADED 1)
I think it'd be better if it was possible to just add that one line to the toolchain file and be done with it
set (CMAKE_ASM_OUTPUT_EXTENSION ".rel")
My suggestion is to add a guard check to CMakeASMInformation.cmake, as it's done also for some of the other variables
if(NOT MAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION)
if(UNIX)
set(CMAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION .o)
else()
set(CMAKE_ASM${ASM_DIALECT}_OUTPUT_EXTENSION .obj)
endif()
endif()
I've tried it out on my installed cmake and it seems to do the right thing.
Somebody else had the same problem some time ago, but it seems there was no follow up
https://cmake.cmake.narkive.com/mTeLbSM6/how-to-change-cmake-s-expected-output-filename