[mlpack-git] [mlpack] Cannot find_package(mlpack) via cmake (#444)

Ryan Curtin notifications at github.com
Wed Jul 1 09:08:13 EDT 2015


Hi there,

To my knowledge nobody has made a `FindMLPACK.cmake` file that either ships as part of CMake or can be used in your project individually.  If you were to write one, I'd happily include it in the mlpack sources and it could be submitted to the CMake project for inclusion in future releases.  The `Find*.cmake` files generally are just a nice wrapper around `find_library()` and `find_path()`.  Below is an example of how you might use those for mlpack:

```
# Store the mlpack include directory in MLPACK_INCLUDE_DIR.
# The PATHS variable may be specified to give hints for where to find core.hpp.
find_path(MLPACK_INCLUDE_DIR
  NAMES core.hpp prereqs.hpp
  PATHS "$ENV{ProgramFiles}/mlpack/" /usr/local/include/
)

# Find libmlpack.so (or equivalent) and store it in MLPACK_LIBRARY.
# If this example script were smarter, it would also find other dependencies of mlpack and store them in
# an MLPACK_LIBRARIES variable instead.
find_library(MLPACK_LIBRARY
  NAMES mlpack
  PATHS "$ENV{ProgramFiles}/mlpack/" /usr/lib64/ /usr/lib/ /usr/local/lib64/ /usr/local/
)
```

and then assuming those calls were successful (I think they will issue an error on failure; if not, you can use an `if(not MLPACK_LIBRARY)` type statement to catch the error and print a failure message or something), you can tell CMake to add the include directories:

```
include_directories(${MLPACK_INCLUDE_DIR})
```

and then link your application against mlpack like you would for any other library:

```
target_link_libraries(hmm_train ${MLPACK_LIBRARY})
```

Like I noted in the comments, my simple example here doesn't find the dependencies of mlpack and link against them too, so you may have to expand the code a bit and find Armadillo, Boost, and libxml2 and use `target_link_libraries()` to link your code correctly (I think that's it).

---
Reply to this email directly or view it on GitHub:
https://github.com/mlpack/mlpack/issues/444#issuecomment-117660440
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.cc.gatech.edu/pipermail/mlpack-git/attachments/20150701/08b4c99e/attachment.html>


More information about the mlpack-git mailing list