CMake Java Support
At the end of last year I’ve worked on Dogtag PKI, which is enterprise-class open source Certificate Authority.
The project is written in serveral different laguages (C, C++ and Java), so I’ve used CMake as the new build system. I know CMake very well and use it since a long time. To be able to build the java project I needed Java support in CMake. The current support is broken and after talking to Bill Hoffman he suggested to write CMake functions. So I’ve started to write functions to compile java files, find jar files, bundle jar files and generate javadoc.
My Java support for CMake should provide everything you need to build java and jni projects. You find the files here:
http://git.cryptomilk.org/projects/cmake-tools.git/tree/language/java
…
FindJNI.cmake:
Find JNI libraries and headers. I think this is the file from CMake itself.
FindJava.cmake:
Find all needed Java tools like javac, javadoc, jar, etc.
UseJava.cmake:
This file provides all needed function to support creating java projects in CMake. Most of the function are documented in detail. There is some documentation missing. I will try to add it soon.
UseJavaClassFilelist.cmake:
This is needed to find the class files in the build directory. One .java file can create multiple .class files. So you have to glob for these file. There is support to only look for certain .class files.
UseJavaSymlinks.cmake:
This is a helper to create symlinks for versioned jar files.
To checkout the tree use:
git clone git://git.cryptomilk.org/projects/cmake-tools.git
It would be nice if this would be included into the CMake distribution, but at
the moment there is still documentation missing. I hope that this will help
some people to get their Java project built with CMake.
Comments, suggestions and patches are welcome!
UPDATE
This work is upstream and will be available with CMake 2.8.6 (September 2011).
Hello Andreas, thanks for posting this CMake Java stuff, it looks like it can be handy. I’ve just started trying it and found that, if it’s not already obvious to the CMake user, you need to have something like project(myProject Java) in your CMakeLists.txt or the variable CMAKE_Java_COMPILER used by add_jar will not be populated… even if FindJava has found your javac and populated JAVA_COMPILE.
The stuff has been improved in the meantime and will be upstream soon:
http://cmake.org/gitweb?p=stage/cmake.git;a=shortlog;h=refs/heads/asn_java_support
There doesn’t appear to be a way of calling javah to generate headers from java files that declare native functions. Is this planned for a future release?
It was to trivial calling it with custom_command. Patches are welcome.