<div dir="ltr">The reasoning is this: when a target is about to be built, it checks its dependencies and if any are out of date (or don't exist), it triggers their building. The binary-dir file is built by the custom command. So when the custom target is built, it will check its dependency (the binary-dir file) and trigger a run of the custom command which is registered to OUTPUT that file.<br>
<br>Petr<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 30, 2014 at 4:25 PM, Eric Wing <span dir="ltr"><<a href="mailto:ewmailing@gmail.com" target="_blank">ewmailing@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Okay, I switched just the add_custom_target DEPENDS to the binary<br>
directory (but left the add_custom_command alone). That seems to be<br>
doing what I need. I think I'm still not fully understanding the<br>
reasoning behind it, but problem solved I guess.<br>
<br>
Thanks,<br>
Eric<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On 6/30/14, Eric Wing <<a href="mailto:ewmailing@gmail.com">ewmailing@gmail.com</a>> wrote:<br>
> Thanks for the reply. So the usage case is that people are going to be<br>
> modifying the resources in the source directory. (These changes have<br>
> to be checked into revision control.) So I'm having trouble seeing how<br>
> depending on the binary directory is going to work. (The reason I must<br>
> copy the resources to the binary directory is it is impossible to<br>
> launch the application through the debugger or otherwise.)<br>
><br>
> Thanks,<br>
> Eric<br>
><br>
><br>
> On 6/30/14, Petr Kmoch <<a href="mailto:petr.kmoch@gmail.com">petr.kmoch@gmail.com</a>> wrote:<br>
>> Hi Eric.<br>
>><br>
>> It seems to me that you're copying from source dir to binary dir, but all<br>
>> dependencies are on the source dir file only. Therefore, there is nothing<br>
>> to trigger the generation of the binary-dir file. Perhaps you wanted<br>
>> 'fooresources' to depend on the binary-dir file instead?<br>
>><br>
>> Petr<br>
>><br>
>><br>
>> On Mon, Jun 30, 2014 at 3:20 PM, Eric Wing <<a href="mailto:ewmailing@gmail.com">ewmailing@gmail.com</a>> wrote:<br>
>><br>
>>> I need to copy resource files from the source directory to the binary<br>
>>> directory with the creation of my executable. I want CMake's<br>
>>> dependency tracking to handle (re)copying these files whenever the<br>
>>> source has been touched.<br>
>>><br>
>>> Looking at other similar questions like:<br>
>>><br>
>>> <a href="http://stackoverflow.com/questions/17018477/cmake-adding-custom-resources-to-build-directory" target="_blank">http://stackoverflow.com/questions/17018477/cmake-adding-custom-resources-to-build-directory</a><br>

>>> and the CMake FAQ: How can I add a dependency to a source file which<br>
>>> is generated in a subdirectory?<br>
>>> <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
>>><br>
>>> I expected the following (simplified) code to work, but it doesn't. I<br>
>>> see the add_custom_target processed in the make chain, but the<br>
>>> add_custom_command never triggers.<br>
>>><br>
>>><br>
>>><br>
>>> project(foo)<br>
>>><br>
>>> cmake_minimum_required(VERSION 2.8)<br>
>>><br>
>>> add_executable(fooexe<br>
>>>         ${CMAKE_SOURCE_DIR}/foo.c<br>
>>>         ${CMAKE_SOURCE_DIR}/asset1.lua<br>
>>> #       ${CMAKE_SOURCE_DIR}/subdir/subasset1.lua<br>
>>> )<br>
>>><br>
>>> add_custom_command(<br>
>>>         OUTPUT "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INT}/asset1.lua"<br>
>>>         COMMAND ${CMAKE_COMMAND} -E copy_if_different<br>
>>> "${CMAKE_SOURCE_DIR}/asset1.lua"<br>
>>> "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INT}/"<br>
>>>         DEPENDS "${CMAKE_SOURCE_DIR}/asset1.lua"<br>
>>>         COMMENT "Copying asset1.lua"<br>
>>> )<br>
>>><br>
>>> # files are only copied if a target depends on them<br>
>>> add_custom_target(fooresources ALL DEPENDS<br>
>>> "${CMAKE_SOURCE_DIR}/asset1.lua"<br>
>>>         COMMENT "fooresources custom target"<br>
>>>         )<br>
>>> ADD_DEPENDENCIES(fooexe fooresources)<br>
>>><br>
>>><br>
>>><br>
>>> Would somebody explain to me the correct way to handle this?<br>
>>><br>
>>><br>
>>> Thanks,<br>
>>> Eric<br>
>>> --<br>
>>><br>
>>> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
>>><br>
>>> Please keep messages on-topic and check the CMake FAQ at:<br>
>>> <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
>>><br>
>>> Kitware offers various services to support the CMake community. For more<br>
>>> information on each offering, please visit:<br>
>>><br>
>>> CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
>>> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
>>> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
>>><br>
>>> Visit other Kitware open-source projects at<br>
>>> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>>><br>
>>> Follow this link to subscribe/unsubscribe:<br>
>>> <a href="http://public.kitware.com/mailman/listinfo/cmake" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
>>><br>
>><br>
><br>
><br>
> --<br>
> Beginning iPhone Games Development<br>
> <a href="http://playcontrol.net/iphonegamebook/" target="_blank">http://playcontrol.net/iphonegamebook/</a><br>
><br>
<br>
<br>
--<br>
Beginning iPhone Games Development<br>
<a href="http://playcontrol.net/iphonegamebook/" target="_blank">http://playcontrol.net/iphonegamebook/</a><br>
</div></div></blockquote></div><br></div>