[CMake] making a jar from swig-generated jni library

Simmons, Aaron asimmons at rosettastone.com
Tue Apr 27 18:04:46 EDT 2010


I am using swig in cmake to create a JNI wrapper around a C++ library.  Everything is working fine, however I would like to jar up all the swig-generated java files.  I'm not sure how to do it.

My project looks more or less like this:
        cmake_minimum_required(VERSION 2.8)
        project(mylib)
            ...<snip>...

            # create library
            include_directories(${CMAKE_SOURCE_DIR})
            add_library(mylib mylib.cpp)
            
            # create the jni wrapper 
            SET_SOURCE_FILES_PROPERTIES(mylib.i PROPERTIES CPLUSPLUS ON)
            SWIG_ADD_MODULE(mylib-jni java mylib.i )
            target_link_libraries(mylib-jni mylib)

        project(mylib-jni Java)
            # jar up the generated swig java sources
            set(JAVA_SRCS ${CMAKE_SWIG_OUTDIR}/mylib.java ${CMAKE_SWIG_OUTDIR}/mylibJNI.java ) 
            include_directories(${CMAKE_SWIG_OUTDIR})
            add_library(mylib-java ${JAVA_SRCS})

However, this gives the error: 'Cannot find source file "mylib.java"'.  Which makes a kind of sense because mylib.java doesn't exist at cmake time.  Do the swig macros not mark the java files as "generated"?  Am I doing something wrong?


Thanks,
aaron


More information about the CMake mailing list