<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div><br></div><div><br></div><div>On Mon, Oct 7, 2019, at 6:55 AM, Craig Scott wrote:<br></div><blockquote type="cite" id="qt"><div dir="ltr"><div dir="ltr"><br></div><div><br></div><div class="qt-gmail_quote"><div class="qt-gmail_attr" dir="ltr">On Mon, Oct 7, 2019 at 9:32 PM Setzer Sebastian (CM-CI2/ECS2) via CMake <<a href="mailto:cmake@cmake.org">cmake@cmake.org</a>> wrote:<br></div><blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204, 204, 204);padding-left:1ex;" class="qt-gmail_quote"><div>Dear list,<br></div><div> The manual says:<br></div><div> <a rel="noreferrer" href="https://cmake.org/cmake/help/latest/command/add_custom_target.html">https://cmake.org/cmake/help/latest/command/add_custom_target.html</a><br></div><div> Reference files and outputs of custom commands created with add_custom_command() command calls in the same directory (CMakeLists.txt file). They will be brought up to date when the target is built.<br></div><div> Use the add_dependencies() command to add dependencies on other targets.<br></div><div> <br></div><div> This is different from what the manual of add_custom_command says, and would be surprising for all users who only read the manual of add_custom_command and then think they know what the parameter means for add_custom_target.<br></div><div> <br></div><div> But on the other hand, when I test with this:<br></div><div> --------------------------------------------------<br></div><div> cmake_minimum_required (VERSION 3.14)<br></div><div> project(dependency_test LANGUAGES)<br></div><div> <br></div><div> add_custom_target(T1<br></div><div>                   COMMAND echo T1<br></div><div>                   )<br></div><div> add_custom_target(T2<br></div><div>                   COMMAND echo T2<br></div><div>                   DEPENDS T1<br></div><div>                   )<br></div><div> <br></div><div> # cmake -GNinja -B build .<br></div><div> # ninja T2<br></div><div> --------------------------------------------------<br></div><div> Then T1 and T2 are built, so contrary to what the manual says, it seems to work.<br></div><div> <br></div><div> Is the manual just outdated (Maybe behavior has changed and only manual for add_custom_command has been updated)?<br></div><div> Should it be the same as for add_custom_command, or are there really some differences?<br></div></blockquote></div><div><br></div><div>As it happens, I just updated the docs for these in the last day or so. You can find it in the not-yet-merged merge request here:<br></div><div><br></div><div><a href="https://gitlab.kitware.com/cmake/cmake/merge_requests/3891">https://gitlab.kitware.com/cmake/cmake/merge_requests/3891</a><br></div><div><br></div><div>I wrote an explanation of the specific behavior of the dependencies in the associated issue here:<br></div><div><br></div><div><a href="https://gitlab.kitware.com/cmake/cmake/issues/19771#note_635547">https://gitlab.kitware.com/cmake/cmake/issues/19771#note_635547</a><br></div><div><br></div><div>There is a difference between the two, but it's subtle and specific to the sort of scenario I mentioned in that issue comment.<br></div><div><br></div><div>-- <br></div><div class="qt-gmail_signature" dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Craig Scott<br></div><div>Melbourne, Australia<br></div><div><a href="https://crascit.com">https://crascit.com</a><br></div><div><br></div><div>Get the hand-book for every CMake user: <a href="https://crascit.com/professional-cmake/">Professional CMake: A Practical Guide</a><br></div><div>Consulting services (CMake, C++, build/release processes): <a href="https://crascit.com/services">https://crascit.com/services</a><br></div></div></div></div></div></div></div></div></div></div></div></div><div>-- <br></div><div><br></div><div>Powered by www.kitware.com<br></div><div><br></div><div>Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ<br></div><div><br></div><div>Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br></div><div><br></div><div>CMake Support: http://cmake.org/cmake/help/support.html<br></div><div>CMake Consulting: http://cmake.org/cmake/help/consulting.html<br></div><div>CMake Training Courses: http://cmake.org/cmake/help/training.html<br></div><div><br></div><div>Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br></div><div><br></div><div>Follow this link to subscribe/unsubscribe:<br></div><div>https://cmake.org/mailman/listinfo/cmake<br></div></blockquote><div><br></div><div>I found the wording for add_custom_command and add_custom_target to be confusing and had to look at examples (and books) to understand it better.<br></div><div><br></div><div>The DEPENDS field is kind of different for the two commands. <br></div><div><br></div><div>It may be that add_custom_target "DEPENDS" can accept other custom targets; it seems from your example it does (which wouldn't surprise me from what I remember from the CMake source code).<br></div><div><br></div><div>For add_custom_target:<br></div><div>The phrase "They will be brought up to date when the target is built." had me thinking that this was going to force the custom command to always run.<br></div><div><br></div><div>Its more of a "The commands of add_custom_target() outputs will be run as needed before any add_custom_target() commands are run."<br></div><div><br></div><div>If a file listed in DEPENDS does not exist on disk then behavior is defined by the build tool and may or may not throw an error.  I recall that Make and Ninja throws errors and MSBuild will have a warning.<br></div><div><br></div><div>Then there is the SOURCES field which acts like:<br></div><div>Similar to ``DEPENDS`` with the addition that the specified files  are checked to exist on disk and will be  added to IDE project files for convenience in editing.<br></div><div><br></div><div>"add_custom_target() sometimes builds SOURCES for Visual Studio generators but never for Makefiles"<br></div><div><a href="https://gitlab.kitware.com/cmake/cmake/issues/10360">https://gitlab.kitware.com/cmake/cmake/issues/10360</a><br></div><div><br></div><div>For add_custom_command it acts like (and this includes the trick that is used to make it always run):<br></div><div>If ``DEPENDS`` is not specified the command will run whenever the ``OUTPUT`` is missing or it will run whenever a file-level dependency is updated. If the command does not create one of the listed ``OUTPUT`` then the rule will always run. For example defining an output file called ALL or FORCE that is never created.<br></div><div><br></div><div>Then for the add_custom_command signature that is used for build events.  You don't need to put the event.  It defaults to POST_BUILD.  This is different from the documentation that shows it is a required field.<br></div><div><br></div><div>--<br></div><div>Fred<br></div></body></html>