clang-uml: Building on non-homebrew arm64 Mac is problematic

I use macports instead of homebrew. I had some issues building, then running.

Got the build to work by doing something like (using fish shell)

begin
    set -lx LLVM_DIR (llvm-config --cmakedir)
    set -lx CMAKE_INSTALL_PREFIX ~/local
    make release
end

(Obviously the install prefix isn’t important here, but I include it for completeness.) However, this always ended (after install) with

$ clang-uml --help
dyld[8313]: Library not loaded: @rpath/libclang-cpp.dylib
  Referenced from: <4F31F4CC-6DA1-362A-A1B6-5E467E264D27> /Users/ehkropf/local/bin/clang-uml
  Reason: no LC_RPATH's found

But if I run the command install_name_tool -add_rpath (llvm-config --libdir) ~/local/bin/clang-uml, it then runs and prints help text as expected.

Setting LLVM_CONFIG_PATH resulted in the same error from the cmake find_package() command – couldn’t locate the llvm cmake files.

Made the changes shown below to cmake/LLVMSetup.cmake. These changes allow it to compile and run as above

$ git diff v0.6.1
diff --git a/cmake/LLVMSetup.cmake b/cmake/LLVMSetup.cmake
index c3fe97f5..ca43f68c 100644
--- a/cmake/LLVMSetup.cmake
+++ b/cmake/LLVMSetup.cmake
@@ -1,25 +1,35 @@
 message(STATUS "Checking for LLVM and Clang...")

+# Use the environment to figure out where llvm-config is located.
+if ("${LLVM_CONFIG_PATH}" STREQUAL "")
+    message(STATUS "LLVM_CONFIG_PATH not provided, trying to find it...")
+    # Try to find llvm-config in PATH
+    find_program(LLVM_CONFIG_EXECUTABLE NAMES llvm-config)
+    if(NOT LLVM_CONFIG_EXECUTABLE STREQUAL "")
+        get_filename_component(LLVM_CONFIG_PATH ${LLVM_CONFIG_EXECUTABLE} PATH)
+        message(STATUS "Found ${LLVM_CONFIG_EXECUTABLE}")
+    else()
+        message(STATUS "llvm-config not found in environment")
+    endif()
+endif()
+
 # If user provided a path to llvm-config executable use it to detect
 # LLVM Version and appropriate CMake module path
 if(NOT "${LLVM_CONFIG_PATH}" STREQUAL "")
-    # Get LLVM prefix
+    # Get LLVM paths
     message(STATUS "Using llvm-config from ${LLVM_CONFIG_PATH}")
-    set(LIBCLANG_LLVM_CONFIG_EXECUTABLE ${LLVM_CONFIG_PATH})
-    set(LLVM_CONFIG_BINARY ${LLVM_CONFIG_PATH})
-    execute_process(COMMAND ${LLVM_CONFIG_PATH} --prefix
-            OUTPUT_VARIABLE LLVM_PREFIX OUTPUT_STRIP_TRAILING_WHITESPACE)
-    set(LLVM_CMAKE_DIR "${LLVM_PREFIX}/lib/cmake/llvm")
-
-    list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
+    set(LIBCLANG_LLVM_CONFIG_EXECUTABLE "${LLVM_CONFIG_PATH}/llvm-config")
+    execute_process(COMMAND ${LIBCLANG_LLVM_CONFIG_EXECUTABLE} --cmakedir
+        OUTPUT_VARIABLE LLVM_CMAKE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+    message(STATUS "Using LLVM_CMAKE_DIR=${LLVM_CMAKE_DIR}")
+    set(LLVM_DIR ${LLVM_CMAKE_DIR})

     # Get LLVM version
-    execute_process(COMMAND ${LLVM_CONFIG_PATH} --version
+    execute_process(COMMAND ${LIBCLANG_LLVM_CONFIG_EXECUTABLE} --version
             OUTPUT_VARIABLE LLVM_VERSION_STR OUTPUT_STRIP_TRAILING_WHITESPACE)
-
-    string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.(.+)"
-            GIT_VERSION_MATCH ${LLVM_VERSION_STR})
-    set(LLVM_VERSION ${CMAKE_MATCH_1})
+    set(LLVM_VERSION "${LLVM_VERSION_STR}")
+    message(STATUS "Detected version ${LLVM_VERSION}")
 endif()

 if(LLVM_VERSION STREQUAL "18")

Was going to create a pull request for this, but after reading CONTRIBUTING.md, I’m not sure what should be done here to make a “good” pull request.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I am able to confirm the first two commands given above do result in compilation and passing tests. Thanks!