Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit a7d748b

Browse files
committed
cmake: Install the OCaml libraries into a more correct path
Add a OCAML_INSTALL_PATH variable that can be used to control the install path for OCaml libraries. The new variable defaults to ${OCAML_STDLIB_PATH}, i.e. the OCaml library path obtained from the OCaml compiler. Install libraries into "llvm" subdirectory. This fixes two issues: 1. OCaml library directories differ between systems, and 'lib/ocaml' is incorrect e.g. on amd64 Gentoo where OCaml is installed in 'lib64/ocaml'. Therefore, obtain the library path from the OCaml compiler using 'ocamlc -where' (which is already used to set OCAML_STDLIB_PATH), which is the method used commonly in OCaml packages. 2. The top-level directory is reserved for the standard library, and has precedence over local directory in search path. As a result, OCaml preferred the files installed along with previous LLVM version over the source tree when building a new version, resulting in two versions being mixed during the build. The new layout is used commonly by other OCaml packages, and findlib is able to find the LLVM libraries successfully. Bug: https://bugs.gentoo.org/559134 Bug: https://bugs.gentoo.org/559624 Differential Revision: https://reviews.llvm.org/D24354 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282895 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 9faad58 commit a7d748b

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

bindings/ocaml/backends/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ foreach(TARGET ${LLVM_TARGETS_TO_BUILD})
2323
"${LLVM_LIBRARY_DIR}/ocaml/META.llvm_${TARGET}")
2424

2525
install(FILES "${LLVM_LIBRARY_DIR}/ocaml/META.llvm_${TARGET}"
26-
DESTINATION lib/ocaml)
26+
DESTINATION "${LLVM_OCAML_INSTALL_PATH}")
2727
endforeach()

bindings/ocaml/backends/META.llvm_backend.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ description = "@TARGET@ Backend for LLVM"
44
requires = "llvm"
55
archive(byte) = "llvm_@[email protected]"
66
archive(native) = "llvm_@[email protected]"
7-
directory = "."
7+
directory = "llvm"

bindings/ocaml/llvm/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ configure_file(
88
"${LLVM_LIBRARY_DIR}/ocaml/META.llvm")
99

1010
install(FILES "${LLVM_LIBRARY_DIR}/ocaml/META.llvm"
11-
DESTINATION lib/ocaml)
11+
DESTINATION "${LLVM_OCAML_INSTALL_PATH}")

bindings/ocaml/llvm/META.llvm.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version = "@PACKAGE_VERSION@"
33
description = "LLVM OCaml bindings"
44
archive(byte) = "llvm.cma"
55
archive(native) = "llvm.cmxa"
6-
directory = "."
6+
directory = "llvm"
77

88
package "analysis" (
99
requires = "llvm"

cmake/config-ix.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ else()
554554
message(STATUS "OCaml bindings enabled.")
555555
find_ocamlfind_package(oUnit VERSION 2 OPTIONAL)
556556
set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")
557+
558+
set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING
559+
"Install directory for LLVM OCaml packages")
557560
else()
558561
message(STATUS "OCaml bindings disabled, need ctypes >=0.4.")
559562
endif()

cmake/modules/AddOCaml.cmake

+12-9
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function(add_ocaml_library name)
5353
endif()
5454

5555
set(ocaml_flags "-lstdc++" "-ldopt" "-L${LLVM_LIBRARY_DIR}"
56-
"-ccopt" "-L\\$CAMLORIGIN/.."
57-
"-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/.."
56+
"-ccopt" "-L\\$CAMLORIGIN/../.."
57+
"-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/../.."
5858
${ocaml_pkgs})
5959

6060
foreach( ocaml_dep ${ARG_OCAMLDEP} )
@@ -135,9 +135,9 @@ function(add_ocaml_library name)
135135
endforeach()
136136

137137
if( APPLE )
138-
set(ocaml_rpath "@executable_path/../../lib")
138+
set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}")
139139
elseif( UNIX )
140-
set(ocaml_rpath "\\$ORIGIN/../../lib")
140+
set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
141141
endif()
142142
list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
143143

@@ -152,7 +152,7 @@ function(add_ocaml_library name)
152152
OUTPUT "${bin}/${name}.odoc"
153153
COMMAND "${OCAMLFIND}" "ocamldoc"
154154
"-I" "${bin}"
155-
"-I" "${LLVM_LIBRARY_DIR}/ocaml/"
155+
"-I" "${LLVM_LIBRARY_DIR}/ocaml/llvm/"
156156
"-dump" "${bin}/${name}.odoc"
157157
${ocaml_pkgs} ${ocaml_inputs}
158158
DEPENDS ${ocaml_inputs} ${ocaml_outputs}
@@ -193,22 +193,25 @@ function(add_ocaml_library name)
193193
endforeach()
194194

195195
install(FILES ${install_files}
196-
DESTINATION lib/ocaml)
196+
DESTINATION "${LLVM_OCAML_INSTALL_PATH}/llvm")
197197
install(FILES ${install_shlibs}
198198
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
199199
GROUP_READ GROUP_EXECUTE
200200
WORLD_READ WORLD_EXECUTE
201-
DESTINATION lib/ocaml)
201+
DESTINATION "${LLVM_OCAML_INSTALL_PATH}/llvm")
202202

203203
foreach( install_file ${install_files} ${install_shlibs} )
204204
get_filename_component(filename "${install_file}" NAME)
205205
add_custom_command(TARGET "ocaml_${name}" POST_BUILD
206206
COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${install_file}"
207-
"${LLVM_LIBRARY_DIR}/ocaml/"
207+
"${LLVM_LIBRARY_DIR}/ocaml/llvm/"
208208
COMMENT "Copying OCaml library component ${filename} to intermediate area"
209209
VERBATIM)
210+
add_dependencies("ocaml_${name}" ocaml_make_directory)
210211
endforeach()
211212
endfunction()
212213

214+
add_custom_target(ocaml_make_directory
215+
COMMAND "${CMAKE_COMMAND}" "-E" "make_directory" "${LLVM_LIBRARY_DIR}/ocaml/llvm")
213216
add_custom_target("ocaml_all")
214-
set_target_properties(ocaml_all PROPERTIES FOLDER "Misc")
217+
set_target_properties(ocaml_all PROPERTIES FOLDER "Misc")

test/lit.cfg

+5-5
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ if llvm_lib_dir is None:
102102
llvm_lib_dir = os.path.join(llvm_obj_root, 'lib')
103103

104104
if llvm_lib_dir is not None:
105-
llvm_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
105+
top_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
106+
llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
106107
if llvm_ocaml_lib is not None:
108+
ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, top_ocaml_lib))
107109
if 'OCAMLPATH' in os.environ:
108-
ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, os.environ['OCAMLPATH']))
109-
config.environment['OCAMLPATH'] = ocamlpath
110-
else:
111-
config.environment['OCAMLPATH'] = llvm_ocaml_lib
110+
ocamlpath = os.path.pathsep.join((ocamlpath, os.environ['OCAMLPATH']))
111+
config.environment['OCAMLPATH'] = ocamlpath
112112

113113
if 'CAML_LD_LIBRARY_PATH' in os.environ:
114114
caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,

0 commit comments

Comments
 (0)