diff options
author | Jakob Odersky <jakob@odersky.com> | 2016-05-02 05:19:07 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2016-05-11 11:17:09 -0700 |
commit | 791cb363b77332e3abdf4039102dfcdb863ce6c3 (patch) | |
tree | 09ff5d807a1407abedade57b692204ceac3f3280 /samples/basic | |
parent | 49563ee13599b0cb1add27b24446677a13b1f563 (diff) | |
download | sbt-jni-791cb363b77332e3abdf4039102dfcdb863ce6c3.tar.gz sbt-jni-791cb363b77332e3abdf4039102dfcdb863ce6c3.tar.bz2 sbt-jni-791cb363b77332e3abdf4039102dfcdb863ce6c3.zip |
Use macro annotation to load native library
This also removes the need for third projects to depend on a "loader library".
Diffstat (limited to 'samples/basic')
-rw-r--r-- | samples/basic/README.md | 3 | ||||
-rw-r--r-- | samples/basic/basic-core/build.sbt | 1 | ||||
-rw-r--r-- | samples/basic/basic-core/src/main/scala/ch/jodersky/jni/basic/Library.scala | 8 | ||||
-rw-r--r-- | samples/basic/basic-core/src/main/scala/ch/jodersky/jni/basic/Main.scala | 13 | ||||
-rw-r--r-- | samples/basic/basic-native/src/CMakeLists.txt | 46 | ||||
-rw-r--r-- | samples/basic/basic-native/src/include/ch_jodersky_jni_basic_Library__.h | 21 | ||||
-rw-r--r-- | samples/basic/basic-native/src/library.c | 16 | ||||
-rw-r--r-- | samples/basic/build.sbt | 31 | ||||
-rw-r--r-- | samples/basic/project/build.properties | 1 | ||||
-rw-r--r-- | samples/basic/project/plugins.sbt | 1 |
10 files changed, 0 insertions, 141 deletions
diff --git a/samples/basic/README.md b/samples/basic/README.md deleted file mode 100644 index 0f29336..0000000 --- a/samples/basic/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Basic demo application using sbt-jni - -Publish plugin before running. diff --git a/samples/basic/basic-core/build.sbt b/samples/basic/basic-core/build.sbt deleted file mode 100644 index cd51bb3..0000000 --- a/samples/basic/basic-core/build.sbt +++ /dev/null @@ -1 +0,0 @@ -//enablePlugins(JniLoader) diff --git a/samples/basic/basic-core/src/main/scala/ch/jodersky/jni/basic/Library.scala b/samples/basic/basic-core/src/main/scala/ch/jodersky/jni/basic/Library.scala deleted file mode 100644 index efe3018..0000000 --- a/samples/basic/basic-core/src/main/scala/ch/jodersky/jni/basic/Library.scala +++ /dev/null @@ -1,8 +0,0 @@ -package ch.jodersky.jni.basic - -/** A demo object, mapping to a native library. */ -object Library { - - @native def print(message: String): Int - -} diff --git a/samples/basic/basic-core/src/main/scala/ch/jodersky/jni/basic/Main.scala b/samples/basic/basic-core/src/main/scala/ch/jodersky/jni/basic/Main.scala deleted file mode 100644 index 2aab1ed..0000000 --- a/samples/basic/basic-core/src/main/scala/ch/jodersky/jni/basic/Main.scala +++ /dev/null @@ -1,13 +0,0 @@ -package ch.jodersky.jni.basic - -import ch.jodersky.jni.NativeLoader - -object Main { - - def main(args: Array[String]): Unit = { - NativeLoader.load("/ch/jodersky/jni/basic/native", "demo1") - val result: Int = Library.print("Hello world!\n") - println("Returned: " + result) - } - -} diff --git a/samples/basic/basic-native/src/CMakeLists.txt b/samples/basic/basic-native/src/CMakeLists.txt deleted file mode 100644 index ec112b3..0000000 --- a/samples/basic/basic-native/src/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -cmake_minimum_required(VERSION 2.6) - -# Define project and related variables -# -project (demo) - -# Set versions and library name -# Note: major version will be appended to library name -# -set (VERSION_MAJOR 1) -set (VERSION_MINOR 2) -set (VERSION_PATCH 3) -set (LIB_NAME demo${VERSION_MAJOR}) - -# Command-line options -# -# required by sbt-jni to install binaries to correct places -set (LIB_INSTALL_DIR lib CACHE PATH "Path in which to install libraries (Autoconf equivalent to --libdir).") -# required by sbt-jni to disable versioned libraries -set (ENABLE_VERSIONED_LIB ON CACHE BOOLEAN "Generate versioned library files and symlinks.") - -# Setup JNI -find_package(JNI REQUIRED) -if (JNI_FOUND) - message (STATUS "JNI include directories: ${JNI_INCLUDE_DIRS}") -endif() - -# Include directories -include_directories(.) -include_directories(include) -include_directories(${JNI_INCLUDE_DIRS}) - -# Setup main shared library -# Note: major version is appended to library name -add_library(${LIB_NAME} SHARED library.c) -if (ENABLE_VERSIONED_LIB) - set_target_properties( - ${LIB_NAME} - PROPERTIES - VERSION 0.${VERSION_MINOR}.${VERSION_PATCH} # major version always 0, it is included in name - SOVERSION 0 - ) -endif() - -# Installation targets -install(TARGETS ${LIB_NAME} LIBRARY DESTINATION ${LIB_INSTALL_DIR}) diff --git a/samples/basic/basic-native/src/include/ch_jodersky_jni_basic_Library__.h b/samples/basic/basic-native/src/include/ch_jodersky_jni_basic_Library__.h deleted file mode 100644 index 60821e4..0000000 --- a/samples/basic/basic-native/src/include/ch_jodersky_jni_basic_Library__.h +++ /dev/null @@ -1,21 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include <jni.h> -/* Header for class ch_jodersky_jni_basic_Library__ */ - -#ifndef _Included_ch_jodersky_jni_basic_Library__ -#define _Included_ch_jodersky_jni_basic_Library__ -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: ch_jodersky_jni_basic_Library__ - * Method: print - * Signature: (Ljava/lang/String;)I - */ -JNIEXPORT jint JNICALL Java_ch_jodersky_jni_basic_Library_00024_print - (JNIEnv *, jobject, jstring); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/samples/basic/basic-native/src/library.c b/samples/basic/basic-native/src/library.c deleted file mode 100644 index eec05e5..0000000 --- a/samples/basic/basic-native/src/library.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <stdio.h> -#include "ch_jodersky_jni_basic_Library__.h" - -/* - * Class: ch_jodersky_jni_basic_Library__ - * Method: print - * Signature: (Ljava/lang/String;)I - */ -JNIEXPORT jint JNICALL Java_ch_jodersky_jni_basic_Library_00024_print -(JNIEnv *env, jobject clazz, jstring message) { - const char* msg = (*env)->GetStringUTFChars(env, message, 0); - fprintf(stdout, "Printing from native library: %s", msg); - fflush(stdout); - (*env)->ReleaseStringUTFChars(env, message, msg); - return 0; -} diff --git a/samples/basic/build.sbt b/samples/basic/build.sbt deleted file mode 100644 index 7f5bedd..0000000 --- a/samples/basic/build.sbt +++ /dev/null @@ -1,31 +0,0 @@ -val commonSettings = Seq( - scalaVersion := "2.11.7", - organization := "ch.jodersky" -) - -lazy val root = Project( - id = "root", - base = file("."), - aggregate = Seq(core, native) -) - -lazy val core = Project( - id = "basic-core", - base = file("basic-core"), - settings = commonSettings ++ Seq( - target in javah in Compile := (sourceDirectory in native).value / "include" - ), - dependencies = Seq( - native % Runtime - ) -).enablePlugins(JniLoading) - -lazy val native = Project( - id = "basic-native", - base = file("basic-native"), - settings = commonSettings ++ Seq( - //enableNativeCompilation in Compile := false, - sourceDirectory in nativeCompile in Compile := sourceDirectory.value, - nativeLibraryPath in Compile := "/ch/jodersky/jni/basic/native" - ) -).enablePlugins(JniNative) diff --git a/samples/basic/project/build.properties b/samples/basic/project/build.properties deleted file mode 100644 index 817bc38..0000000 --- a/samples/basic/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=0.13.9 diff --git a/samples/basic/project/plugins.sbt b/samples/basic/project/plugins.sbt deleted file mode 100644 index ec8b3e3..0000000 --- a/samples/basic/project/plugins.sbt +++ /dev/null @@ -1 +0,0 @@ -addSbtPlugin("ch.jodersky" % "sbt-jni" % "0.4.0-SNAPSHOT") |