3

I am trying to install libarchive on macOS for my school project. I tried to do it using brew formulae, but CMake says that it can't detect it. How can I install libarchive in the right way?

What I tried: brew install libarchive

What I got in CLion:

  Could NOT find LibArchive (missing: LibArchive_INCLUDE_DIR)
Kevin
  • 16,549
  • 8
  • 60
  • 74
Denys Ivanenko
  • 388
  • 7
  • 21

2 Answers2

1

As mentioned in this GitHub issue post, libarchive isn't installed into the standard system paths. So, you'll need to tell CMake where to find it by setting the following in your CMake file:

set(LibArchive_INCLUDE_DIR "/usr/local/opt/libarchive/include")

Note, you may have to modify the path here to match where libarchive was installed on your system

Kevin
  • 16,549
  • 8
  • 60
  • 74
  • The only thing is include direcotry is not `*/libarcvhie/lib`, but `*/libarchive/include`. – Denys Ivanenko May 15 '20 at 03:16
  • 1
    @DenisIvanenko Thanks, I didn't have the archive in front of me, so just was going off of the GitHub issue post. Hope this helps! – Kevin May 15 '20 at 09:06
0

This works for Linux, macOS and macOS on Apple silicon.

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    # Homebrew ships libarchive keg only, include dirs have to be set manually
    execute_process(
        COMMAND brew --prefix libarchive
        OUTPUT_VARIABLE LIBARCHIVE_PREFIX
        OUTPUT_STRIP_TRAILING_WHITESPACE
        COMMAND_ERROR_IS_FATAL ANY
    )
    set(LibArchive_INCLUDE_DIR "${LIBARCHIVE_PREFIX}/include")
endif()
find_package(LibArchive REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE LibArchive::LibArchive)
ManuelSchneid3r
  • 15,850
  • 12
  • 65
  • 103