aaronman
aaronman

Reputation: 18751

Get cmake and home-brew to work together

When I install libraries with homebrew cmake can't seem to find them. Is there a simple way to fix this for an arbitrary library installed with brew.

Upvotes: 12

Views: 10887

Answers (1)

user2288008
user2288008

Reputation:

Default

By default brew's libraries installed to /usr/local/lib folder:

> ls /usr/local/lib/liblzma.dylib 
/usr/local/lib/liblzma.dylib@

Check that this path exists in CMAKE_SYSTEM_PREFIX_PATH variable. In this case find is trivial:

message("system: ${CMAKE_SYSTEM_PREFIX_PATH}")
find_library(LZMA_LIBRARY lzma)
message("lzma: ${LZMA_LIBRARY}")

Result:

system: /usr/local;/usr;/;...
lzma: /usr/local/lib/liblzma.dylib

Otherwise

If it is not you need to modify CMAKE_PREFIX_PATH or CMAKE_LIBRARY_PATH before find_library command:

list(APPEND CMAKE_PREFIX_PATH /usr/local)

Upvotes: 19

Related Questions