The purpose is to allow software developers to develop Java applications that use CEDA, even though CEDA is implemented in C++.
To allow this, Java Native Interface (JNI) is used. See the JNI example.
At least intially we will ignore IDEs such as Eclipse. Instead, we emphasise command line build tools, such as CMake.
Since we currently build the CEDA SDK under Windows using either the MSVC compiler cl, or clang-cl, we will also use that to build the application defined JNI dlls. This is controlled by CMake variables when CMake is invoked on the command line for the configure phase.
The PyCeda python package comes with a python script called generate_jni.py which is used to generate the .java and .cpp JNI files for a given CEDA based library. See Generating JNI with a python script.
We need to deal with JNI wrappers for everything in the ceda namespace. See JNI for the ceda namespace.
It would be interesting to see if we can make the ceda-samples project automatically run the generate_jni.py script, then build the JNI library. Running the samples would include running sample Java programs.
But that means a python script needs to execute as part of the build process. CMake can do this of course, but maybe to get going we just use a batch file. We already have a batch file windows_build_samples.bat which can be extended for this purpose.
The following folder structure is proposed:
(root) ├── CedaExamples └── MyCompany └── Java ├── cpp └── java
Building of the shared library: This requires the following to be done:
See CMake documentation: How to use MinGW to cross compile software for Windows . This describes how to make a CMake toolchain file.
This is not really necessary anymore - we have shown that it is possible to use cl or clang-cl to build JNI shared libs.
CMake provides the module FindJava to search for Java on the host. It also provides the module FindJNI to find the Java Native Interface (JNI) libraries.
Example usage:
find_package(Java)