[CMake] What is the correct way to manage a possibly user-defined directory?
Cedric Doucet
cedric.doucet at inria.fr
Mon May 18 07:35:49 EDT 2015
Hi Petr!
Thank you very much!
Now, I understand when an option should be used! :)
I tried
set(FOO_DIR "" CACHE PATH "Provide path to FOO library here")
and it works fine with the user interface!
Cheers,
Cédric
----- Mail original -----
> De: "Petr Kmoch" <petr.kmoch at gmail.com>
> À: "Cedric Doucet" <cedric.doucet at inria.fr>
> Cc: cmake at cmake.org
> Envoyé: Lundi 18 Mai 2015 12:04:21
> Objet: Re: [CMake] What is the correct way to manage a possibly user-defined
> directory?
> Hi Cedric.
> 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:
> if(NOT EXISTS ${FOO_DIR})
> Second, option() is intended for on/off options only (a checkbox). If you
> want to provide a path selector, use set(... CACHE) instead:
> set(FOO_DIR "" CACHE PATH "Provide path to FOO library here")
> This will create a path selector widget in CMake UI, with "Provide path to
> FOO library here" serving as its tooltip/documentation.
> Petr
> On Mon, May 18, 2015 at 11:48 AM, Cedric Doucet < cedric.doucet at inria.fr >
> wrote:
> > Hello,
>
> > I would like to let users choose between providing third party libraries or
> > let CMake download them.
>
> > To do that, I try to write a simple code like this to manage a third party
> > library FOO of an executable MY_EXEC:
>
> > =================================================
>
> > IF(NOT EXISTS FOO_DIR)
>
> > MESSAGE(STATUS "FOO LIBRARY WILL BE DOWNLOADED AND INSTALLED")
>
> > # download and install FOO, define FOO_DIR
>
> > ENDIF()
>
> > INCLUDE_DIRECTORIES(MY_EXEC ${FOO_DIR}/include)
>
> > TARGET_LINK_LIBRARIES(MY_EXEC ${FOO_DIR}/include)
>
> > =================================================
>
> > To do that, I think the user should have the possibility to define FOO_DIR
> > with an option.
>
> > So, I put the line
>
> > OPTION(FOO_DIR)
>
> > before the code below.
>
> > However, it doesn't seem to work because FOO_DIR does not seem to be
> > defined.
>
> > The message "FOO LIBRARY WILL BE DOWNLOADED AND INSTALLED" always appears,
>
> > - even if I type "cmake -D FOO_DIR=path", where path is a user-defined path
> > to FOO library,
>
> > - even if I put a default value to FOO_DIR with OPTION(FOO_DIR path), where
> > path is a hard-coded path to FOO.
>
> > Where does I make a mistake here?
>
> > What is the correct way to manage FOO_DIR when it can be defined by a user?
>
> > 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.
>
> > Thank you very much for your help!
>
> > Cédric
>
> > --
>
> > Powered by www.kitware.com
>
> > Please keep messages on-topic and check the CMake FAQ at:
> > http://www.cmake.org/Wiki/CMake_FAQ
>
> > Kitware offers various services to support the CMake community. For more
> > information on each offering, please visit:
>
> > CMake Support: http://cmake.org/cmake/help/support.html
>
> > CMake Consulting: http://cmake.org/cmake/help/consulting.html
>
> > CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
>
> > Follow this link to subscribe/unsubscribe:
>
> > http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150518/aec2227f/attachment.html>
More information about the CMake
mailing list