[proofs] Make sure --proof-check=... is no-op when not checking proofs (#7638)
[cvc5.git] / cmake / FindJUnit.cmake
index cbea213a6c9f8d119470109e552182414b46bead..1532042a4942a5e96fd2efebf173a0629f6ab8ab 100644 (file)
@@ -1,36 +1,63 @@
-#####################
-## FindJUnit.cmake
-## Top contributors (to current version):
-##   Mathias Preiner
-## This file is part of the CVC4 project.
-## Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
-## in the top-level source directory and their institutional affiliations.
-## All rights reserved.  See the file COPYING in the top-level source
-## directory for licensing information.
-##
+###############################################################################
+# Top contributors (to current version):
+#   Mathias Preiner, Mudathir Mohamed
+#
+# This file is part of the cvc5 project.
+#
+# Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
+# in the top-level source directory and their institutional affiliations.
+# All rights reserved.  See the file COPYING in the top-level source
+# directory for licensing information.
+# #############################################################################
+#
 # Find JUnit
-# JUnit_FOUND - system has JUnit lib
-# JUnit_JAR - JUnit jar file
-# JUnit_JAR_DEPS - JUnit jar dependencies
+# JUnit_FOUND - should be true for testing
+# JUnit_JAR   - absolute path to JUnit5 jar file
+##
 
-find_package(Java REQUIRED)
-include(UseJava)
-find_package(Hamcrest REQUIRED)
+include(deps-helper)
 
-find_jar(JUnit_JAR NAMES junit junit4)
+find_jar(JUnit_JAR junit-platform-console-standalone
+  PATHS
+    ${DEPS_BASE}/share/java
+    $ENV{PATH} $ENV{HOME} $ENV{CLASSPATH} $ENV{JUNIT_HOME}
+)
 
+set(JUnit_FOUND_SYSTEM FALSE)
 if(JUnit_JAR)
-  set(JUnit_JAR_DEPS ${Hamcrest_JAR})
-  # Determine version of JUnit
-  execute_process(
-    COMMAND ${Java_JAVA_EXECUTABLE} -cp ${JUnit_JAR} junit.runner.Version
-    OUTPUT_VARIABLE JUnit_VERSION
-    OUTPUT_STRIP_TRAILING_WHITESPACE)
+  set(JUnit_FOUND_SYSTEM TRUE)
 endif()
 
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(JUnit
-  REQUIRED_VARS JUnit_JAR JUnit_JAR_DEPS
-  VERSION_VAR JUnit_VERSION)
+if(NOT JUnit_FOUND_SYSTEM)
+  check_auto_download("JUnit" "")
+  set(JUNIT_VERSION 1.7.1)
+  include(ExternalProject)
+
+  # Download junit generator jar
+  ExternalProject_Add(
+    JUnit-EP-jar
+    PREFIX ${DEPS_PREFIX}
+    URL https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/${JUNIT_VERSION}/junit-platform-console-standalone-${JUNIT_VERSION}.jar
+    URL_HASH SHA1=99245bde65d028a8b8ff604be26e929ab6ff2e58
+    DOWNLOAD_NO_EXTRACT ON
+    CONFIGURE_COMMAND ""
+    BUILD_COMMAND ""
+    INSTALL_COMMAND ${CMAKE_COMMAND} -E copy
+      <SOURCE_DIR>/../junit-platform-console-standalone-${JUNIT_VERSION}.jar
+      <INSTALL_DIR>/share/java/junit-platform-console-standalone-${JUNIT_VERSION}.jar
+    BUILD_BYPRODUCTS <INSTALL_DIR>/share/java/junit-platform-console-standalone-${JUNIT_VERSION}.jar
+  )
+
+  set(JUnit_JAR "${DEPS_BASE}/share/java/junit-platform-console-standalone-${JUNIT_VERSION}.jar")
+endif()
+
+set(JUnit_FOUND TRUE)
+
+mark_as_advanced(JUnit_JAR)
+mark_as_advanced(JUnit_FOUND)
 
-mark_as_advanced(JUnit_JAR JUnit_JAR_DEPS)
+if(JUnit_FOUND_SYSTEM)
+  message(STATUS "Found JUnit: ${JUnit_JAR}")
+else()
+  message(STATUS "Downloading JUnit: ${JUnit_JAR}")
+endif()
\ No newline at end of file