Skip to content

Commit cb6d351

Browse files
authored
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.
1 parent 0d0e6f7 commit cb6d351

File tree

2 files changed

+181
-2
lines changed

2 files changed

+181
-2
lines changed

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ foreach(POM_LINE ${POM_FILE})
9696
string(REGEX REPLACE "^[ \t]+|<[^>]*>" "" DETECTED_VERSION "${POM_LINE}")
9797
string(STRIP "${DETECTED_VERSION}" DETECTED_VERSION)
9898
if(DETECTED_VERSION STREQUAL "")
99-
MESSAGE(WARNING "Could not parse version from pom.xml, defaulting to \"${JSSC_VERSION}\"")
99+
MESSAGE(WARNING "Could not parse JSSC version from pom.xml, defaulting to \"${JSSC_VERSION}\"")
100100
else()
101101
SET(JSSC_VERSION "${DETECTED_VERSION}")
102-
MESSAGE(STATUS "Found version \"${JSSC_VERSION}\" in pom.xml")
102+
MESSAGE(STATUS "Found JSSC version \"${JSSC_VERSION}\" in pom.xml")
103103
endif()
104104
break()
105105
endif()
@@ -108,6 +108,8 @@ configure_file(src/cpp/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY)
108108

109109
add_library(jssc SHARED src/cpp/${JSSC_PLATFORM}/jssc.cpp)
110110

111+
# Fall-back header for when maven is not available
112+
list(APPEND JSSC_ADDITIONAL_INCLUDES src/cpp/)
111113
target_include_directories(jssc PRIVATE ${JNI_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${JSSC_ADDITIONAL_INCLUDES})
112114

113115
set_target_properties(jssc PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR}/jssc_SerialNativeInterface.h)
@@ -124,6 +126,10 @@ elseif(FORCE_M64)
124126
# Build 64-bit binary on Linux
125127
set_target_properties(jssc PROPERTIES COMPILE_FLAGS -m64 LINK_FLAGS -m64)
126128
endif()
129+
# Copy native library back to source tree
130+
add_custom_command(TARGET jssc POST_BUILD
131+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/natives/ ${CMAKE_CURRENT_SOURCE_DIR}/src/main/resources-precompiled/natives/
132+
)
127133

128134
# Call strip on non-debug builds
129135
if(CMAKE_STRIP AND NOT CMAKE_BUILD_TYPE MATCHES "Deb")

src/cpp/jssc_SerialNativeInterface.h

Lines changed: 173 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)