[CMake] mixed java/c project.

George Neill georgen at neillnet.com
Mon Oct 20 10:31:20 EDT 2008


Mathieu,

On Mon, Oct 20, 2008 at 4:06 AM, Mathieu Malaterre
<mathieu.malaterre at gmail.com> wrote:
> On Sat, Oct 18, 2008 at 7:48 PM, George Neill <georgen at neillnet.com> wrote:
>> Hi All,
>>
>> On Sat, Oct 18, 2008 at 2:01 AM, George Neill <georgen at neillnet.com> wrote:
>>> Hi all,
>>>
>>>  I am trying to convert a project to cmake which has mixed java and c
>>> compilations.  Here's the project layout,
>>>
>>>  project/
>>>     -> src/c
>>>     -> src/java
>>>
>>> I get the java project to build fine if I use the top level
>>> CMakeLists.txt file, but if I use add_subdirectory(src/java) in the
>>> top level CMakeLists.txt and create a CMakeLists.txt file in src/java
>>> it appears to break (below is the error)
>>>
>>> The -d option of the javac command line appears to be coming out wrong
>>> ... CMakeFiles/luajava.dir/org/keplerproject/luajava should actually
>>> be src/java/CMakeFiles/luajava.dir/org/keplerproject/luajava
>>>
>>> I took a look in Modules/CMakeJavaInformation.cmake and here's what I found,
>>>
>>> # compile a Java file into an object file
>>> IF(NOT CMAKE_Java_COMPILE_OBJECT)
>>>  SET(CMAKE_Java_COMPILE_OBJECT
>>>    "<CMAKE_Java_COMPILER>   <FLAGS> <SOURCE> -d <OBJECT_DIR>")
>>> ENDIF(NOT CMAKE_Java_COMPILE_OBJECT)
>>>
>>> OBJECT_DIR seems to be the wrong place,  any ideas on the best way to fix this?
>>
>> Well, it looks like this isn't a new issue.  (
>> http://www.mail-archive.com/cmake@cmake.org/msg02564.html )
>>
>> I was able to get by it by doing this,
>>
>> SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
>> SET(CMAKE_USER_MAKE_RULES_OVERRIDE "override")
>>
>> my override.cmake contains,
>>
>> # compile a Java file into an object file
>> IF(NOT CMAKE_Java_COMPILE_OBJECT)
>>  SET(CMAKE_Java_COMPILE_OBJECT
>>    "<CMAKE_Java_COMPILER>   <FLAGS> <SOURCE> -d
>> <CMAKE_CURRENT_BINARY_DIR>/<OBJECT_DIR>")
>> ENDIF(NOT CMAKE_Java_COMPILE_OBJECT)
>>
>> Is this acceptable, or should I be doing something else?
>
> IMHO I think it is. Please open a bug report, otherwise it might get
> lost -again?-

I will.  I have made a couple of changes since I last posted.  I found
out my change, while it did make everything compile fine ... messed up
the .jar file creation.  So here's what I ended up with,

bash-3.00$ cat override.cmake
# compile a Java file into an object file
FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/.class)

SET(CMAKE_Java_COMPILE_OBJECT
  "<CMAKE_Java_COMPILER> <FLAGS> <SOURCE> -d <CMAKE_CURRENT_BINARY_DIR>/.class"
)

# this is a place holder if java needed flags for javac they would go here.
SET(CMAKE_Java_CREATE_STATIC_LIBRARY
  "<CMAKE_Java_ARCHIVE> -cf <TARGET> -C <CMAKE_CURRENT_BINARY_DIR>/.class ."
)

Thanks,
George.


More information about the CMake mailing list