[llvm] r282895 - cmake: Install the OCaml libraries into a more correct path

Michal Gorny via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 11:34:23 PDT 2016


Author: mgorny
Date: Fri Sep 30 13:34:23 2016
New Revision: 282895

URL: http://llvm.org/viewvc/llvm-project?rev=282895&view=rev
Log:
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

Modified:
    llvm/trunk/bindings/ocaml/backends/CMakeLists.txt
    llvm/trunk/bindings/ocaml/backends/META.llvm_backend.in
    llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt
    llvm/trunk/bindings/ocaml/llvm/META.llvm.in
    llvm/trunk/cmake/config-ix.cmake
    llvm/trunk/cmake/modules/AddOCaml.cmake
    llvm/trunk/test/lit.cfg

Modified: llvm/trunk/bindings/ocaml/backends/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/backends/CMakeLists.txt?rev=282895&r1=282894&r2=282895&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/backends/CMakeLists.txt (original)
+++ llvm/trunk/bindings/ocaml/backends/CMakeLists.txt Fri Sep 30 13:34:23 2016
@@ -23,5 +23,5 @@ foreach(TARGET ${LLVM_TARGETS_TO_BUILD})
     "${LLVM_LIBRARY_DIR}/ocaml/META.llvm_${TARGET}")
 
   install(FILES "${LLVM_LIBRARY_DIR}/ocaml/META.llvm_${TARGET}"
-          DESTINATION lib/ocaml)
+          DESTINATION "${LLVM_OCAML_INSTALL_PATH}")
 endforeach()

Modified: llvm/trunk/bindings/ocaml/backends/META.llvm_backend.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/backends/META.llvm_backend.in?rev=282895&r1=282894&r2=282895&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/backends/META.llvm_backend.in (original)
+++ llvm/trunk/bindings/ocaml/backends/META.llvm_backend.in Fri Sep 30 13:34:23 2016
@@ -4,4 +4,4 @@ description = "@TARGET@ Backend for LLVM
 requires = "llvm"
 archive(byte) = "llvm_ at TARGET@.cma"
 archive(native) = "llvm_ at TARGET@.cmxa"
-directory = "."
+directory = "llvm"

Modified: llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt?rev=282895&r1=282894&r2=282895&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt (original)
+++ llvm/trunk/bindings/ocaml/llvm/CMakeLists.txt Fri Sep 30 13:34:23 2016
@@ -8,4 +8,4 @@ configure_file(
   "${LLVM_LIBRARY_DIR}/ocaml/META.llvm")
 
 install(FILES "${LLVM_LIBRARY_DIR}/ocaml/META.llvm"
-        DESTINATION lib/ocaml)
+        DESTINATION "${LLVM_OCAML_INSTALL_PATH}")

Modified: llvm/trunk/bindings/ocaml/llvm/META.llvm.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/META.llvm.in?rev=282895&r1=282894&r2=282895&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/META.llvm.in (original)
+++ llvm/trunk/bindings/ocaml/llvm/META.llvm.in Fri Sep 30 13:34:23 2016
@@ -3,7 +3,7 @@ version = "@PACKAGE_VERSION@"
 description = "LLVM OCaml bindings"
 archive(byte) = "llvm.cma"
 archive(native) = "llvm.cmxa"
-directory = "."
+directory = "llvm"
 
 package "analysis" (
     requires = "llvm"

Modified: llvm/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/config-ix.cmake?rev=282895&r1=282894&r2=282895&view=diff
==============================================================================
--- llvm/trunk/cmake/config-ix.cmake (original)
+++ llvm/trunk/cmake/config-ix.cmake Fri Sep 30 13:34:23 2016
@@ -554,6 +554,9 @@ else()
         message(STATUS "OCaml bindings enabled.")
         find_ocamlfind_package(oUnit VERSION 2 OPTIONAL)
         set(LLVM_BINDINGS "${LLVM_BINDINGS} ocaml")
+
+        set(LLVM_OCAML_INSTALL_PATH "${OCAML_STDLIB_PATH}" CACHE STRING
+            "Install directory for LLVM OCaml packages")
       else()
         message(STATUS "OCaml bindings disabled, need ctypes >=0.4.")
       endif()

Modified: llvm/trunk/cmake/modules/AddOCaml.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddOCaml.cmake?rev=282895&r1=282894&r2=282895&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/AddOCaml.cmake (original)
+++ llvm/trunk/cmake/modules/AddOCaml.cmake Fri Sep 30 13:34:23 2016
@@ -53,8 +53,8 @@ function(add_ocaml_library name)
   endif()
 
   set(ocaml_flags "-lstdc++" "-ldopt" "-L${LLVM_LIBRARY_DIR}"
-                  "-ccopt" "-L\\$CAMLORIGIN/.."
-                  "-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/.."
+                  "-ccopt" "-L\\$CAMLORIGIN/../.."
+                  "-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/../.."
                   ${ocaml_pkgs})
 
   foreach( ocaml_dep ${ARG_OCAMLDEP} )
@@ -135,9 +135,9 @@ function(add_ocaml_library name)
   endforeach()
 
   if( APPLE )
-    set(ocaml_rpath "@executable_path/../../lib")
+    set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}")
   elseif( UNIX )
