Enable Java examples (#7702)
authormudathirmahgoub <mudathirmahgoub@gmail.com>
Wed, 1 Dec 2021 15:08:31 +0000 (09:08 -0600)
committerGitHub <noreply@github.com>
Wed, 1 Dec 2021 15:08:31 +0000 (15:08 +0000)
CMakeLists.txt
cmake/cvc5Config.cmake.in
examples/CMakeLists.txt
examples/api/java/CMakeLists.txt
src/api/java/CMakeLists.txt

index fb84058a3071e8ee61a553632db6ff7775bdd14d..ac654957ad86cdf83282e132cc98c54882f4a689 100644 (file)
@@ -475,7 +475,6 @@ endif()
 
 if(BUILD_BINDINGS_JAVA)
   add_subdirectory(src/api/java)
-  message(WARNING "Java API is currently under development.")
 endif()
 
 if(BUILD_DOCS)
index 6b238fb38ae52b92fbb20818312e16eaf1f056f3..11217e087f03e8a75cee378c9c865baf40ef3409 100644 (file)
@@ -21,9 +21,7 @@ if(NOT TARGET cvc5::cvc5)
   include(${CMAKE_CURRENT_LIST_DIR}/cvc5Targets.cmake)
 endif()
 
-# TODO(project wishue #83): enable these lines
-# if(CVC5_BINDINGS_JAVA AND NOT TARGET cvc5::cvc5jar)
-#  set_and_check(CVC5_JNI_PATH "@PACKAGE_LIBRARY_INSTALL_DIR@")
-# include(${CMAKE_CURRENT_LIST_DIR}/cvc5JavaTargets.cmake)
-# endif()
+if(CVC5_BINDINGS_JAVA AND NOT TARGET cvc5::cvc5jar)
+ include(${CMAKE_CURRENT_LIST_DIR}/cvc5JavaTargets.cmake)
+endif()
 
index d08e63e0f99fa721f0fd5b9998b4edc69bef4d69..27ecd72b56b0d596a596f75b3c08f9e8d52ee9c6 100644 (file)
@@ -85,23 +85,39 @@ add_subdirectory(api/cpp)
 
 if(TARGET cvc5::cvc5jar)
   find_package(Java REQUIRED)
+  find_package(JNI REQUIRED)
   include(UseJava)
+  message(STATUS "JNI_LIBRARIES: ${JNI_LIBRARIES}")
 
-  ## disabled until bindings for the new API are in place (issue #2284)
-  # get_target_property(CVC5_JAR cvc5::cvc5jar JAR_FILE)
-  #
-  # add_jar(SimpleVC SimpleVC.java INCLUDE_JARS "${CVC5_JAR}")
-  #
-  # add_test(
-  #   NAME java/SimpleVC
-  #   COMMAND
-  #     ${Java_JAVA_EXECUTABLE}
-  #       -cp "${CVC5_JAR}:${CMAKE_BINARY_DIR}/SimpleVC.jar"
-  #       -Djava.library.path=${CVC5_JNI_PATH}
-  #       SimpleVC
-  # )
-  # TODO(project wishue #83): enable java examples
-  # add_subdirectory(api/java)
+  # 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)
+  message(STATUS "CVC5_JNI_PATH: ${CVC5_JNI_PATH}")
+
+
+  get_target_property(CVC5_JAR cvc5::cvc5jar JAR_FILE)
+  message(STATUS "cvc5jar: ${CVC5_JAR}")
+
+  add_jar(SimpleVC SimpleVC.java INCLUDE_JARS "${CVC5_JAR}")
+  add_test(
+    NAME java/SimpleVC
+    COMMAND
+      ${Java_JAVA_EXECUTABLE}
+        -cp "${CVC5_JAR}:${CMAKE_BINARY_DIR}/SimpleVC.jar"
+        -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()
 
 if(CVC5_BINDINGS_PYTHON)
index 29ca63b93a1584562cf142178a6e8916ed891f05..bd4eb179a605350682a621deca3c31134648fdba 100644 (file)
 ##
 
 set(EXAMPLES_API_JAVA
-  ## disabled until bindings for the new API are in place (issue #2284)
-  # BitVectors
-  # BitVectorsAndArrays
-  # CVC5Streams
-  # Combination
-  # Datatypes
-  # Exceptions
-  # FloatingPointArith
-  # HelloWorld
-  # LinearArith
-  # PipedInput
-  # Relations
-  # Statistics
-  # Strings
-  # UnsatCores
+   BitVectors
+   BitVectorsAndArrays
+   Combination
+   Datatypes
+   Exceptions
+   Extract
+   FloatingPointArith
+   HelloWorld
+   LinearArith
+   QuickStart
+   Relations
+   Sequences
+   Sets
+   Statistics
+   Strings
+   SygusFun
+   SygusGrammar
+   SygusInv
+   Transcendentals
+   UnsatCores
 )
 
 foreach(example ${EXAMPLES_API_JAVA})
@@ -47,4 +52,6 @@ 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 ecfec21099037b63f9ba51b4929594521135b7e4..2c4151be794c953d0979df159a161c3bd390ceb5 100644 (file)
@@ -142,3 +142,18 @@ add_jar(cvc5jar
 )
 
 add_dependencies(cvc5jar generate-java-kinds cvc5jni cvc5)
+
+# install in the same directory of cvc5-targets
+install(TARGETS cvc5jni
+  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+install_jar(cvc5jar DESTINATION share/java)
+
+install_jar_exports(
+  TARGETS cvc5jar
+  NAMESPACE cvc5::
+  FILE cvc5JavaTargets.cmake
+  DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cvc5
+)