-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[CMake][OCaml] Make OCaml bindings suitable for out-of-tree install #123478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alan-j-hu
wants to merge
6
commits into
llvm:main
Choose a base branch
from
alan-j-hu:ocaml-cmake
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1644b1b
[CMake][OCaml] Make OCaml bindings suitable for out-of-tree install
alan-j-hu 583a0e1
Remove usage of CMAKE_SHARED_LIBRARY_SUFFIX elsewhere in AddOCaml.cmake
alan-j-hu 8ae9be9
In AddOCaml.cmake, replace broken BUILD_SHARED_LIBS logic
alan-j-hu 3fcb90f
Revise instructions in OCaml bindings README
alan-j-hu 0e007ad
Pass -custom for in-tree build, but not for out-of-tree build
alan-j-hu efb9b9f
Define ocaml_custom
alan-j-hu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you change the suffixes? What about Windows when we have
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) | ||
|
|
@@ -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}) | ||
|
|
@@ -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} ) | ||
|
|
@@ -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() | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_STANDALONEwe would do afindPackage(LLVM ...). That in turn would setLLVM_LIBRARY_DIRto be the external dir, and we wouldn't need the conditions below.