<div dir="ltr"><div><div><div><div>Hi Doug,<br><br></div>your syntax for `set()` in Foo is incorrect; you're actually setting a non-cache variable OPT1 do the value "ON;FORCE".<br><br></div>You want to set the *cache* variable OPT1, which would be done like this:<br><br></div>  set(OPT1 ON CACHE BOOL "Set to OFF|ON (default is OFF) to control build of Bar library" FORCE)<br><br></div>Petr<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 20 May 2016 at 11:24, Doug Cuthbertson <span dir="ltr"><<a href="mailto:doug.cuthbertson@gmail.com" target="_blank">doug.cuthbertson@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 dir="ltr"><br style="font-size:12.8px"><div dir="ltr" style="font-size:12.8px">CMake (version 3.5.2) surprised me with how it's passing values to sub-projects, so I was wondering if this is expected behavior. Here's an example of what I mean. Let's say I have a project Foo in a directory of the same name. It contains a third-party library called Bar which has a CMakeLists.txt file that looks like:<div><br></div><div>    cmake_minimum_required(VERSION 2.8.12)</div><div>    </div><div><div>    option(OPT1</div><div>      "Set to OFF|ON (default is OFF) to control build of Bar library" OFF)</div><div>    </div><div>    if(OPT1)</div><div>      message("Bar: OPT1 is on")</div><div>    else(OPT1)</div><div>      message("Bar: OPT1 is off")</div><div>    endif(OPT1)</div><div><br></div><div>I then create CMakeLists.txt for Foo that sets OPT1 to ON and includes Bar:</div><div><br></div><div><div>    cmake_minimum_required(VERSION 2.8.12)</div><div>    </div><div></div><div>    set(OPT1 ON FORCE)</div><div>    if(OPT1)</div><div>      message("Foo: OPT1 is on")</div><div>    else(OPT1)</div><div>      message("Foo: OPT1 is off")</div><div>    endif(OPT1)</div><div>    add_subdirectory(Bar)</div></div><div><br></div><div>The first time I run cmake the message output is:</div><div><br></div><div>    Foo: OPT1 is on</div><div>    Bar: OPT1 is off</div><div><br></div><div>If I run cmake again, I get:</div><div><br></div><div>    Foo: OPT1 is on</div><div>    Bar: OPT1 is on</div><div><br></div><div>If this is expected behavior, is there any way I can ensure Bar receives the value of OPT1 the first time? It makes a huge difference when the option controls, for example, whether a static or dynamic library will be built.</div><div><br></div><div>Thanks,</div><div>Doug</div></div></div></div>
<br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br></blockquote></div><br></div>