<div dir="ltr"><div dir="ltr">How is this file subproject1 depends on generated?<div><br></div><div>I have a project where some file was generated using add_custom_command, like this:</div><div><br></div><div><font face="monospace, monospace">    add_custom_command( OUTPUT ${FILE_NAME} COMMAND ${CMD_LINE} )</font></div><div><br></div><div>So, in order to my lib to depend on this file I created a custom target</div><div><br></div><div><font face="monospace, monospace">    add_custom_target( target_name, ALL DEPENDS ${FILE_NAME} )</font></div><div><br></div><div>and then added as a dependency to my lib:</div><div><br></div><div><font face="monospace, monospace">    add_dependencies( my_lib_name, target_name ${FILE_NAME} )</font></div><div><br></div><div>See and try adding an explicit dependency on the generated file like this.</div><div><div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em ter, 19 de mar de 2019 às 14:46, Timothy Wrona <<a href="mailto:tjwrona1992@gmail.com" target="_blank">tjwrona1992@gmail.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Never mind... I spoke too soon. add_dependencies isn't working. It is correctly making the other project build first, but the header file is for some reason not generated until after it is needed.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 19, 2019 at 1:41 PM Timothy Wrona <<a href="mailto:tjwrona1992@gmail.com" target="_blank">tjwrona1992@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Seems I might be able to answer my own question.<div><br></div><div>It looks like "add_dependencies(subproject1_exe subproject2_lib)" worked.</div><div><br></div><div>I had to do a clean first though because it didn't work the first time since some old files were left around.</div><div><br></div><div>Hope this helps anyone else with a similar issue!</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 19, 2019 at 1:13 PM Timothy Wrona <<a href="mailto:tjwrona1992@gmail.com" target="_blank">tjwrona1992@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I am working on a complex <span class="gmail-il">CMake</span> project that is part of a large legacy system that uses a top level project and "add_subdirectory" to create subprojects.<div><br></div><div>I have run into an issue because now one of the subprojects is dependant on another subproject, but I can't seem to find a clear way to tell <span class="gmail-il">CMake</span> about this dependency.</div><div><br></div><div>Consider this example:</div><div><br></div><div><font face="monospace, monospace">    my_project/</font></div><div><font face="monospace, monospace">        CMakeLists.txt:</font></div><div><font face="monospace, monospace">          add_subdirectory('subproject1')</font></div><div><font face="monospace, monospace">          add_subdirectory('subproject2')</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    my_project/subproject1/</font></div><div><font face="monospace, monospace">        CMakeLists.txt:</font></div><div><font face="monospace, monospace">            add_executable(subproject1_exe <sources>)</font></div><div><font face="monospace, monospace">            target_link_libraries(subproject1_exe subproject2_lib) # <-- THIS is the problem</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    my_project/subproject2/</font></div><div><font face="monospace, monospace">        CMakeLists.txt:</font></div><div><font face="monospace, monospace">            add_library(subproject2_lib <sources>)</font></div><div><br></div><div>The actual code is much more complex than this, but this simple example illustrates the problem. The actual compilation error I am getting is caused by subproject1 including a header file that gets generated when subproject2 is built.</div><div><br></div><div>Does anyone know how to properly tell <span class="gmail-il">CMake</span> about the dependency so it will build correctly?</div></div></blockquote></div></blockquote></div>-- </blockquote></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">-- <br>Rafael Vargas</div></div></div>