summaryrefslogtreecommitdiffstats
path: root/java/CMakeLists.txt
blob: 867525b42c7cd15a0a22002f2ca644b17507f2bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
find_package(Java REQUIRED)
include(UseJava)

if (NOT DEFINED $ENV{JAVA_HOME_NATIVE})
  set (JAVA_HOME_NATIVE $ENV{JAVA_HOME})
  set (JAVAC $ENV{JAVA_HOME}/bin/javac)
  set (JAR $ENV{JAVA_HOME}/bin/jar)
else ()
  set (JAVAC $ENV{JAVA_HOME_NATIVE}/bin/javac)
  set (JAR $ENV{JAVA_HOME_NATIVE}/bin/jar)
endif ()


# Check that we can use javah
if(NOT Java_JAVAH_EXECUTABLE)
    message(FATAL_ERROR "Cannot locate javah executable.")
endif(NOT Java_JAVAH_EXECUTABLE)

set(CMAKE_JNI_TARGET TRUE)
file(GLOB_RECURSE JAVA_SOURCES "*.java")
add_jar(tinybjar ${JAVA_SOURCES}
                  MANIFEST ${CMAKE_CURRENT_BINARY_DIR}/manifest.txt
                  OUTPUT_NAME tinyb2
)

set(JAVA_CLASSES org.tinyb.BluetoothAdapter
                 org.tinyb.BluetoothCallback
                 org.tinyb.BluetoothDevice
                 org.tinyb.BluetoothEvent
                 org.tinyb.BluetoothFactory
                 org.tinyb.BluetoothGattCharacteristic
                 org.tinyb.BluetoothGattService
                 org.tinyb.BluetoothGattDescriptor
                 org.tinyb.BluetoothManager
                 org.tinyb.BluetoothObject
                 org.tinyb.BluetoothType
                 org.tinyb.BluetoothException
                 org.tinyb.ObjectArgCallback
                 org.tinyb.ObjectArrayArgCallback
                 tinyb.dbus.DBusAdapter
                 tinyb.dbus.DBusDevice
                 tinyb.dbus.DBusEvent
                 tinyb.dbus.DBusGattCharacteristic
                 tinyb.dbus.DBusGattDescriptor
                 tinyb.dbus.DBusGattService
                 tinyb.dbus.DBusManager
                 tinyb.dbus.DBusObject
                 tinyb.hci.HCIAdapter
                 tinyb.hci.HCIDevice
                 tinyb.hci.HCIEvent
                 tinyb.hci.HCIGattCharacteristic
                 tinyb.hci.HCIGattDescriptor
                 tinyb.hci.HCIGattService
                 tinyb.hci.HCIManager
                 tinyb.hci.HCIObject)
add_custom_command (TARGET tinybjar
  POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E echo "Generating JNI headers.."
  WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/tinybjar.dir"
  COMMAND ${Java_JAVAH_EXECUTABLE} -d jni/ -jni ${JAVA_CLASSES}
)

set(JNI_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/tinybjar.dir/jni")
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyb2.jar DESTINATION ${CMAKE_INSTALL_LIBDIR}/../lib/java)

add_subdirectory (jni)