[CMake] How do I create a dependency to copy (touched) resource files when building an executable?
Eric Wing
ewmailing at gmail.com
Mon Jun 30 09:20:14 EDT 2014
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
More information about the CMake
mailing list