1

I'm trying to find the most convenient way of installing C++ libraries on macOS by using brew. It's my first approach to understand cmake with CLion.

I would like to use C++ library osmium https://github.com/osmcode/libosmium:

$ brew install libosmium

$ brew list libosmium /usr/local/Cellar/libosmium/2.15.4/include/osmium/ (198 files) /usr/local/Cellar/libosmium/2.15.4/include/gdalcpp.hpp /usr/local/Cellar/libosmium/2.15.4/libexec/include/ (12 files)

$ brew unlink libosmium --dry-run | xargs ls -l /usr/local/include/gdalcpp.hpp -> ../Cellar/libosmium/2.15.4/include/gdalcpp.hpp /usr/local/include/osmium -> ../Cellar/libosmium/2.15.4/include/osmium

Based on this post I tried to add paths:

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

list(APPEND CMAKE_SYSTEM_PREFIX_PATH /usr/local/include)
list(APPEND CMAKE_PREFIX_PATH /usr/local/include)
list(APPEND CMAKE_LIBRARY_PATH /usr/local/include)

find_library(OSMIUM_LIBRARY_LIB libosmium)
find_library(OSMIUM_LIBRARY osmium)

message("osmium: ${OSMIUM_LIBRARY}")
message("osmium_lib: ${OSMIUM_LIBRARY_LIB}")

Output:

lzma: /usr/local/lib/liblzma.dylib
osmium: OSMIUM_LIBRARY-NOTFOUND
osmium_lib: OSMIUM_LIBRARY_LIB-NOTFOUND

Then I played around with this answer:

if(APPLE)
    set(CMAKE_FIND_FRAMEWORK ONLY)
    message(APPLE)
    find_library(OSM
            NAMES osmium libosmium
            HINTS /usr/local/include
            REQUIRED)
    message("OSM: ${OSM}")
    if(OSM)
        include_directories(${OSM}/Headers)
        link_libraries(${OSM})
        message("OSM found: ${OSM}")
    endif()
endif()

Output:

APPLE
OSM: OSM-NOTFOUND

To make everything clear this is the code which I'm trying to execute and this is the error:

main.cpp:5:10: fatal error: 'osmium/io/any_input.hpp' file not found
#include <osmium/io/any_input.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Maybe there is a better way to integrate external libraries C++. I'm open for suggestions.

zperkowski
  • 11
  • 3
  • 1
    From the project's [README](https://github.com/osmcode/libosmium/blob/master/README.md): "Osmium is a **header-only** library, so there is nothing to build for the library itself.". So `find_library` is not needed. – Tsyvarev Mar 24 '20 at 12:14
  • @Tsyvarev So you are saying `find_library` is building under the hood by using cmake files? However it would mean that my project should be able to find the library installed by brew itself but is not. Does not matter if I modify `CMakeList.txt` or not, the error which is at the end of the question appears anyway. – zperkowski Mar 24 '20 at 12:20
  • Directory `/usr/local/include` should be automatically used as include directory. If not sure, you may always explicitely add this directory: `include_directories("/usr/local/include")`.Please, show (add to the question post) **exact** `CMakeList.txt` file which you use for building the example and **exact** error message it produces. – Tsyvarev Mar 24 '20 at 12:37
  • `include_directories("/usr/local/include")` helped. I didn't know that this command has to be used. Thank you for your help! – zperkowski Mar 24 '20 at 14:56

0 Answers0