diff options
author | Marc Chevrier <marc.chevrier@sap.com> | 2018-01-19 13:26:46 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@sap.com> | 2018-01-22 16:15:59 (GMT) |
commit | 4829ea239aa2b45170ce841e14d8e1ec076240ee (patch) | |
tree | 6cd8b76ef9b8d632199fdededdd9df2cea372c58 /Tests | |
parent | be2f0509037880a94f487867bee088a231054f4b (diff) | |
download | CMake-4829ea239aa2b45170ce841e14d8e1ec076240ee.zip CMake-4829ea239aa2b45170ce841e14d8e1ec076240ee.tar.gz CMake-4829ea239aa2b45170ce841e14d8e1ec076240ee.tar.bz2 |
add_jar: add option GENERATE_NATIVE_HEADERS
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLists.txt | 54 | ||||
-rw-r--r-- | Tests/JavaNativeHeaders/CMakeLists.txt | 18 | ||||
-rw-r--r-- | Tests/JavaNativeHeaders/D.cpp | 10 | ||||
-rw-r--r-- | Tests/JavaNativeHeaders/D.java | 19 | ||||
-rw-r--r-- | Tests/JavaNativeHeaders/E.cpp | 10 | ||||
-rw-r--r-- | Tests/JavaNativeHeaders/E.java | 19 | ||||
-rw-r--r-- | Tests/JavaNativeHeaders/HelloWorld3.java | 15 |
7 files changed, 129 insertions, 16 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index fb7313f..506e995 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -3195,29 +3195,51 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release --test-command ${JAVA_RUNTIME} -classpath hello3.jar HelloWorld) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJarSourceListAndOutput") - # For next test, java tool must have same architecture as toolchain + # For next tests, java tool must have same architecture as toolchain math(EXPR _object_mode "${CMAKE_SIZEOF_VOID_P} * 8") execute_process( COMMAND "${Java_JAVA_EXECUTABLE}" -d${_object_mode} -version OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE _result ) if(_result EQUAL 0) - if(_isMultiConfig) - set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah/$<CONFIGURATION>) - else() - set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah) + ## next test is valid only if Java version is less than 1.10 + if ("${Java_VERSION}" VERSION_LESS 1.10) + if(_isMultiConfig) + set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah/$<CONFIGURATION>) + else() + set (JAVAH_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaJavah) + endif() + add_test(NAME Java.Javah COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/JavaJavah" + "${CMake_BINARY_DIR}/Tests/JavaJavah" + ${build_generator_args} + --build-project helloJavah + --build-two-config + --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaJavah/" + --build-options ${build_options} + --test-command ${JAVA_RUNTIME} -Djava.library.path=${JAVAH_LIBRARY_PATH} -classpath hello3.jar HelloWorld2) + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJavah") + endif() + ## next test is valid only if Java is, at least, version 1.8 + if (NOT "${Java_VERSION}" VERSION_LESS 1.8) + if(_isMultiConfig) + set (JAVANATIVEHEADERS_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaNativeHeaders/$<CONFIGURATION>) + else() + set (JAVANATIVEHEADERS_LIBRARY_PATH ${CMake_BINARY_DIR}/Tests/JavaNativeHeaders) + endif() + add_test(NAME Java.NativeHeaders COMMAND ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/JavaNativeHeaders" + "${CMake_BINARY_DIR}/Tests/JavaNativeHeaders" + ${build_generator_args} + --build-project helloJavaNativeHeaders + --build-two-config + --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaNativeHeaders/" + --build-options ${build_options} + --test-command ${JAVA_RUNTIME} -Djava.library.path=${JAVANATIVEHEADERS_LIBRARY_PATH} -classpath hello4.jar HelloWorld3) + list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaNativeHeaders") endif() - add_test(NAME Java.Javah COMMAND ${CMAKE_CTEST_COMMAND} - --build-and-test - "${CMake_SOURCE_DIR}/Tests/JavaJavah" - "${CMake_BINARY_DIR}/Tests/JavaJavah" - ${build_generator_args} - --build-project helloJavah - --build-two-config - --build-run-dir "${CMake_BINARY_DIR}/Tests/JavaJavah/" - --build-options ${build_options} - --test-command ${JAVA_RUNTIME} -Djava.library.path=${JAVAH_LIBRARY_PATH} -classpath hello3.jar HelloWorld2) - list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/JavaJavah") endif() endif() endif() diff --git a/Tests/JavaNativeHeaders/CMakeLists.txt b/Tests/JavaNativeHeaders/CMakeLists.txt new file mode 100644 index 0000000..7dc2679 --- /dev/null +++ b/Tests/JavaNativeHeaders/CMakeLists.txt @@ -0,0 +1,18 @@ +project(helloJavaNativeHeaders Java CXX) + +cmake_minimum_required (VERSION 2.6) +set(CMAKE_VERBOSE_MAKEFILE 1) + +find_package(Java COMPONENTS Development) +include (UseJava) + +# JNI support +find_package(JNI) + +add_jar(B1 D.java GENERATE_NATIVE_HEADERS D1-native) +add_jar(E1 E.java GENERATE_NATIVE_HEADERS E1-native) + +add_jar(hello4 HelloWorld3.java) + +add_library(D SHARED D.cpp E.cpp) +target_link_libraries (D PRIVATE D1-native E1-native) diff --git a/Tests/JavaNativeHeaders/D.cpp b/Tests/JavaNativeHeaders/D.cpp new file mode 100644 index 0000000..2a90a08 --- /dev/null +++ b/Tests/JavaNativeHeaders/D.cpp @@ -0,0 +1,10 @@ + +#include <jni.h> +#include <stdio.h> + +#include "D.h" + +JNIEXPORT void JNICALL Java_D_printName(JNIEnv*, jobject) +{ + printf("D\n"); +} diff --git a/Tests/JavaNativeHeaders/D.java b/Tests/JavaNativeHeaders/D.java new file mode 100644 index 0000000..449c0df --- /dev/null +++ b/Tests/JavaNativeHeaders/D.java @@ -0,0 +1,19 @@ +class D +{ + public D() + { + } + + public native void printName(); + + static { + try { + + System.loadLibrary("D"); + + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load.\n" + e); + System.exit(1); + } + } +} diff --git a/Tests/JavaNativeHeaders/E.cpp b/Tests/JavaNativeHeaders/E.cpp new file mode 100644 index 0000000..fb98946 --- /dev/null +++ b/Tests/JavaNativeHeaders/E.cpp @@ -0,0 +1,10 @@ + +#include <jni.h> +#include <stdio.h> + +#include "E.h" + +JNIEXPORT void JNICALL Java_E_printName(JNIEnv*, jobject) +{ + printf("E\n"); +} diff --git a/Tests/JavaNativeHeaders/E.java b/Tests/JavaNativeHeaders/E.java new file mode 100644 index 0000000..30fd95a --- /dev/null +++ b/Tests/JavaNativeHeaders/E.java @@ -0,0 +1,19 @@ +class E +{ + public E() + { + } + + public native void printName(); + + static { + try { + + System.loadLibrary("D"); + + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load.\n" + e); + System.exit(1); + } + } +} diff --git a/Tests/JavaNativeHeaders/HelloWorld3.java b/Tests/JavaNativeHeaders/HelloWorld3.java new file mode 100644 index 0000000..77f1fed --- /dev/null +++ b/Tests/JavaNativeHeaders/HelloWorld3.java @@ -0,0 +1,15 @@ +class HelloWorld3 +{ + public static void main(String args[]) + { + D d; + d = new D(); + d.printName(); + + E e; + e = new E(); + e.printName(); + + System.out.println("Hello World!"); + } +} |