[CMake] adding dependencies on generated files to source code files

Tony Bridges nabridges at gmail.com
Tue Mar 9 18:55:43 EST 2010


Hi JD,

Busy day, at a conference all day, and just got a chance to look into this.


Unfortunately, no, the "pretty much make sure" part actually doesn't.


With the add_dependency in place on the executable, to bind it to the
external target, still, the external target is not generated before the rc
is compiled.  The interproject dependency is correct in the output (i.e. I
see that bbs PROJ has a dependency on externalDependency PROJ) but the
project is not invoked at the right time.


so this:

add_executable( cm_bbsExe WIN32 ${SOURCES} )
target_link_libraries( cm_bbsExe winmm ... )

add_dependencies( cm_bbsExe externalDependency )

behaves like this:

myExe : bbs.rc

myExe : externalDependency


which leaves the relationship between the externalDependency and bbs.rc
undefined.  50/50, and it fails.  I suspect that VC plods along, resolving
it's dependencies, and it gets to the RC dependency before it gets to the
externalDependency.


Perhaps the problem is that when cmake scans the RC file, it doesn't
understand how to resolve the included file that does not exist; or does not
equate it to an external dependency ?  Even telling it that it's generated
does not help.


SET_SOURCE_FILES_PROPERTIES(${EnterpriseDir}/lib/rsrc/msg00001.bin
PROPERTIES GENERATED 1)


What I need is either to make cmake realize that externalDependency and
msg00001.bin are one and the same (so that it sees the dependency), or to
bind the inter-project dependency explicitly to the RC file that includes
the bin file.


Other than that, my only other option is to set up the resource compile as a
custom rule.


Is there any plan to allow file-level dependencies to be specified in cmake
?  And/or is there another option ?


Thanks again for all your help with this.




>I was just playing with this...

>

>cmake_minimum_required(VERSION 2.8)

>

>set( FAKE source.h )

>

>#this would be text->.h

>add_custom_command( OUTPUT source.h

>                     #DEPENDS ${SACK_BASE}/all_resources.rc

>                     COMMAND echo \#include \"stdio.h\" >source.h

> )

>

># this would be .h used by

>add_custom_command( OUTPUT main.c

>                     DEPENDS source.h

>                     COMMAND echo int main( void ) { return 1\; } >main.c

> )

>

>ADD_CUSTOM_TARGET( generate_foo DEPENDS main.c )

>

># have to touch filea.c fileb.c and filec.c yourself... for brevity...

>set( SOURCES main.c filea.c fileb.c filec.c )

>

>add_executable( main ${SOURCES} )

># this pretty much makes sure that the header is generated before

>other tings are compiled.

>add_dependencies( main generate_foo )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100309/48d805bd/attachment-0001.htm>


More information about the CMake mailing list