llvm.org GIT mirror llvm / a7d748b
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 Michal Gorny 4 years ago
7 changed file(s) with 24 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
2222 "${LLVM_LIBRARY_DIR}/ocaml/META.llvm_${TARGET}")
2323
2424 install(FILES "${LLVM_LIBRARY_DIR}/ocaml/META.llvm_${TARGET}"
25 DESTINATION lib/ocaml)
25 DESTINATION "${LLVM_OCAML_INSTALL_PATH}")
2626 endforeach()
33 requires = "llvm"
44 archive(byte) = "llvm_@TARGET@.cma"
55 archive(native) = "llvm_@TARGET@.cmxa"
6 directory = "."
6 directory = "llvm"
77 "${LLVM_LIBRARY_DIR}/ocaml/META.llvm")
88
99 install(FILES "${LLVM_LIBRARY_DIR}/ocaml/META.llvm"
10 DESTINATION lib/ocaml)
10 DESTINATION "${LLVM_OCAML_INSTALL_PATH}")
22 description = "LLVM OCaml bindings"
33 archive(byte) = "llvm.cma"
44 archive(native) = "llvm.cmxa"
5 directory = "."
5 directory = "llvm"
66
77 package "analysis" (
88 requires = "llvm"
553553 message(STATUS "OCaml bindings enabled.")
554554 find_ocamlfind_package(oUnit VERSION 2 OPTIONAL)
555555 set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")
556
557 set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING
558 "Install directory for LLVM OCaml packages")
556559 else()
557560 message(STATUS "OCaml bindings disabled, need ctypes >=0.4.")
558561 endif()
5252 endif()
5353
5454 set(ocaml_flags "-lstdc++" "-ldopt" "-L${LLVM_LIBRARY_DIR}"
55 "-ccopt" "-L\\$CAMLORIGIN/.."
56 "-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/.."
55 "-ccopt" "-L\\$CAMLORIGIN/../.."
56 "-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/../.."
5757 ${ocaml_pkgs})
5858
5959 foreach( ocaml_dep ${ARG_OCAMLDEP} )
134134 endforeach()
135135
136136 if( APPLE )
137 set(ocaml_rpath "@executable_path/../../lib")
137 set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}")
138138 elseif( UNIX )
139 set(ocaml_rpath "\\$ORIGIN/../../lib")
139 set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
140140 endif()
141141 list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
142142
151151 OUTPUT "${bin}/${name}.odoc"
152152 COMMAND "${OCAMLFIND}" "ocamldoc"
153153 "-I" "${bin}"
154 "-I" "${LLVM_LIBRARY_DIR}/ocaml/"
154 "-I" "${LLVM_LIBRARY_DIR}/ocaml/llvm/"
155155 "-dump" "${bin}/${name}.odoc"
156156 ${ocaml_pkgs} ${ocaml_inputs}
157157 DEPENDS ${ocaml_inputs} ${ocaml_outputs}
192192 endforeach()
193193
194194 install(FILES ${install_files}
195 DESTINATION lib/ocaml)
195 DESTINATION "${LLVM_OCAML_INSTALL_PATH}/llvm")
196196 install(FILES ${install_shlibs}
197197 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
198198 GROUP_READ GROUP_EXECUTE
199199 WORLD_READ WORLD_EXECUTE
200 DESTINATION lib/ocaml)
200 DESTINATION "${LLVM_OCAML_INSTALL_PATH}/llvm")
201201
202202 foreach( install_file ${install_files} ${install_shlibs} )
203203 get_filename_component(filename "${install_file}" NAME)
204204 add_custom_command(TARGET "ocaml_${name}" POST_BUILD
205205 COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${install_file}"
206 "${LLVM_LIBRARY_DIR}/ocaml/"
206 "${LLVM_LIBRARY_DIR}/ocaml/llvm/"
207207 COMMENT "Copying OCaml library component ${filename} to intermediate area"
208208 VERBATIM)
209 add_dependencies("ocaml_${name}" ocaml_make_directory)
209210 endforeach()
210211 endfunction()
211212
213 add_custom_target(ocaml_make_directory
214 COMMAND "${CMAKE_COMMAND}" "-E" "make_directory" "${LLVM_LIBRARY_DIR}/ocaml/llvm")
212215 add_custom_target("ocaml_all")
213 set_target_properties(ocaml_all PROPERTIES FOLDER "Misc")
216 set_target_properties(ocaml_all PROPERTIES FOLDER "Misc")
101101 llvm_lib_dir = os.path.join(llvm_obj_root, 'lib')
102102
103103 if llvm_lib_dir is not None:
104 llvm_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
104 top_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
105 llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
105106 if llvm_ocaml_lib is not None:
107 ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, top_ocaml_lib))
106108 if 'OCAMLPATH' in os.environ:
107 ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, os.environ['OCAMLPATH']))
108 config.environment['OCAMLPATH'] = ocamlpath
109 else:
110 config.environment['OCAMLPATH'] = llvm_ocaml_lib
109 ocamlpath = os.path.pathsep.join((ocamlpath, os.environ['OCAMLPATH']))
110 config.environment['OCAMLPATH'] = ocamlpath
111111
112112 if 'CAML_LD_LIBRARY_PATH' in os.environ:
113113 caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,