Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/bindings/ocaml/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ 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 \
-DCMAKE_INSTALL_PREFIX=[Preinstalled LLVM path] \
-DLLVM_OCAML_INSTALL_PATH=[OCaml install prefix] \
-DLLVM_OCAML_EXTERNAL_LLVM_LIBDIR=[LLVM libdir, e.g. `llvm-config --libdir`] \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't do this, instead with an OCAML_BINDINGS_BUILD_STANDALONE we would do a findPackage(LLVM ...). That in turn would set LLVM_LIBRARY_DIR to be the external dir, and we wouldn't need the conditions below.

-DLLVM_OCAML_INSTALL_PATH=[OCaml install prefix, e.g. `opam var lib`] \
[... any other options]

then build and install it as:
Expand Down
36 changes: 28 additions & 8 deletions llvm/cmake/modules/AddOCaml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,27 @@ function(add_ocaml_library name)
set(ocaml_inputs)

set(ocaml_outputs "${bin}/${name}.cma")

# The -custom flag causes bytecode executables to fail upon creating the
# runtime when installing the bindings for an out-of-tree build.
#
# However, the -custom flag is necessary when running the in-tree
# test suite, otherwise multiple libraries will link to the same libLLVM and
# runtime errors of the form
# "CommandLine Error: Option *opt* registered more than once!" will occur.
if (NOT LLVM_OCAML_OUT_OF_TREE AND NOT BUILD_SHARED_LIBS)
set(ocaml_custom TRUE)
else()
set(ocaml_custom FALSE)
endif()

if( ARG_C )
# ocamlmklib outputs .a and .so
list(APPEND ocaml_outputs
"${bin}/lib${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
if ( BUILD_SHARED_LIBS )
"${bin}/lib${name}.a")
if ( NOT ocaml_custom )
list(APPEND ocaml_outputs
"${bin}/dll${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
"${bin}/dll${name}.so")
Comment on lines +58 to +61
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the suffixes? What about Windows when we have .lib and .dll?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see past talk on this, I still don't like this solution, however.

endif()
endif()
if( HAVE_OCAMLOPT )
Expand All @@ -52,7 +67,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})
Expand All @@ -62,12 +82,12 @@ function(add_ocaml_library name)
list(APPEND ocaml_flags ${dep_ocaml_flags})
endforeach()

if( NOT BUILD_SHARED_LIBS )
if(ocaml_custom)
list(APPEND ocaml_flags "-custom")
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} )
Expand Down Expand Up @@ -201,9 +221,9 @@ function(add_ocaml_library name)
if( NOT (ext STREQUAL ".cmo" OR
ext STREQUAL ".ml" OR
ext STREQUAL CMAKE_C_OUTPUT_EXTENSION OR
ext STREQUAL CMAKE_SHARED_LIBRARY_SUFFIX) )
ext STREQUAL ".so") )
list(APPEND install_files "${ocaml_output}")
elseif( ext STREQUAL CMAKE_SHARED_LIBRARY_SUFFIX)
elseif( ext STREQUAL ".so")
list(APPEND install_shlibs "${ocaml_output}")
endif()
endforeach()
Expand Down
Loading