<div dir="ltr"><div>Okay, I think I understand what you're saying. Variables set in a CMakeLists.txt file added by add_subdirectory are only visible in that CMakeLists.txt and any further ones it adds via add_subdirectory. The higher level CMakeLists.txt files would not have the necessary visibility, hence the need to cache the project source directory variable. To make it behave consistently it would be necessary for cmake to be able to set a variable in the scope of the top level CMakeLists.txt. Similar to the PARENT_SCOPE that the set() command already has, something like set(foo_SOURCE_PROJECT "path/to/source" ROOT_SCOPE). <br>
<br>I suspect that the reason cmake is caching these variable is because the set() command doesn't have a ROOT_SCOPE ability and using cache variables was the easiest way to simulate that. And we have to live with the unfortunate side effect that the cached variables don't exist on the first run but do on subsequent runs.<br>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 1 May 2014 19:00, John Drescher <span dir="ltr"><<a href="mailto:drescherjm@gmail.com" target="_blank">drescherjm@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Thu, May 1, 2014 at 1:54 PM, Glenn Coombs <<a href="mailto:glenn.coombs@gmail.com">glenn.coombs@gmail.com</a>> wrote:<br>
> What I am saying is that project("foo") should internally execute the<br>
> equivalent of set(foo_SOURCE_DIR "/path/to/source") rather than set(foo<br>
> "/path/to/source" CACHE STRING). That way it would fail on every run if you<br>
> referenced a project source directory variable before you had done the<br>
> add_subdirectory() for that project. Currently in that situation it fails<br>
> the first time you run cmake but works as expected on subsequent runs of<br>
> cmake, which I think is odd behaviour.<br>
><br>
<br>
</div>I am saying making this change to not cache the source folder would break<br>
<br>
cmake binfolder<br>
<br>
and<br>
<br>
cmake --build buildfolder<br>
<br>
and several other commands that have worked this way for years.<br>
<span class="HOEnZb"><font color="#888888"><br>
John<br>
</font></span></blockquote></div><br></div>