shun-iwasawa 82a8f5
find_package(Java REQUIRED)
shun-iwasawa 82a8f5
find_package(JNI REQUIRED)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
# Allow the Java compiler flags to be set using an environment variable
shun-iwasawa 82a8f5
if(NOT DEFINED CMAKE_JAVA_COMPILE_FLAGS AND DEFINED ENV{JAVAFLAGS})
shun-iwasawa 82a8f5
  set(CMAKE_JAVA_COMPILE_FLAGS $ENV{JAVAFLAGS})
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
include(UseJava)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(CMAKE_JAVA_COMPILE_FLAGS "${CMAKE_JAVA_COMPILE_FLAGS} -J-Dfile.encoding=UTF8")
shun-iwasawa 82a8f5
message(STATUS "CMAKE_JAVA_COMPILE_FLAGS = ${CMAKE_JAVA_COMPILE_FLAGS}")
shun-iwasawa 82a8f5
string(REGEX REPLACE " " ";" CMAKE_JAVA_COMPILE_FLAGS "${CMAKE_JAVA_COMPILE_FLAGS}")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(JAVAARGS "" CACHE STRING "Additional arguments to pass to java when running unit tests (example: -d32)")
shun-iwasawa 82a8f5
message(STATUS "JAVAARGS = ${JAVAARGS}")
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(JAVA_SOURCES org/libjpegturbo/turbojpeg/TJ.java
shun-iwasawa 82a8f5
  org/libjpegturbo/turbojpeg/TJCompressor.java
shun-iwasawa 82a8f5
  org/libjpegturbo/turbojpeg/TJCustomFilter.java
shun-iwasawa 82a8f5
  org/libjpegturbo/turbojpeg/TJDecompressor.java
shun-iwasawa 82a8f5
  org/libjpegturbo/turbojpeg/TJException.java
shun-iwasawa 82a8f5
  org/libjpegturbo/turbojpeg/TJScalingFactor.java
shun-iwasawa 82a8f5
  org/libjpegturbo/turbojpeg/TJTransform.java
shun-iwasawa 82a8f5
  org/libjpegturbo/turbojpeg/TJTransformer.java
shun-iwasawa 82a8f5
  org/libjpegturbo/turbojpeg/YUVImage.java
shun-iwasawa 82a8f5
  TJUnitTest.java
shun-iwasawa 82a8f5
  TJExample.java
shun-iwasawa 82a8f5
  TJBench.java)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set(TURBOJPEG_DLL_NAME "turbojpeg")
shun-iwasawa 82a8f5
if(MINGW)
shun-iwasawa 82a8f5
  set(TURBOJPEG_DLL_NAME "libturbojpeg")
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
if(WIN32)
shun-iwasawa 82a8f5
  configure_file(org/libjpegturbo/turbojpeg/TJLoader-win.java.in
shun-iwasawa 82a8f5
    ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java)
shun-iwasawa 82a8f5
else()
shun-iwasawa 82a8f5
  configure_file(org/libjpegturbo/turbojpeg/TJLoader-unix.java.in
shun-iwasawa 82a8f5
    ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
set(JAVA_SOURCES ${JAVA_SOURCES}
shun-iwasawa 82a8f5
  ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java)
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(MSYS)
shun-iwasawa 82a8f5
  # UGLY HACK ALERT: If we don't do this, then UseJava.cmake will separate
shun-iwasawa 82a8f5
  # class path members with a semicolon, which is interpreted as a command
shun-iwasawa 82a8f5
  # separator by the MSYS shell.
shun-iwasawa 82a8f5
  set(CMAKE_HOST_SYSTEM_NAME_BAK ${CMAKE_HOST_SYSTEM_NAME})
shun-iwasawa 82a8f5
  set(CMAKE_HOST_SYSTEM_NAME "MSYS")
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
add_jar(turbojpeg-java ${JAVA_SOURCES} OUTPUT_NAME turbojpeg
shun-iwasawa 82a8f5
  ENTRY_POINT TJExample)
shun-iwasawa 82a8f5
if(MSYS)
shun-iwasawa 82a8f5
  set(CMAKE_HOST_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_NAME_BAK})
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
add_custom_target(javadoc COMMAND
shun-iwasawa 82a8f5
  javadoc -notimestamp -d ${CMAKE_CURRENT_SOURCE_DIR}/doc -sourcepath ${CMAKE_CURRENT_SOURCE_DIR} org.libjpegturbo.turbojpeg)
shun-iwasawa 82a8f5
set(JAVACLASSPATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/turbojpeg-java.dir)
shun-iwasawa 82a8f5
if(Java_VERSION_MAJOR GREATER 9)
shun-iwasawa 82a8f5
  add_custom_target(javah
shun-iwasawa 82a8f5
    COMMAND javac -h ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH}
shun-iwasawa 82a8f5
      -d ${CMAKE_CURRENT_BINARY_DIR}/__unused
shun-iwasawa 82a8f5
      ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJ.java
shun-iwasawa 82a8f5
      ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJCompressor.java
shun-iwasawa 82a8f5
      ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJDecompressor.java
shun-iwasawa 82a8f5
      ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJTransformer.java)
shun-iwasawa 82a8f5
else()
shun-iwasawa 82a8f5
  add_custom_target(javah
shun-iwasawa 82a8f5
    COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJ
shun-iwasawa 82a8f5
    COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJCompressor
shun-iwasawa 82a8f5
    COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJDecompressor
shun-iwasawa 82a8f5
    COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJTransformer)
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if(NOT DEFINED CMAKE_INSTALL_DEFAULT_JAVADIR)
shun-iwasawa 82a8f5
  set(CMAKE_INSTALL_DEFAULT_JAVADIR "<cmake_install_datarootdir>/java")</cmake_install_datarootdir>
shun-iwasawa 82a8f5
endif()
shun-iwasawa 82a8f5
GNUInstallDirs_set_install_dir(JAVADIR
shun-iwasawa 82a8f5
  "The directory into which Java classes should be installed")
shun-iwasawa 82a8f5
GNUInstallDirs_get_absolute_install_dir(CMAKE_INSTALL_FULL_JAVADIR
shun-iwasawa 82a8f5
  CMAKE_INSTALL_JAVADIR)
shun-iwasawa 82a8f5
set(CMAKE_INSTALL_JAVADIR ${CMAKE_INSTALL_JAVADIR} PARENT_SCOPE)
shun-iwasawa 82a8f5
set(CMAKE_INSTALL_FULL_JAVADIR ${CMAKE_INSTALL_FULL_JAVADIR} PARENT_SCOPE)
shun-iwasawa 82a8f5
report_directory(JAVADIR)
shun-iwasawa 82a8f5
install_jar(turbojpeg-java ${CMAKE_INSTALL_JAVADIR})
shun-iwasawa 82a8f5
mark_as_advanced(CLEAR CMAKE_INSTALL_JAVADIR)