Skip to content

Commit 1644b1b

Browse files
committed
[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
1 parent 2b1e037 commit 1644b1b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

llvm/bindings/ocaml/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The bindings can also be built out-of-tree, i.e. targeting a preinstalled
1919
LLVM. To do this, configure the LLVM build tree as follows:
2020

2121
$ cmake -DLLVM_OCAML_OUT_OF_TREE=TRUE \
22+
-DLLVM_OCAML_EXTERNAL_LLVM_LIBDIR=[llvm-config --libdir] \
2223
-DCMAKE_INSTALL_PREFIX=[Preinstalled LLVM path] \
2324
-DLLVM_OCAML_INSTALL_PATH=[OCaml install prefix] \
2425
[... any other options]

llvm/cmake/modules/AddOCaml.cmake

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ function(add_ocaml_library name)
4040
set(ocaml_outputs "${bin}/${name}.cma")
4141
if( ARG_C )
4242
list(APPEND ocaml_outputs
43-
"${bin}/lib${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
43+
"${bin}/lib${name}.a")
4444
if ( BUILD_SHARED_LIBS )
4545
list(APPEND ocaml_outputs
46-
"${bin}/dll${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
46+
"${bin}/dll${name}.so")
4747
endif()
4848
endif()
4949
if( HAVE_OCAMLOPT )
@@ -52,7 +52,12 @@ function(add_ocaml_library name)
5252
"${bin}/${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
5353
endif()
5454

55-
set(ocaml_flags "-lstdc++" "-ldopt" "-L${LLVM_LIBRARY_DIR}"
55+
if ( LLVM_OCAML_OUT_OF_TREE )
56+
set(ocaml_llvm_libdir "-L${LLVM_OCAML_EXTERNAL_LLVM_LIBDIR}")
57+
else()
58+
set(ocaml_llvm_libdir "-L${LLVM_LIBRARY_DIR}")
59+
endif()
60+
set(ocaml_flags "-lstdc++" "${ocaml_llvm_libdir}"
5661
"-ccopt" "-L\\$CAMLORIGIN/../.."
5762
"-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/../.."
5863
${ocaml_pkgs})
@@ -67,7 +72,7 @@ function(add_ocaml_library name)
6772
endif()
6873

6974
if(LLVM_LINK_LLVM_DYLIB)
70-
list(APPEND ocaml_flags "-lLLVM")
75+
list(APPEND ocaml_flags "-lLLVM-${LLVM_VERSION_MAJOR}")
7176
else()
7277
explicit_map_components_to_libraries(llvm_libs ${ARG_LLVM})
7378
foreach( llvm_lib ${llvm_libs} )

0 commit comments

Comments
 (0)