Linking clangTooling/LLVM statically with CMake and Homebrew on macOS

Hyde is a clangTooling-based frontend that compiles C++ into documentation boilerplate ready for consumption by Jekyll. We use CMake for our project setup, and on macOS we are using Homebrew to download/install Clang and LLVM.

The issue we are hitting is that the CMake script generates an Xcode project that links to libLLVM.dylib, requiring that it be present on all machines that are going to run the tool:

I would like to change this such that LLVM is statically linked into the artifact instead. The clangTooling libraries are already linked in this way. I can see static libraries for LLVM alongside LLVM.dylib, so I am reasonably confident this is possible, but I do not know the CMake invocation to make it happen. I have tried setting CMake parameters in CMakeLists.txt to be explicit about the need for static libraries, to no avail:

find_package(Clang REQUIRED clangTooling libClang clangASTMatchers)
find_package(Clang REQUIRED CONFIG)
find_package(LLVM REQUIRED CONFIG)

if(APPLE)
    set(LLVM_LINK_LLVM_DYLIB OFF)
    set(CLANG_LINK_CLANG_DYLIB "OFF")
    set(DISABLE_LLVM_LINK_LLVM_DYLIB ON)
endif()

Would anyone know what must do to CMakeLists.txt to get LLVM to link statically into my final artifact?

1 Like