[CMake] mixing Java and C++ in one project

Alex Makarenko alexei at cas.edu.au
Mon Jul 10 06:31:10 EDT 2006


I'm new to Java and simply wanted to compile a hello world executable within 
an existing C++ project. I took the example from 
cmake-2.4.2/Tests/Java/ and stuck it inside my project. It didn't quite work 
as I expected so i've been playing with Tests/Java/ and Tests/Simple/ trying 
to combine them into a project and see what works and what doesn't.

1. Placed unmodified examples inside dir 'mixed' and combined like so:
PROJECT( mixed )
SUBDIRS( Simple Java )

Note that both subdir's define their own PROJECT's.

Result: the in-source build works but the out-of-source does NOT. Out of 
source build fails like this:

------------------
/opt/jdk1.5.0_07/bin/javac    -classpath /home/makara/cvs/test/mixed-out/Java:/home/makara/cvs/test/mixed-out/build/Java   /home/makara/cvs/test/mixed-out/Java/HelloWorld.java -d 
CMakeFiles/hello.dir
/home/makara/cvs/test/mixed-out/Java/HelloWorld.java:1: error while writing 
HelloWorld: CMakeFiles/hello.dir/HelloWorld.class (No such file or directory)
class HelloWorld
^
1 error
------------------
The problem seems to be with the relative path following '-d' flag. That line 
fails when executed manually as is, but works if I put the absolute path in. 
Is there a fix?

2. is it possible to do this without creating sub-projects for Simple and 
Java? The documentation for PROJECT says that "By default all languages are 
supported." Does it mean that all of them are supported at once or only one 
at a time?

If Java is build without a PROJECT command, I get this:
/bin/sh: -classpath: command not found

If I say PROJECT( mixed CXX Java ), then C++ doesn't get setup properly:
Linking CXX static library libsimpleLib.a
/bin/sh: cr: command not found

Thanks a lot, Alex


More information about the CMake mailing list