[CMake] Adding a generated source to all multiple targets

Oliver Smith osmith at playnet.com
Tue Feb 23 23:02:44 EST 2010


I have a CMake project with a number of targets, and a Lua wrapper 
generated through tolua++ which is included by several of them, so that 
it is compiled with the target-specific make flags per-target.

Global make flags: -O0 -ggdb3 -Wall -Werror ... etc
Target1 make flags: -DAS_DB_PROXY ...
Target2 make flags: -DAS_GAME_SERVER ...
Target3 make flags: -DAS_CLIENT
<etc - there are 10 targets in total>
LuaTarget make flags: -Wno-unused

The LuaTarget is "luapkg.cc" generated from "lua.pkg" via "tolua++ -n 
game -o luapkg.cc luapkg.pkg"

If I add "luapkg.cc" to the list of sources for any given target, CMake 
barfs because luapkg.cc doesn't exist.

I've tried variations of add_custom_target and add_custom_command to no 
avail.

Is there a way to do this with CMake 2.6 or 2.8?

And it occurs to me that if I can find a solution to this, I can 
probably use the same solution for adding a precompiled header to each 
target (for my limited subset of platforms).

- Oliver



More information about the CMake mailing list