<div dir="ltr">Hej Yves,<div><br></div><div>The problem is that the 'add_custom_command' does *NOT* create a new target, which seems to be what you assume, see <a href="https://cmake.org/cmake/help/v3.0/command/add_custom_command.html">https://cmake.org/cmake/help/v3.0/command/add_custom_command.html</a></div><div><br></div><div>The signature you're using is supposed to be used to *add* a custom command to an *existing* target. In other words, it should read:</div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">add_custom_command(TARGET </span><span style="font-size:12.8px">foo PRE_BUILD </span><span style="font-size:12.8px">COMMAND ${CMAKE_COMMAND} -E touch</span><br style="font-size:12.8px"><span style="font-size:12.8px">  ${CMAKE_BINARY_DIR}/myfile.</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">txt)</span><br></div><div><br></div><div>(and hopefully it is immediately obvious that the 'sleep' command should go - CMake will never execute that command)</div><div><br></div><div>Sincerely,</div><div>Jakob</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 17, 2017 at 12:02 PM, Yves Frederix <span dir="ltr"><<a href="mailto:yves.frederix+cmake@gmail.com" target="_blank">yves.frederix+cmake@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I have a situation in which I would need to define a dependency for<br>
the automoc target. Is it possible to do this somehow?<br>
<br>
Basically, I have a setup in which a resource that is to be embedded<br>
is generated by another target. However, due to parallelism in the<br>
build and the lack of a dependency of the _automoc target on this<br>
target, I often get an error like :<br>
<br>
   RCC: Error in '.../build/resources.qrc': Cannot find file<br>
'../build/myfile.txt'<br>
<br>
I tried adding a dependency using add_dependencies, but this doesn't<br>
seem to work.<br>
<br>
Minimal example code is below (you will need to create an empty<br>
main.cpp though). I am using CMake 3.7.1 with a VS generator. My build<br>
command looks like 'cmake --build . -- -m'.<br>
<br>
<br>
cmake_minimum_required(VERSION 3.7)<br>
<br>
project(test CXX)<br>
<br>
find_package(Qt5Quick REQUIRED)<br>
<br>
set(CMAKE_AUTORCC ON)<br>
<br>
# Define target that generates some files.<br>
add_custom_target(generate_<wbr>files)<br>
add_custom_command(TARGET generate_files COMMAND sleep 1) # Wait a bit...<br>
add_custom_command(TARGET generate_files COMMAND ${CMAKE_COMMAND} -E touch<br>
  ${CMAKE_BINARY_DIR}/myfile.<wbr>txt)<br>
<br>
# Write the .qrc file for embedding these generated files.<br>
file(WRITE ${CMAKE_BINARY_DIR}/resources.<wbr>qrc<br>
  "<!DOCTYPE RCC><RCC<br>
  version=\"1.0\">\n<qresource>\<wbr>n<file>${CMAKE_BINARY_DIR}/<wbr>myfile.txt</file>\n</<wbr>qresource>\n</RCC>")<br>
<br>
add_library(foo SHARED main.cpp ${CMAKE_BINARY_DIR}/resources.<wbr>qrc)<br>
add_dependencies(foo generate_files)<br>
target_link_libraries(foo PRIVATE Qt5::Quick)<br>
<br>
<br>
Thanks!<br>
<br>
Regards,<br>
Yves<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/cmake</a><br>
</blockquote></div><br></div>