From cb6d351862da830f40ee8c511594c13dac134a32 Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Mon, 20 May 2019 14:50:36 -0400 Subject: [PATCH] Build natives to src tree; provide sample header (#55) - Adds the Unix javah-created header (also tested with MSVC) for creating builds on machines without (or with dated version of) maven. - Adds a "cmake -E copy" task to copy the native libraries to src/main/resources-precompiled/natives; convenience for speeding up the time it takes to update the binary releases in the repo. --- CMakeLists.txt | 10 +- src/cpp/jssc_SerialNativeInterface.h | 173 +++++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 src/cpp/jssc_SerialNativeInterface.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b10b6e5ab..4e7a7c976d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,10 +96,10 @@ foreach(POM_LINE ${POM_FILE}) string(REGEX REPLACE "^[ \t]+|<[^>]*>" "" DETECTED_VERSION "${POM_LINE}") string(STRIP "${DETECTED_VERSION}" DETECTED_VERSION) if(DETECTED_VERSION STREQUAL "") - MESSAGE(WARNING "Could not parse version from pom.xml, defaulting to \"${JSSC_VERSION}\"") + MESSAGE(WARNING "Could not parse JSSC version from pom.xml, defaulting to \"${JSSC_VERSION}\"") else() SET(JSSC_VERSION "${DETECTED_VERSION}") - MESSAGE(STATUS "Found version \"${JSSC_VERSION}\" in pom.xml") + MESSAGE(STATUS "Found JSSC version \"${JSSC_VERSION}\" in pom.xml") endif() break() endif() @@ -108,6 +108,8 @@ configure_file(src/cpp/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY) add_library(jssc SHARED src/cpp/${JSSC_PLATFORM}/jssc.cpp) +# Fall-back header for when maven is not available +list(APPEND JSSC_ADDITIONAL_INCLUDES src/cpp/) target_include_directories(jssc PRIVATE ${JNI_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${JSSC_ADDITIONAL_INCLUDES}) set_target_properties(jssc PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/jssc_SerialNativeInterface.h) @@ -124,6 +126,10 @@ elseif(FORCE_M64) # Build 64-bit binary on Linux set_target_properties(jssc PROPERTIES COMPILE_FLAGS -m64 LINK_FLAGS -m64) endif() +# Copy native library back to source tree +add_custom_command(TARGET jssc POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/natives/ ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources-precompiled/natives/ +) # Call strip on non-debug builds if(CMAKE_STRIP AND NOT CMAKE_BUILD_TYPE MATCHES "Deb") diff --git a/src/cpp/jssc_SerialNativeInterface.h b/src/cpp/jssc_SerialNativeInterface.h new file mode 100644 index 0000000000..afde9b032e --- /dev/null +++ b/src/cpp/jssc_SerialNativeInterface.h @@ -0,0 +1,173 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class jssc_SerialNativeInterface */ + +#ifndef _Included_jssc_SerialNativeInterface +#define _Included_jssc_SerialNativeInterface +#ifdef __cplusplus +extern "C" { +#endif +#undef jssc_SerialNativeInterface_OS_LINUX +#define jssc_SerialNativeInterface_OS_LINUX 0L +#undef jssc_SerialNativeInterface_OS_WINDOWS +#define jssc_SerialNativeInterface_OS_WINDOWS 1L +#undef jssc_SerialNativeInterface_OS_SOLARIS +#define jssc_SerialNativeInterface_OS_SOLARIS 2L +#undef jssc_SerialNativeInterface_OS_MAC_OS_X +#define jssc_SerialNativeInterface_OS_MAC_OS_X 3L +#undef jssc_SerialNativeInterface_ERR_PORT_BUSY +#define jssc_SerialNativeInterface_ERR_PORT_BUSY -1LL +#undef jssc_SerialNativeInterface_ERR_PORT_NOT_FOUND +#define jssc_SerialNativeInterface_ERR_PORT_NOT_FOUND -2LL +#undef jssc_SerialNativeInterface_ERR_PERMISSION_DENIED +#define jssc_SerialNativeInterface_ERR_PERMISSION_DENIED -3LL +#undef jssc_SerialNativeInterface_ERR_INCORRECT_SERIAL_PORT +#define jssc_SerialNativeInterface_ERR_INCORRECT_SERIAL_PORT -4LL +/* + * Class: jssc_SerialNativeInterface + * Method: getNativeLibraryVersion + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_jssc_SerialNativeInterface_getNativeLibraryVersion + (JNIEnv *, jclass); + +/* + * Class: jssc_SerialNativeInterface + * Method: openPort + * Signature: (Ljava/lang/String;Z)J + */ +JNIEXPORT jlong JNICALL Java_jssc_SerialNativeInterface_openPort + (JNIEnv *, jobject, jstring, jboolean); + +/* + * Class: jssc_SerialNativeInterface + * Method: setParams + * Signature: (JIIIIZZI)Z + */ +JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_setParams + (JNIEnv *, jobject, jlong, jint, jint, jint, jint, jboolean, jboolean, jint); + +/* + * Class: jssc_SerialNativeInterface + * Method: purgePort + * Signature: (JI)Z + */ +JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_purgePort + (JNIEnv *, jobject, jlong, jint); + +/* + * Class: jssc_SerialNativeInterface + * Method: closePort + * Signature: (J)Z + */ +JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_closePort + (JNIEnv *, jobject, jlong); + +/* + * Class: jssc_SerialNativeInterface + * Method: setEventsMask + * Signature: (JI)Z + */ +JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_setEventsMask + (JNIEnv *, jobject, jlong, jint); + +/* + * Class: jssc_SerialNativeInterface + * Method: getEventsMask + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_jssc_SerialNativeInterface_getEventsMask + (JNIEnv *, jobject, jlong); + +/* + * Class: jssc_SerialNativeInterface + * Method: waitEvents + * Signature: (J)[[I + */ +JNIEXPORT jobjectArray JNICALL Java_jssc_SerialNativeInterface_waitEvents + (JNIEnv *, jobject, jlong); + +/* + * Class: jssc_SerialNativeInterface + * Method: setRTS + * Signature: (JZ)Z + */ +JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_setRTS + (JNIEnv *, jobject, jlong, jboolean); + +/* + * Class: jssc_SerialNativeInterface + * Method: setDTR + * Signature: (JZ)Z + */ +JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_setDTR + (JNIEnv *, jobject, jlong, jboolean); + +/* + * Class: jssc_SerialNativeInterface + * Method: readBytes + * Signature: (JI)[B + */ +JNIEXPORT jbyteArray JNICALL Java_jssc_SerialNativeInterface_readBytes + (JNIEnv *, jobject, jlong, jint); + +/* + * Class: jssc_SerialNativeInterface + * Method: writeBytes + * Signature: (J[B)Z + */ +JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_writeBytes + (JNIEnv *, jobject, jlong, jbyteArray); + +/* + * Class: jssc_SerialNativeInterface + * Method: getBuffersBytesCount + * Signature: (J)[I + */ +JNIEXPORT jintArray JNICALL Java_jssc_SerialNativeInterface_getBuffersBytesCount + (JNIEnv *, jobject, jlong); + +/* + * Class: jssc_SerialNativeInterface + * Method: setFlowControlMode + * Signature: (JI)Z + */ +JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_setFlowControlMode + (JNIEnv *, jobject, jlong, jint); + +/* + * Class: jssc_SerialNativeInterface + * Method: getFlowControlMode + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_jssc_SerialNativeInterface_getFlowControlMode + (JNIEnv *, jobject, jlong); + +/* + * Class: jssc_SerialNativeInterface + * Method: getSerialPortNames + * Signature: ()[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_jssc_SerialNativeInterface_getSerialPortNames + (JNIEnv *, jobject); + +/* + * Class: jssc_SerialNativeInterface + * Method: getLinesStatus + * Signature: (J)[I + */ +JNIEXPORT jintArray JNICALL Java_jssc_SerialNativeInterface_getLinesStatus + (JNIEnv *, jobject, jlong); + +/* + * Class: jssc_SerialNativeInterface + * Method: sendBreak + * Signature: (JI)Z + */ +JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_sendBreak + (JNIEnv *, jobject, jlong, jint); + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file