-    set(ocaml_rpath "\\$ORIGIN/../../lib")
+    set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}")
   endif()
   list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
 
@@ -152,7 +152,7 @@ function(add_ocaml_library name)
     OUTPUT "${bin}/${name}.odoc"
     COMMAND "${OCAMLFIND}" "ocamldoc"
             "-I" "${bin}"
-            "-I" "${LLVM_LIBRARY_DIR}/ocaml/"
+            "-I" "${LLVM_LIBRARY_DIR}/ocaml/llvm/"
             "-dump" "${bin}/${name}.odoc"
             ${ocaml_pkgs} ${ocaml_inputs}
     DEPENDS ${ocaml_inputs} ${ocaml_outputs}
@@ -193,22 +193,25 @@ function(add_ocaml_library name)
   endforeach()
 
   install(FILES ${install_files}
-          DESTINATION lib/ocaml)
+          DESTINATION "${LLVM_OCAML_INSTALL_PATH}/llvm")
   install(FILES ${install_shlibs}
           PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
                       GROUP_READ GROUP_EXECUTE
                       WORLD_READ WORLD_EXECUTE
-          DESTINATION lib/ocaml)
+          DESTINATION "${LLVM_OCAML_INSTALL_PATH}/llvm")
 
   foreach( install_file ${install_files} ${install_shlibs} )
     get_filename_component(filename "${install_file}" NAME)
     add_custom_command(TARGET "ocaml_${name}" POST_BUILD
       COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${install_file}"
-                                             "${LLVM_LIBRARY_DIR}/ocaml/"
+                                             "${LLVM_LIBRARY_DIR}/ocaml/llvm/"
       COMMENT "Copying OCaml library component ${filename} to intermediate area"
       VERBATIM)
+    add_dependencies("ocaml_${name}" ocaml_make_directory)
   endforeach()
 endfunction()
 
+add_custom_target(ocaml_make_directory
+  COMMAND "${CMAKE_COMMAND}" "-E" "make_directory" "${LLVM_LIBRARY_DIR}/ocaml/llvm")
 add_custom_target("ocaml_all")
-set_target_properties(ocaml_all PROPERTIES FOLDER "Misc")
\ No newline at end of file
+set_target_properties(ocaml_all PROPERTIES FOLDER "Misc")

Modified: llvm/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg?rev=282895&r1=282894&r2=282895&view=diff
==============================================================================
--- llvm/trunk/test/lit.cfg (original)
+++ llvm/trunk/test/lit.cfg Fri Sep 30 13:34:23 2016
@@ -102,13 +102,13 @@ if llvm_lib_dir is None:
         llvm_lib_dir = os.path.join(llvm_obj_root, 'lib')
 
 if llvm_lib_dir is not None:
-    llvm_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
+    top_ocaml_lib = os.path.join(llvm_lib_dir, 'ocaml')
+    llvm_ocaml_lib = os.path.join(top_ocaml_lib, 'llvm')
     if llvm_ocaml_lib is not None:
+        ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, top_ocaml_lib))
         if 'OCAMLPATH' in os.environ:
-            ocamlpath = os.path.pathsep.join((llvm_ocaml_lib, os.environ['OCAMLPATH']))
-            config.environment['OCAMLPATH'] = ocamlpath
-        else:
-            config.environment['OCAMLPATH'] = llvm_ocaml_lib
+            ocamlpath = os.path.pathsep.join((ocamlpath, os.environ['OCAMLPATH']))
+        config.environment['OCAMLPATH'] = ocamlpath
 
         if 'CAML_LD_LIBRARY_PATH' in os.environ:
             caml_ld_library_path = os.path.pathsep.join((llvm_ocaml_lib,




More information about the llvm-commits mailing list