On Thu, Mar 04, 2010 at 11:50:14AM -0800, aaron_wri...@selinc.com wrote:
> 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")

add_dependencies() is for adding dependencies on targets, not on files.

> 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)

AFIAK this is the "right" way to do what you want.

> 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?

You could try a PRE_BUILD custom_command instead. I think that will run
every time instead of just when bar.ini has changed.

If you are going to tweak foo_SOURCES, you will need to do it before you
call add_executable().

tyler
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to