diff options
Diffstat (limited to 'project/jni.scala')
-rw-r--r-- | project/jni.scala | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/project/jni.scala b/project/jni.scala index 7cde93b..5e248f2 100644 --- a/project/jni.scala +++ b/project/jni.scala @@ -1,9 +1,11 @@ import sbt._ import Keys._ import NativeKeys._ +import scala.util.Try object JniKeys { - val jdkHome = settingKey[File]("Home of JDK.") + val jdkHome = settingKey[Option[File]]("Home of JDK.") + val jdkHomeNotFound = taskKey[Unit]("Utility task that informs user that no JDK was found.") val javahHeaderDirectory = settingKey[File]("Directory where generated javah header files are placed.") val javahClasses = settingKey[Seq[String]]("Fully qualified names of classes containing native declarations.") val javahClasspath = taskKey[Seq[File]]("Classpath to use in javah.") @@ -14,12 +16,22 @@ object JniDefaults { import JniKeys._ val defaultSettings: Seq[Setting[_]] = Seq( - jdkHome := file(sys.env("JAVA_HOME")), + jdkHome := Try(file(sys.env("JAVA_HOME"))).toOption, + jdkHomeNotFound := jdkHomeNotFoundImpl.value, + nativeCompile in Native := ((nativeCompile in Native) dependsOn jdkHomeNotFound).value, javahHeaderDirectory := (sourceManaged in Native).value / "javah", - javah := javahImpl.value, + javah := javahImpl.value, sourceGenerators in Native <+= javah map { headers => headers}, includeDirectories in Native += javahHeaderDirectory.value, - includeDirectories in Native += jdkHome.value / "include") + includeDirectories in Native ++= jdkHome.value.map( jdk => jdk / "include").toSeq) + + def jdkHomeNotFoundImpl = Def.task { + if (jdkHome.value == None) { + streams.value.log.warn( + "No JDK home directory found, any native code using JNI may not compile. Please set JAVA_HOME environment variable.") + } + () + } def javahImpl = Def.task { val cps = javahClasspath.value |