<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">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 CMake 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 CMake 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 CMake about the dependency so it will build correctly?</div></div>
</blockquote></div>
</blockquote></div>