[CMake] How to add file dependencies to a target?

Aaron_Wright at selinc.com Aaron_Wright at selinc.com
Thu Mar 4 14:50:14 EST 2010


I want to make an executable depend on output of a custom command. The 
custom command just copies a file to a place where the executable will be 
able to find it. I find that I can't get a dependency between an 
executable and, essentially, a file to work.

For example, this doesn't work:

ADD_EXECUTABLE(foo ${foo_SOURCES} ${foo_HEADERS})

ADD_CUSTOM_COMMAND(
   OUTPUT "${PROJECT_BINARY_DIR}/bar.ini"
   COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/bar.ini" 
"${PROJECT_BINARY_DIR}"
   DEPENDS "${PROJECT_SOURCE_DIR}/bar.ini"
   COMMENT "Localizing \"bar.ini\"")

ADD_DEPENDENCIES(foo "${PROJECT_BINARY_DIR}/bar.ini")

I know it'll work if I was generating a source file and feeding that into 
${foo_SOURCES}, but that didn't seem like the right thing to do.
I can also get it to work if I add another target like so:

ADD_EXECUTABLE(foo ${foo_SOURCES} ${foo_HEADERS})

ADD_CUSTOM_COMMAND(
   OUTPUT "${PROJECT_BINARY_DIR}/bar.ini"
   COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/bar.ini" 
"${PROJECT_BINARY_DIR}"
   DEPENDS "${PROJECT_SOURCE_DIR}/bar.ini"
   COMMENT "Localizing \"bar.ini\"")

ADD_CUSTOM_TARGET(copy_bar.ini DEPENDS "${PROJECT_BINARY_DIR}/bar.ini")

ADD_DEPENDENCIES(foo copy_bar.ini)

So do I have to have this additional indirection with the extra target? I 
have way too many targets as is. Is there anyway to get the first approach 
to work? It's like I need to add a file to ${foo_SOURCES} or 
${foo_HEADERS} that isn't compiled or that doesn't show up in the IDE. And 
can this be done after the ADD_EXECUTABLE call, or does it have to be 
before?
-------------------------------------------------------------
Aaron Wright
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100304/58629c44/attachment.htm>


More information about the CMake mailing list