1 FIND_PACKAGE (JNI REQUIRED) 2 3 include_directories ( 4 ${JAVA_INCLUDE_PATH} 5 ${JAVA_INCLUDE_PATH2} 6 ${CMAKE_CURRENT_SOURCE_DIR}/.. 7 ) 8 9 # SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is required 10 set_source_files_properties (mraajava.i PROPERTIES SWIG_FLAGS ";-package;mraa;-I${CMAKE_BINARY_DIR}/src") 11 set_source_files_properties (mraajava.i PROPERTIES CPLUSPLUS ON) 12 13 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -DJAVACALLBACK") 14 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DJAVACALLBACK") 15 16 if (NOT DEFINED $ENV{JAVA_HOME_NATIVE}) 17 set (JAVA_HOME_NATIVE $ENV{JAVA_HOME}) 18 set (JAVAC $ENV{JAVA_HOME}/bin/javac) 19 set (JAR $ENV{JAVA_HOME}/bin/jar) 20 else () 21 set (JAVAC $ENV{JAVA_HOME_NATIVE}/bin/javac) 22 set (JAR $ENV{JAVA_HOME_NATIVE}/bin/jar) 23 endif () 24 25 swig_add_module (mraajava java mraajava.i ${mraa_LIB_SRCS}) 26 swig_link_libraries (mraajava ${JAVA_LIBRARIES} ${mraa_LIBS}) 27 28 add_custom_command (TARGET mraajava 29 POST_BUILD 30 COMMAND cmake -E echo "Compiling java.." 31 COMMAND cmake -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/mraa 32 COMMAND ${JAVAC} *.java -d ${CMAKE_CURRENT_BINARY_DIR} 33 COMMAND cmake -E create_symlink java/libmraajava.so ${CMAKE_CURRENT_BINARY_DIR}/../libmraajava.so 34 COMMAND cmake -E echo "Creating jar" 35 COMMAND ${JAR} cvf mraa.jar mraa 36 ) 37 38 if (DOXYGEN_FOUND) 39 foreach (_file ${DOCFILES}) 40 add_dependencies (${SWIG_MODULE_mraajava_REAL_NAME} ${_file}doc_i) 41 endforeach () 42 endif () 43 44 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/libmraajava.so 45 DESTINATION lib/java 46 ) 47 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/../libmraajava.so 48 DESTINATION lib/ 49 ) 50 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.jar 51 DESTINATION lib/java 52 ) 53