[CMake] Adding a generated source to all multiple targets

Oliver kfsone Smith osmith at playnet.com
Wed Feb 24 20:23:55 EST 2010


Tyler Roscoe said the following on 2/24/2010 6:50 PM:
> 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.
>    
Ok - I just wanted to make sure there wasn't some built-in way of doing 
it before I plowed ahead with that :)

>> 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
>    
Hehe, no, it's not :) And I didn't make it clear where I was just using 
${...} to denote "stuff from another place" :)

> 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} ...)
>    
Hmm - I didn't know you could do that, so I've been doing everything 
project relative, but then the size of this project and the number of 
sub-targets, and the huge amount of shared code between targets means 
that things aren't really organized by target, so all of the targets sit 
in one top-level project.


- Oliver



More information about the CMake mailing list