[CMake] Do an execute_process before compilation

Darius Blaszyk dhkblaszyk at zeelandnet.nl
Sat Aug 15 08:00:48 EDT 2009


On Sat, 2009-08-15 at 11:05 +0200, Michael Wild wrote:
> On 15. Aug, 2009, at 10:21, Darius Blaszyk wrote:
> 
> > My application links an object file in. This objectfile is not a c++ -
> > code file but some other file that needs to be linked in. The  
> > problem I
> > have now is that each time I change this file I need to run the linker
> > from a shell script manually and only then I can issue a make command.
> > Is there a way to automate that? In other words can cmake do an
> > execute_process before attempting to compile my application if I  
> > issue a
> > make?
> >
> > Regards, Darius
> >
> 
> Have a look at ADD_CUSTOM_COMMAND(TARGET PRE_LINK ...)
> 
> Michael

I did a test, but the make process complained "Cannot find source file
myobj.o". Which seems to be logical because the .o file needs to be
created first by ADD_CUSTOM_COMMAND.
What I have now is: 

ADD_CUSTOM_COMMAND(TARGET mytest_gui PRE_LINK COMMAND ld -r -b binary -o
mytest_glade.o mytest.glade)
ADD_CUSTOM_COMMAND(TARGET mytest_gui PRE_LINK COMMAND objcopy
--rename-section .data=.rodata,alloc,load,readonly,data,contents
mytest_glade.o mytest_glade.o)
ADD_EXECUTABLE(mytest_gui main.cpp mytest_glade.o)
TARGET_LINK_LIBRARIES(mytest_gui ${GTKMM_LIBRARIES})

This obviously does not work because of a missing mytest_glade.o, but
how to circumvent that?

Darius



More information about the CMake mailing list