<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>
<div>Dear Cornelis,</div>

<div> </div>

<div>your description looks to me like having a three valued option: ON, OFF, UNDEFINED. But an option in cmake language has only two values: ON or OFF. </div>

<div>To solve your problem with the connection between your sub-project and the main project, you should forget about the main project and concentrate on the sub project only. Than, you have two possibilities:</div>

<div>    1) Keep the three state variable "THAT_OPTION". Set it to undefined at the very beginning and check later with if(DEFINED THAT_OPTION) .... With this variant, you can handle the "I forgot to set it"-case. But your user will not see it as an option in the cmake gui. Your main project will set it, as desired.</div>

<div>    2) Use an initial value for the option. Now, it is always defined, there is no need to check for the source. It is the responsibility of the user to set the option appropriately.</div>

<div> </div>

<div>I think, the second version is the easiest way.</div>

<div> </div>

<div>Regards,</div>

<div>Andreas</div>

<div> 
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><b>Gesendet:</b> Montag, 11. Juni 2018 um 10:20 Uhr<br/>
<b>Von:</b> "Cornelis Bockemühl" <cornelis@bockemuehl.ch><br/>
<b>An:</b> cmake@cmake.org<br/>
<b>Betreff:</b> [CMake] conditions and included subprojects</div>

<div name="quoted-content">
<div>Dear CMake users,</div>

<div> </div>

<div>Maybe my question is trivial for most, but still I do not find an answer on my own!</div>

<div> </div>

<div>If you have a project and some sub-project (or module or whatever the jargon is) that are both managed with CMake, they should be in separate directories (directory trees), and each of them have a CMakeLists.txt in the root directory, where the sub-project is "included" into the main project with an ADD_DIRECTORY() etc. So far so clear.</div>

<div> </div>

<div>But then I learned that it is good practice to ensure that the sub-project would also be "buildable" with cmake separately. My problem is about how to pass options from the main to the sub project in such a way that this is working properly, i.e.:</div>

<div> </div>

<div>- if the sub project is part of the main project it would simply take over the option from the main project level</div>

<div>- but if the sub project is being built standalone, the option is not defined and should be set e.g. in cmake-gui</div>

<div> </div>

<div>If I write now in the sub project</div>

<div> </div>

<div>IF(THAT_OPTION)</div>

<div>...</div>

<div> </div>

<div>this will be true if THAT_OPTION was set to ON in the main project. So far so good. But the expression is now so "clever" that it cannot distinguish between THAT_OPTION being set to OFF in the main project, or THAT_OPTION not being defined at all - like in a standalone build!</div>

<div> </div>

<div>One way would be to have an additional option or variable BUILDING_MAINPROJECT which is set to ON or TRUE in the main project and can be checked. However, I have so far not seen any CMakeLists.txt with such a code, so ... what are the experts doing in such a case?</div>

<div> </div>

<div>Thanks and regards,</div>

<div>Cornelis</div>

<div> </div>
-- Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a> Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a> Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a> Follow this link to subscribe/unsubscribe: <a href="https://cmake.org/mailman/listinfo/cmake" target="_blank">https://cmake.org/mailman/listinfo/cmake</a></div>
</div>
</div>
</div></div></body></html>