[CMake] running command for each .o

Josef 'Jeff' Sipek jeffpc at josefsipek.net
Tue Jul 2 15:41:42 EDT 2013


Long story short, I'm trying to accomplish something like this using CMake.
Specifically, after each .o file gets generated, I want to process it using
another utility (ctfconvert).  Then, after the target has been linked I want
to run a different utility (ctfmerge) on the binary.  I realize that the
mange-the-target-binary I can be done via add_custom_command(... POST_BUILD
...), but...

  1) how do I run a custom command after a .o is generated?
  2) how do I get the list of .o file that are fed into the linking stage?

Any suggestions?

Thanks,

Jeff.


CC=gcc
CTFCONVERT=/opt/onbld/bin/i386/ctfconvert
CTFMERGE=/opt/onbld/bin/i386/ctfmerge
CFLAGS=-g -Wall -O2 -m64

all: testlist

clean:
	rm -f testlist testlist.o

%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<
	$(CTFCONVERT) -L VERSION $@

testlist: testlist.o
	$(CC) $(CFLAGS) -o $@ $<
	$(CTFMERGE) -L VERSION -o $@ $<

-- 
You measure democracy by the freedom it gives its dissidents, not the
freedom it gives its assimilated conformists.
		- Abbie Hoffman


More information about the CMake mailing list