[Java API] Do not link JNI libraries (#8870)
authorAndres Noetzli <andres.noetzli@gmail.com>
Thu, 9 Jun 2022 02:30:40 +0000 (19:30 -0700)
committerGitHub <noreply@github.com>
Thu, 9 Jun 2022 02:30:40 +0000 (19:30 -0700)
Fixes #8869. We are not using `libjawt.so` or `libjvm.so` (we are not
using the Java Invocation API), so we don't need to link `libcvc5jni`
against `JNI_LIBRARIES`. This change allows us to use cvc5 from Java
without linking against the JNI libraries (see changes in the `examples`
folder).

examples/CMakeLists.txt
examples/api/java/CMakeLists.txt
src/api/java/CMakeLists.txt

index cda98e41a3d40223665933c5f26305713698b5d0..e2bbefc3887fce2863f233ab8d105bd2004ddc77 100644 (file)
@@ -78,18 +78,8 @@ add_subdirectory(api/cpp)
 
 if(TARGET cvc5::cvc5jar)
   find_package(Java REQUIRED)
-  find_package(JNI REQUIRED)
   include(UseJava)
-  message(STATUS "JNI_LIBRARIES: ${JNI_LIBRARIES}")
 
-  # get the directories of libraries libjawt.so and libjvm.so
-  set(JNI_LIBRARIES_PATHS "")
-  foreach(LIB ${JNI_LIBRARIES})
-    get_filename_component(LIB_PATH ${LIB} DIRECTORY)
-    set(JNI_LIBRARIES_PATHS "${JNI_LIBRARIES_PATHS}${LIB_PATH}:")
-  endforeach()
-
-  message(STATUS "JNI_LIBRARIES_PATHS: ${JNI_LIBRARIES_PATHS}")
   # get directory build/install/lib where libcvc5jni.so is installed
   get_target_property(CVC5_LIB_FILE cvc5::cvc5 LOCATION)
   get_filename_component(CVC5_JNI_PATH ${CVC5_LIB_FILE} DIRECTORY)
@@ -108,8 +98,6 @@ if(TARGET cvc5::cvc5jar)
         -Djava.library.path=${CVC5_JNI_PATH}
         SimpleVC
   )
-  set_tests_properties(java/SimpleVC PROPERTIES
-    ENVIRONMENT "LD_LIBRARY_PATH=${JNI_LIBRARIES_PATHS}")
   add_subdirectory(api/java)
 endif()
 
index 53b13498eb21fb462e2a1d0fb4beaaca529df13e..9c80ecb93792e1148f9ef42119fc5583c82ff4ce 100644 (file)
@@ -53,6 +53,4 @@ foreach(example ${EXAMPLES_API_JAVA})
         ${example}
   )
   set_tests_properties(${EXAMPLE_TEST_NAME} PROPERTIES SKIP_RETURN_CODE 77)
-  set_tests_properties(${EXAMPLE_TEST_NAME} PROPERTIES
-    ENVIRONMENT "LD_LIBRARY_PATH=${JNI_LIBRARIES_PATHS}")
 endforeach()
index 93b018179ce1bfbe2e2810a8466b6528249d2a7d..ed3bee3ce2e629d51e3c7a8845a0864ed4418c41 100644 (file)
@@ -163,7 +163,6 @@ target_include_directories(cvc5jni PUBLIC ${JNI_INCLUDE_DIRS})
 target_include_directories(cvc5jni PUBLIC ${PROJECT_SOURCE_DIR}/src)
 target_include_directories(cvc5jni PUBLIC ${CMAKE_BINARY_DIR}/src/)
 target_include_directories(cvc5jni PUBLIC ${JNI_DIR})
-target_link_libraries(cvc5jni PRIVATE ${JNI_LIBRARIES})
 target_link_libraries(cvc5jni PRIVATE cvc5)
 
 set(CVC5_JAR "cvc5-${CVC5_VERSION}.jar")