<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div><br></div><div>Ok, I found the error:<br></div><div>IF(NOT EXISTS FOO_DIR)</div><div>should be replaced by<br></div><div>IF(NOT EXISTS ${FOO_DIR})</div><div><br></div><div>However, it seems I don't need to define an option.<br></div><div>I just have to type<br></div><div>cmake -D FOO_DIR=path ..<br></div><div><br></div><div>Should I define an option?<br></div><div>When does one need to define an option?<br></div><div><br></div><div>Cédric<br></div><div><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>"Cedric Doucet" <cedric.doucet@inria.fr><br><b>À: </b>cmake@cmake.org<br><b>Envoyé: </b>Lundi 18 Mai 2015 11:48:52<br><b>Objet: </b>[CMake] What is the correct way to manage a possibly user-defined directory?<br><div><br></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><br>-- <br><div><br></div>Powered by www.kitware.com<br><div><br></div>Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ<br><div><br></div>Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br><div><br></div>CMake Support: http://cmake.org/cmake/help/support.html<br>CMake Consulting: http://cmake.org/cmake/help/consulting.html<br>CMake Training Courses: http://cmake.org/cmake/help/training.html<br><div><br></div>Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br><div><br></div>Follow this link to subscribe/unsubscribe:<br>http://public.kitware.com/mailman/listinfo/cmake</blockquote><div><br></div></div></body></html>