[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 09:38:14 EDT 2014


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140630/6587f9a5/attachment.html>


More information about the CMake mailing list