summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorGrant Limberg <glimberg@gmail.com>2015-04-30 21:50:28 -0700
committerGrant Limberg <glimberg@gmail.com>2015-04-30 21:50:28 -0700
commit0a15eae00f7360930dad1fcfb25f02c15c930710 (patch)
treebc3869b0053acfb068d2cf3f4d964028b7990560 /java
parent75d71370258b102144a1f5941b64f35ddf815a8c (diff)
downloadinfinitytier-0a15eae00f7360930dad1fcfb25f02c15c930710.tar.gz
infinitytier-0a15eae00f7360930dad1fcfb25f02c15c930710.zip
Setup native build for Windows Java.
Still need to do Mac & Linux
Diffstat (limited to 'java')
-rw-r--r--java/CMakeLists.txt74
-rw-r--r--java/build.xml40
-rw-r--r--java/jni/ZT1_jniutils.h7
3 files changed, 116 insertions, 5 deletions
diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt
new file mode 100644
index 00000000..c97e86d6
--- /dev/null
+++ b/java/CMakeLists.txt
@@ -0,0 +1,74 @@
+cmake_minimum_required(VERSION 3.2)
+
+project(ZeroTierOneJNI)
+
+find_package(Java COMPONENTS Development)
+message("JAVA_HOME: $ENV{JAVA_HOME}")
+
+set(Java_INCLUDE_DIRS $ENV{JAVA_HOME}/include)
+
+message("Java Include Dirs: ${Java_INCLUDE_DIRS}")
+
+if(WIN32)
+ add_definitions(-DNOMINMAX)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /W3 /MP")
+endif()
+
+set(src_files
+ ../ext/lz4/lz4.c
+ ../ext/json-parser/json.c
+ ../ext/http-parser/http_parser.c
+ ../node/C25519.cpp
+ ../node/CertificateOfMembership.cpp
+ ../node/Defaults.cpp
+ ../node/Dictionary.cpp
+ ../node/Identity.cpp
+ ../node/IncomingPacket.cpp
+ ../node/InetAddress.cpp
+ ../node/Multicaster.cpp
+ ../node/Network.cpp
+ ../node/NetworkConfig.cpp
+ ../node/Node.cpp
+ ../node/OutboundMulticast.cpp
+ ../node/Packet.cpp
+ ../node/Peer.cpp
+ ../node/Poly1305.cpp
+ ../node/Salsa20.cpp
+ ../node/SelfAwareness.cpp
+ ../node/SHA512.cpp
+ ../node/Switch.cpp
+ ../node/Topology.cpp
+ ../node/Utils.cpp
+ ../osdep/Http.cpp
+ ../osdep/OSUtils.cpp
+ jni/com_zerotierone_sdk_Node.cpp
+ jni/ZT1_jniutils.cpp
+ )
+
+set(include_dirs
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include/
+ ${Java_INCLUDE_DIRS})
+
+if(WIN32)
+ set(include_dirs
+ ${include_dirs}
+ ${Java_INCLUDE_DIRS}/win32)
+endif()
+
+include_directories(
+ ${include_dirs}
+ )
+
+add_library(${PROJECT_NAME} SHARED ${src_files})
+
+set(link_libs )
+
+if(WIN32)
+ set(link_libs
+ wsock32
+ ws2_32
+
+ )
+endif()
+
+target_link_libraries(${PROJECT_NAME} ${link_libs}) \ No newline at end of file
diff --git a/java/build.xml b/java/build.xml
index 2057a509..0ee27185 100644
--- a/java/build.xml
+++ b/java/build.xml
@@ -1,15 +1,20 @@
<project default="build" name="ZeroTierOneSDK">
<property environment="env"/>
+ <condition property="isWindows">
+ <os family="windows"/>
+ </condition>
+
<target name="clean">
<delete dir="bin" failonerror="false"/>
<delete dir="classes" failonerror="false"/>
+ <delete dir="cmakebuild" failonerror="false"/>
<delete dir="libs" failonerror="false"/>
<delete dir="obj" failonerror="false"/>
</target>
- <target name="build">
- <echo message="os.name = ${os.name}"/>
+ <target name="build_java">
+ <echo message="os.name = ${os.name}"/>
<echo message="os.arch = ${os.arch}"/>
<echo message="ant.java.version = ${ant.java.version}"/>
<echo message="java.version = ${java.version}"/>
@@ -19,6 +24,9 @@
destdir="classes"
classpath="${env.ANDROID_PLATFORM}/android.jar"
includeantruntime="false"/>
+ </target>
+
+ <target name="build_android">
<exec dir="jni" executable="${env.NDK_BUILD_LOC}" failonerror="true">
<arg value="ZT1=${user.dir}/../"/>
</exec>
@@ -34,6 +42,34 @@
<copy file="libs/x86/libZeroTierOneJNI.so"
tofile="${user.dir}/classes/lib/x86/libZeroTierOneJNI.so"
overwrite="true"/>
+ </target>
+
+
+ <target name="windows" if="isWindows">
+ <mkdir dir="build_win32"/>
+ <exec dir="build_win32/" executable="cmake" failonerror="true">
+ <arg line=".. -G&quot;Visual Studio 11 2012&quot; -DCMAKE_BUILD_TYPE=Release"/>
+ </exec>
+ <exec dir="build_win32/" executable="cmake" failonerror="true">
+ <arg line="--build . --config Release"/>
+ </exec>
+ <copy file="build_win32/Release/ZeroTierOneJNI.dll"
+ tofile="classes/lib/ZeroTierOneJNI_win32.dll"
+ overwrite="true"/>
+
+ <mkdir dir="build_win64"/>
+ <exec dir="build_win64/" executable="cmake" failonerror="true">
+ <arg line=".. -G&quot;Visual Studio 11 2012 Win64&quot; -DCMAKE_BUILD_TYPE=Release"/>
+ </exec>
+ <exec dir="build_win64/" executable="cmake" failonerror="true">
+ <arg line="--build . --config Release"/>
+ </exec>
+ <copy file="build_win64/Release/ZeroTierOneJNI.dll"
+ tofile="classes/lib/ZeroTierOneJNI_win64.dll"
+ overwrite="true"/>
+ </target>
+
+ <target name="build" depends="build_java,build_android,windows">
<jar destfile="bin/ZeroTierOneSDK.jar" basedir="classes"/>
</target>
diff --git a/java/jni/ZT1_jniutils.h b/java/jni/ZT1_jniutils.h
index 6c43704c..d8baf85d 100644
--- a/java/jni/ZT1_jniutils.h
+++ b/java/jni/ZT1_jniutils.h
@@ -1,5 +1,6 @@
#ifndef ZT1_jniutils_h_
#define ZT1_jniutils_h_
+#include <stdio.h>
#include <jni.h>
#include <ZeroTierOne.h>
@@ -15,9 +16,9 @@ extern "C" {
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
#else
-#define LOGI(...)
-#define LOGD(...)
-#define LOGE(...)
+#define LOGI(...) fprintf(stdout, __VA_ARGS__)
+#define LOGD(...) fprintf(stdout, __VA_ARGS__)
+#define LOGE(...) fprintf(stdout, __VA_ARGS__)
#endif
jobject createResultObject(JNIEnv *env, ZT1_ResultCode code);