[CMake] Adding a generated source to all multiple targets

Tyler Roscoe tyler at cryptio.net
Wed Feb 24 19:50:50 EST 2010


On Wed, Feb 24, 2010 at 05:17:27PM -0600, Oliver kfsone Smith wrote:
> That's half the problem solved -- the bulk of the post was, though: I 
> want to automatically generate one of these per-target, so that the 
> tolua runs with per-target compiler switches, and so that the resulting 
> .cc file is compiled with the per-target compile flags plus any specific 
> flags needed to compile that source.

I would write a wrapper for add_library() and/or add_executable() that
does the normal add_*() stuff and then also sets up the custom command
for generating the lua.*.cc files.

> I.e. the origin file is "lua.pkg";
> For target "dbproxy" I want to run "tolua++ -n game 
> ${db_proxy_definitions} ${common_definitions} -o 
> ${Foo_BINARY_DIR}/lua.dbproxy.cc ${Foo_SOURCE_DIR}/lua.pkg"
> For target "statsd" I want to run "tolua++ -n game ${statsd_definitions} 
> ${common_definitions} -o ${Foo_BINARY_DIR}/lua.statsd.cc 
> ${Foo_SOURCE_DIR}/lua.pkg"

If these are real examples from your code, I would strongly suggest
normalizing your variable names. If the target is called dbproxy then
making all the config variables for that target match the form
dbproxy_WHATEVER lets you say stuff like:

add_library(${this_target} ${${this_target}_SOURCE_FILES} ...)

tyler


More information about the CMake mailing list