[CMake] What is the correct way to manage a possibly user-defined directory?
Cedric Doucet
cedric.doucet at inria.fr
Mon May 18 05:48:52 EDT 2015
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150518/c536436e/attachment.html>
More information about the CMake
mailing list