In the cmake documentation for target_link_libraries() it says that:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<span style="line-height:22px;text-align:justify;font-size:11px;font-family:Verdana,Arial,Helvetica,sans-serif">The named &lt;target&gt; must have been created in the current directory by a command such as add_executable or add_library. </span></blockquote>


<div><br></div><div> Can someone provide a reason for that, and is there a work-around? </div><div><div><br class="Apple-interchange-newline"><br></div><div>We have a large project that is composed of many smaller semi-independent modules (each module builds one or more libraries and/or executables). Each module contains its own CMakeLists.txt file which is added to the top level project&#39;s CMakeLists.txt file with add_subdirectory(). Each module stores the set of public libraries that it generates, allowing us to specify dependencies between targets and modules (multiple targets).</div>

<div><br></div><div>However for this to work, the CMakeLists.txt in the module directory must be parsed by cmake before the CMakeLists.txt of the target target. </div><div><br></div></div><div>Currently, we manually specify the order that modules get built, however this is fragile and error prone.</div>

<div><br></div><div>The cleanest way that I have thought of to remedy this situation would be to aggregate the target-&gt;module dependencies into a cached file, and then parse this file as the last thing cmake does, calling target_link_libraries() as needed. Unfortunately, this would require a function that could call target_link_libraries() from a directory that is different than the directory where the target was created :-/</div>

<div><br></div><div>Thanks!</div>