<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div><br></div><div>Hi Petr!<br></div><div><br></div><div>Thank you very much!<br>Now, I understand when an option should be used! :)</div><div><br>I tried <br></div><div>set(FOO_DIR "" CACHE PATH "Provide path to FOO library here")</div><div>and it works fine with the user interface!<br></div><div><br></div><div>Cheers,<br></div><div><br></div><div>Cédric<br></div><div><br></div><div><br></div><hr id="zwchr"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Petr Kmoch" <petr.kmoch@gmail.com><br><b>À: </b>"Cedric Doucet" <cedric.doucet@inria.fr><br><b>Cc: </b>cmake@cmake.org<br><b>Envoyé: </b>Lundi 18 Mai 2015 12:04:21<br><b>Objet: </b>Re: [CMake] What is the correct way to manage a possibly user-defined directory?<br><div><br></div><div dir="ltr"><div><div><div><div><div><div>Hi Cedric.<br><div><br></div></div>if(EXISTS) does not automatically dereference its argument. So your current code is testing for the existence of a directory literally named "FOO_DIR". You want to dereference the variable:<br><div><br></div></div>    if(NOT EXISTS ${FOO_DIR})<br><div><br></div></div>Second, option() is intended for on/off options only (a checkbox). If you want to provide a path selector, use set(... CACHE) instead:<br><div><br></div></div>    set(FOO_DIR "" CACHE PATH "Provide path to FOO library here")<br><div><br></div><br></div>This will create a path selector widget in CMake UI, with "Provide path to FOO library here" serving as its tooltip/documentation.<br><div><br></div></div>Petr<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 18, 2015 at 11:48 AM, Cedric Doucet <span dir="ltr"><<a href="mailto:cedric.doucet@inria.fr" target="_blank">cedric.doucet@inria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000"><div><br></div><div>Hello,<br></div><div><br></div><div>I would like to let users choose between providing third party libraries or let CMake download them.<br>To do that, I try to write a simple code like this to manage a third party library FOO of an executable MY_EXEC:<br></div><div>=================================================<br></div><div>IF(NOT EXISTS FOO_DIR)<br></div><div>      MESSAGE(STATUS "FOO LIBRARY WILL BE DOWNLOADED AND INSTALLED")<br></div><div>      # download and install FOO, define FOO_DIR<br></div><div>ENDIF()<br></div><div>INCLUDE_DIRECTORIES(MY_EXEC ${FOO_DIR}/include)<br>TARGET_LINK_LIBRARIES(MY_EXEC ${FOO_DIR}/include)<br></div><div>=================================================</div><div>To do that, I think the user should have the possibility to define FOO_DIR with an option.<br></div><div>So, I put the line<br></div><div>OPTION(FOO_DIR)<br></div><div>before the code below.<br></div><div><br></div><div>However, it doesn't seem to work because FOO_DIR does not seem to be defined.<br></div><div>The message "FOO LIBRARY WILL BE DOWNLOADED AND INSTALLED" always appears, </div><div>- even if I type "cmake -D FOO_DIR=path", where path is a user-defined path to FOO library,<br></div><div>- even if I put a default value to FOO_DIR with OPTION(FOO_DIR path), where path is a hard-coded path to FOO.<br></div><div><br></div><div>Where does I make a mistake here?<br></div><div>What is the correct way to manage FOO_DIR when it can be defined by a user?<br></div><div><br></div><div>Note: the next step is to define FOO_DIR in a FindFoo.cmake file and use find_package(Foo), but it's not my goal yet.<br></div><div><br></div><div>Thank you very much for your help!<br></div><div><br></div><div>Cédric<br></div><div><br></div></div></div><br>--<br>
<br>
Powered by <a href="http://www.kitware.com" 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" 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" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" 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" 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" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br></blockquote></div><br></div>
</blockquote><div><br></div></div></body></html>