[CMake] Trying to generate a source that depends on a library target's object files.

Luke Dalessandro luked at cs.rochester.edu
Thu Jul 7 08:43:24 EDT 2011


Hi Everyone,

I have the following build dependencies that I'm trying to implement in cmake.

The ultimate target of the build is an archive library, libme.a.

libme.a is composed of a number of static source files, (s1.cpp, ..., sn.cpp), and one generated source file, (g.cpp).

g.cpp is built using a perl script that examines the object files associated with S. For instance maybe it contains one string array with the names of all of the symbols in the objects obtained with nm or objdump.

So traditionally, we have a build cycle that looks like:

compile s1.cpp -> s1.o
...
compile sn.cpp -> sn.o
perl getSymbols.pl s1.o ... sn.o -> g.cpp
compile g.cpp -> g.o
archive s1.o ... sn.o  g.o ->libme.a

I'm trying to emulate this with CMake. The only platform we have support for the getSymbols.pl stuff is on Unix-based systems, in Windows we disable this particular configuration.

My current plan is to have a library target libme.a that has the (s1.cpp, ..., sn.cpp) as its sources, and a second library, libtemp.a, that has g.cpp as a source. g.cpp is the output of a custom_command that depends on (s1.cpp, ..., sn.cpp) and is built using getSymbols.pl (modified to account for the fact that its input is a .a rather than the set of .os). Then I will add a POST_BUILD custom_command for libtemp.a that extracts the object from libtemp.a and adds it to the libme.a archive.

This has the advantage that g.cpp is compiled with all of the same flags as the rest of the project---I'm not sure that there's a way to do this without the libtemp intermediate target. I don't know how to add a PRE_LINK command to libme.a that generates and compiles g.cpp in exactly the way that everything else is compiled, and I can't add g.cpp as a generated source for libme.a because I can't depend on the (s1.o, ..., sn.o) object files produced in its compilation.

I'm worried that the dependency on the custom g.cpp isn't quite right because I really depend on their object files. I could depend on libme.a, but that seems like it will introduce a circular dependency since I update libme.a in a POST_BUILD command for libtemp.a. I could also just say that target_link_libraries(me temp) but I don't really want to expose the two different libraries to users.

Does anyone know of a cleaner way to do this?

Luke


More information about the CMake mailing list