[llvm] [CMake][OCaml] Make OCaml bindings suitable for out-of-tree install (PR #123478)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 18 13:31:01 PST 2025
https://github.com/alan-j-hu created https://github.com/llvm/llvm-project/pull/123478
- CMAKE_{STATIC,SHARED}_LIBRARY_SUFFIX reports incorrect suffixes for Mac. Use .so and .a for both Mac and Linux.
- Add LLVM_OCAML_EXTERNAL_LLVM_LIBDIR option.
- LLVM dynamic library is always suffixed with major version
>From 1644b1b49d898cf9230011b95037d3b1d2f6510c Mon Sep 17 00:00:00 2001
From: Alan Hu <ahulambda at gmail.com>
Date: Sat, 18 Jan 2025 16:20:20 -0500
Subject: [PATCH] [CMake][OCaml] Make OCaml bindings suitable for out-of-tree
install
- CMAKE_{STATIC,SHARED}_LIBRARY_SUFFIX reports incorrect suffixes for Mac.
Use .so and .a for both Mac and Linux.
- Add LLVM_OCAML_EXTERNAL_LLVM_LIBDIR option.
- LLVM dynamic library is always suffixed with major version
---
llvm/bindings/ocaml/README.txt | 1 +
llvm/cmake/modules/AddOCaml.cmake | 13 +++++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/llvm/bindings/ocaml/README.txt b/llvm/bindings/ocaml/README.txt
index 08b5514e0a6642..053931df40919a 100644
--- a/llvm/bindings/ocaml/README.txt
+++ b/llvm/bindings/ocaml/README.txt
@@ -19,6 +19,7 @@ The bindings can also be built out-of-tree, i.e. targeting a preinstalled
LLVM. To do this, configure the LLVM build tree as follows:
$ cmake -DLLVM_OCAML_OUT_OF_TREE=TRUE \
+ -DLLVM_OCAML_EXTERNAL_LLVM_LIBDIR=[llvm-config --libdir] \
-DCMAKE_INSTALL_PREFIX=[Preinstalled LLVM path] \
-DLLVM_OCAML_INSTALL_PATH=[OCaml install prefix] \
[... any other options]
diff --git a/llvm/cmake/modules/AddOCaml.cmake b/llvm/cmake/modules/AddOCaml.cmake
index 2d9116b08a5261..8a7720d5dc3e38 100644
--- a/llvm/cmake/modules/AddOCaml.cmake
+++ b/llvm/cmake/modules/AddOCaml.cmake
@@ -40,10 +40,10 @@ function(add_ocaml_library name)
set(ocaml_outputs "${bin}/${name}.cma")
if( ARG_C )
list(APPEND ocaml_outputs
- "${bin}/lib${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ "${bin}/lib${name}.a")
if ( BUILD_SHARED_LIBS )
list(APPEND ocaml_outputs
- "${bin}/dll${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ "${bin}/dll${name}.so")
endif()
endif()
if( HAVE_OCAMLOPT )
@@ -52,7 +52,12 @@ function(add_ocaml_library name)
"${bin}/${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()
- set(ocaml_flags "-lstdc++" "-ldopt" "-L${LLVM_LIBRARY_DIR}"
+ if ( LLVM_OCAML_OUT_OF_TREE )
+ set(ocaml_llvm_libdir "-L${LLVM_OCAML_EXTERNAL_LLVM_LIBDIR}")
+ else()
+ set(ocaml_llvm_libdir "-L${LLVM_LIBRARY_DIR}")
+ endif()
+ set(ocaml_flags "-lstdc++" "${ocaml_llvm_libdir}"
"-ccopt" "-L\\$CAMLORIGIN/../.."
"-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/../.."
${ocaml_pkgs})
@@ -67,7 +72,7 @@ function(add_ocaml_library name)
endif()
if(LLVM_LINK_LLVM_DYLIB)
- list(APPEND ocaml_flags "-lLLVM")
+ list(APPEND ocaml_flags "-lLLVM-${LLVM_VERSION_MAJOR}")
else()
explicit_map_components_to_libraries(llvm_libs ${ARG_LLVM})
foreach( llvm_lib ${llvm_libs} )
More information about the llvm-commits
mailing list