Search code examples
ccmakearmkeil

cmake convert to object file


I have a Keil project for an ARM target that I converted to a Makefile for a command line build system. I was also thinking of using cmake but I cannot find the right command/cmakey way to do the task. My Makefile converts a whole bunch of source files from different directories and creates object files out of them. Then the linker takes all these object files to make an executable taking in a bunch of flags and memory map files. So I can't just use the add_executable command. What can be the best way to do this in cmake?

EDIT:

So here is what the Makefile is trying to do(basically replicating the way Keil is building the project)

OBJECT_FILES=out/abc.o out/def.o out/xyz.o

all: binary.hex

binary.hex: binary.axf
           $(ELFTOHEX) $(FLAGS) binary.hex

out/binary.axf: $(OBJECT_FILES)
               ARMLINK $(MANY_FLAGS) $^ -o $@

out/abc.o: ../../../src/modules/abc.c
       ARMCC -o $@ $(FLAGS) $^ 
out/def.o: ../../../src/utilities/def.c
       ARMCC -o $@ $(FLAGS) $^ 
out/xyz.o: src/xyz.c
       ARMCC -o $@ $(FLAGS) $^ 

Solution

  • You can use add_library with OBJECT signature:

    add_library(yourlib OBJECT sources)
    

    and then link them into executable, for instance:

    add_executable(yourexe $<TARGET_OBJECTS:yourlib>)