This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
CMakeLists.txt
65 lines (57 loc) · 2.16 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
include (LibAddMacros)
include (LibAddBinding)
include (SafeCheckSymbolExists)
if (DEPENDENCY_PHASE)
if (APPLE)
execute_process (
COMMAND "/usr/libexec/java_home --failfast"
ERROR_QUIET
OUTPUT_VARIABLE JAVA_HOME
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif ()
find_package (JNI QUIET)
if (JNI_FOUND)
set (DIRS ${JNI_INCLUDE_DIRS} ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2} ${JAVA_AWT_INCLUDE_PATH})
set (LIBS ${JAVA_MAWT_LIBRARY} ${JNI_LIBRARIES} ${JAVA_AWT_LIBRARY} ${JAVA_JVM_LIBRARY}) # for check_symbol_exists
set (CMAKE_REQUIRED_INCLUDES ${DIRS})
safe_check_symbol_exists (JNI_VERSION_1_8 jni.h JNI_CORRECT_VERSION)
unset (CMAKE_REQUIRED_INCLUDES)
if (NOT JNI_CORRECT_VERSION)
remove_plugin (jni "jni.h does not define JNI_VERSION_1_8")
endif ()
else ()
remove_plugin (jni "jni not found")
endif ()
endif ()
add_plugin (
jni
SOURCES jni.c
INCLUDE_DIRECTORIES ${DIRS}
LINK_LIBRARIES ${LIBS} COMPONENT libelektra${SO_VERSION}-java
ONLY_SHARED USE_LINK_RPATH)
if (ADDTESTING_PHASE)
check_binding_was_added ("jna" BINDING_WAS_ADDED)
find_program (MAVEN_EXECUTABLE mvn)
if (ENABLE_BROKEN_TESTS)
if (BUILD_TESTING
AND BINDING_WAS_ADDED
AND MAVEN_EXECUTABLE)
add_plugintest (jni MEMLEAK)
include_directories (${CMAKE_CURRENT_BINARY_DIR})
# Generate header file
set (LIBELEKTRA5J_PATH ${CMAKE_BINARY_DIR}/src/bindings/jna/libelektra)
add_custom_command (
COMMAND ${MAVEN_EXECUTABLE} ARGS dependency:build-classpath -q -Dmdep.outputFile=classpath.txt
COMMAND
${CMAKE_COMMAND} ARGS -D SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR} -D
DESTINATION_PATH=${CMAKE_CURRENT_BINARY_DIR} -D LIBELEKTRA5J_PATH=${LIBELEKTRA5J_PATH} -D
KDB_VERSION=${KDB_VERSION} -P ${CMAKE_SOURCE_DIR}/scripts/cmake/ElektraClasspath.cmake
OUTPUT "${LIBELEKTRA5J_PATH}/classpath.txt" "${CMAKE_CURRENT_BINARY_DIR}/testmod_jni.h"
WORKING_DIRECTORY ${LIBELEKTRA5J_PATH}
DEPENDS "${LIBELEKTRA5J_PATH}/pom.xml jna")
add_custom_target (jni_header DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/testmod_jni.h")
else ()
message (WARNING "jna bindings are required for testing, test deactivated")
endif ()
endif (ENABLE_BROKEN_TESTS)
endif ()