[CMake] Linking object files into executable target
Colin D Bennett
colin at gibibit.com
Wed Dec 10 01:26:11 EST 2008
I'm using CMake and SDCC to build a project for the 8051
microcontroller. CMake has been working great for this so far, but now
I need to link in an object file that I've assembled with SDCC's
"asx8051" assembler, and I am not able to get CMake to explicitly add
an object file to the list of objects to be linked into a target.
The problem is that CMake is *silently* ignoring the request to link the
object file into the executable target with ADD_EXECUTABLE().
First, I am using ADD_CUSTOM_COMMAND to assemble the assembly code into
an object file (".rel" extension, as are the object files produced by
SDCC for compiled C code). The custom command is resulting in the
object file being produced properly.
Next, my ADD_EXECUTABLE() call simply names the object file in addition
to the C source files that I already am specifying. However, while the
C source files are compiled and linked with into the target executable,
the '.rel' object file is not being added into the list of objects to
link into the executable.
I think that the GENERATED=TRUE and EXTERNAL_OBJECT=TRUE source
properties on the generated object file should cause CMake to link it.
Is there something I'm doing wrong?
Here's my CMakeLists.txt:
-----------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(timertest C)
SET(CMAKE_ASM_OUTPUT_EXTENSION ${CMAKE_C_OUTPUT_EXTENSION})
SET(MY_SRCS main.c)
SET(MY_ASM_SRCS sleep_timer_get.asm)
FOREACH(ASMFILE ${MY_ASM_SRCS})
GET_FILENAME_COMPONENT(BASENAME ${ASMFILE} NAME_WE)
SET(SRC ${CMAKE_CURRENT_SOURCE_DIR}/${ASMFILE})
SET(OBJ
${CMAKE_CURRENT_BINARY_DIR}/${BASENAME}${CMAKE_ASM_OUTPUT_EXTENSION})
SET_SOURCE_FILES_PROPERTIES(${OBJ} PROPERTIES
GENERATED TRUE
EXTERNAL_OBJECT TRUE)
ADD_CUSTOM_COMMAND(OUTPUT ${OBJ}
MAIN_DEPENDENCY ${SRC}
COMMAND asx8051-wrapper
ARGS -I${CMAKE_CURRENT_SOURCE_DIR}
-o ${OBJ} ${SRC})
LIST(APPEND MY_ASM_OBJS ${OBJ})
ENDFOREACH(ASMFILE ${MY_ASM_SRCS})
MESSAGE(STATUS "MY_ASM_OBJS is ${MY_ASM_OBJS}")
ADD_EXECUTABLE(timertest main.c ${MY_ASM_OBJS})
-----------------------------------------------------------------
I have attached the output I get when I build using this file.
I have spent all day and most of the night trying to get this to work,
and I've already started working on a Makefile to replace CMake for
this, though I really would hate to give up CMake; however, this silent
failure by CMake is creating an impossible-to-track-down problem.
Thanks for any help.
Regards,
Colin
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: log1.txt
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081209/e2818c46/attachment-0001.txt>
More information about the CMake
mailing list