[CMake] How do I create a dependency to copy (touched) resource files when building an executable?

Petr Kmoch petr.kmoch at gmail.com
Mon Jun 30 10:22:41 EDT 2014


Simply change the custom target to depend on the binary-dir file; it will
become driver of the custom command, like this:

add_custom_target(fooresources ALL DEPENDS "${CMAKE_BINARY_DIR}/${CMAKE_
CFG_INT}/asset1.lua"
        COMMENT "fooresources custom target"
)

Petr

On Mon, Jun 30, 2014 at 4:12 PM, Eric Wing <ewmailing at gmail.com> wrote:

> Thanks for the reply. So the usage case is that people are going to be
> modifying the resources in the source directory. (These changes have
> to be checked into revision control.) So I'm having trouble seeing how
> depending on the binary directory is going to work. (The reason I must
> copy the resources to the binary directory is it is impossible to
> launch the application through the debugger or otherwise.)
>
> Thanks,
> Eric
>
>
> On 6/30/14, Petr Kmoch <petr.kmoch at gmail.com> wrote:
> > Hi Eric.
> >
> > It seems to me that you're copying from source dir to binary dir, but all
> > dependencies are on the source dir file only. Therefore, there is nothing
> > to trigger the generation of the binary-dir file. Perhaps you wanted
> > 'fooresources' to depend on the binary-dir file instead?
> >
> > Petr
> >
> >
> > On Mon, Jun 30, 2014 at 3:20 PM, Eric Wing <ewmailing at gmail.com> wrote:
> >
> >> I need to copy resource files from the source directory to the binary
> >> directory with the creation of my executable. I want CMake's
> >> dependency tracking to handle (re)copying these files whenever the
> >> source has been touched.
> >>
> >> Looking at other similar questions like:
> >>
> >>
> http://stackoverflow.com/questions/17018477/cmake-adding-custom-resources-to-build-directory
> >> and the CMake FAQ: How can I add a dependency to a source file which
> >> is generated in a subdirectory?
> >> http://www.cmake.org/Wiki/CMake_FAQ
> >>
> >> I expected the following (simplified) code to work, but it doesn't. I
> >> see the add_custom_target processed in the make chain, but the
> >> add_custom_command never triggers.
> >>
> >>
> >>
> >> project(foo)
> >>
> >> cmake_minimum_required(VERSION 2.8)
> >>
> >> add_executable(fooexe
> >>         ${CMAKE_SOURCE_DIR}/foo.c
> >>         ${CMAKE_SOURCE_DIR}/asset1.lua
> >> #       ${CMAKE_SOURCE_DIR}/subdir/subasset1.lua
> >> )
> >>
> >> add_custom_command(
> >>         OUTPUT "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INT}/asset1.lua"
> >>         COMMAND ${CMAKE_COMMAND} -E copy_if_different
> >> "${CMAKE_SOURCE_DIR}/asset1.lua"
> >> "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INT}/"
> >>         DEPENDS "${CMAKE_SOURCE_DIR}/asset1.lua"
> >>         COMMENT "Copying asset1.lua"
> >> )
> >>
> >> # files are only copied if a target depends on them
> >> add_custom_target(fooresources ALL DEPENDS
> >> "${CMAKE_SOURCE_DIR}/asset1.lua"
> >>         COMMENT "fooresources custom target"
> >>         )
> >> ADD_DEPENDENCIES(fooexe fooresources)
> >>
> >>
> >>
> >> Would somebody explain to me the correct way to handle this?
> >>
> >>
> >> Thanks,
> >> Eric
> >> --
> >>
> >> Powered by www.kitware.com
> >>
> >> Please keep messages on-topic and check the CMake FAQ at:
> >> http://www.cmake.org/Wiki/CMake_FAQ
> >>
> >> Kitware offers various services to support the CMake community. For more
> >> information on each offering, please visit:
> >>
> >> CMake Support: http://cmake.org/cmake/help/support.html
> >> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> >> CMake Training Courses: http://cmake.org/cmake/help/training.html
> >>
> >> Visit other Kitware open-source projects at
> >> http://www.kitware.com/opensource/opensource.html
> >>
> >> Follow this link to subscribe/unsubscribe:
> >> http://public.kitware.com/mailman/listinfo/cmake
> >>
> >
>
>
> --
> Beginning iPhone Games Development
> http://playcontrol.net/iphonegamebook/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140630/690c4774/attachment-0001.html>


More information about the CMake mailing list