Skip to content
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

Build java ffi with cmake #131

Merged
merged 8 commits into from
Dec 15, 2021

Conversation

WorldofJARcraft
Copy link
Contributor

Hello,

I tried to build the Java FFI libraries on both Windows and Linux. While this worked on Linux using the Makefile, the Windows library would not link properly.
Instead of trying to fix the Windows build scripts which I thought were difficult to understand and maintain and error-prone, I created a CMakeLists.txt which compiles both the native bindings and the test JARs and performs the tests using ctest. It was useful for me, so I wanted to contribute it back.
I have tested the CMakeLists and the corresponding documentation on both Windows 10 x86_64 and Ubuntu 20.04 amd64, and the mclwrap library worked without issue on both. The mclelgamalwrap library still fails to compile on Windows and crashes on Linux, but I don't think that this is related to the build script. It did the same for me when I tried to build it using the existing scripts.

@herumi
Copy link
Owner

herumi commented Dec 6, 2021

Thank you for the patch.
I think that MCL_USE_GMP=OFF on Windows because it requires extra libraries.

I have one question.
The following command shows an error on Linux. Does it need any options?

cd ffi/java
mkdir build
cd build
cmake ..
mcl/ffi/java/build% cmake ..
-- JNI_INCLUDE_DIRS=/usr/lib/jvm/default-java/include;/usr/lib/jvm/default-java/include/linux;/usr/lib/jvm/default-java/include
-- JNI_LIBRARIES=/usr/lib/jvm/default-java/lib/libjawt.so;/usr/lib/jvm/default-java/lib/server/libjvm.so
-- MCL_LIBRARY=MCL_LIBRARY-NOTFOUND GMP_LIBRARY=/usr/lib/x86_64-linux-gnu/libgmp.so
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
MCL_LIBRARY
    linked by target "mclelgamaljava" in directory /home/shigeo/Program/mcl/ffi/java
    linked by target "mcljava" in directory /home/shigeo/Program/mcl/ffi/java

@WorldofJARcraft
Copy link
Contributor Author

Hello @herumi,

the CMake-configuration expects the libmcl.a to be installed in the system library directory (/usr/lib) per default. You can set the MCL_LINK_DIR CMake option to the directory where libmlc.a resides (e.g. cmake -DMCL_LINK_DIR=[path to mcl dir]/build/lib if mcl was compiled using CMake as well) to override this default location.
On Windows, since there is no default library directory, this option is mandatory.
I could have tried using a relative path (like ../../build), but this is highly discouraged in CMake, so I thought this was the best solution.

@herumi herumi merged commit d00a822 into herumi:master Dec 15, 2021
@herumi
Copy link
Owner

herumi commented Dec 15, 2021

Thank you. I've merged it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants