1find_package(Java REQUIRED) 2find_package(JNI REQUIRED) 3 4# Allow the Java compiler flags to be set using an environment variable 5if(NOT DEFINED CMAKE_JAVA_COMPILE_FLAGS AND DEFINED ENV{JAVAFLAGS}) 6 set(CMAKE_JAVA_COMPILE_FLAGS $ENV{JAVAFLAGS}) 7endif() 8 9include(UseJava) 10 11set(CMAKE_JAVA_COMPILE_FLAGS "${CMAKE_JAVA_COMPILE_FLAGS} -J-Dfile.encoding=UTF8") 12message(STATUS "CMAKE_JAVA_COMPILE_FLAGS = ${CMAKE_JAVA_COMPILE_FLAGS}") 13string(REGEX REPLACE " " ";" CMAKE_JAVA_COMPILE_FLAGS "${CMAKE_JAVA_COMPILE_FLAGS}") 14 15set(JAVAARGS "" CACHE STRING "Additional arguments to pass to java when running unit tests (example: -d32)") 16message(STATUS "JAVAARGS = ${JAVAARGS}") 17 18set(JAVA_SOURCES org/libjpegturbo/turbojpeg/TJ.java 19 org/libjpegturbo/turbojpeg/TJCompressor.java 20 org/libjpegturbo/turbojpeg/TJCustomFilter.java 21 org/libjpegturbo/turbojpeg/TJDecompressor.java 22 org/libjpegturbo/turbojpeg/TJException.java 23 org/libjpegturbo/turbojpeg/TJScalingFactor.java 24 org/libjpegturbo/turbojpeg/TJTransform.java 25 org/libjpegturbo/turbojpeg/TJTransformer.java 26 org/libjpegturbo/turbojpeg/YUVImage.java 27 TJUnitTest.java 28 TJExample.java 29 TJBench.java) 30 31set(TURBOJPEG_DLL_NAME "turbojpeg") 32if(MINGW) 33 set(TURBOJPEG_DLL_NAME "libturbojpeg") 34endif() 35if(WIN32) 36 configure_file(org/libjpegturbo/turbojpeg/TJLoader-win.java.in 37 ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java) 38else() 39 configure_file(org/libjpegturbo/turbojpeg/TJLoader-unix.java.in 40 ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java) 41endif() 42set(JAVA_SOURCES ${JAVA_SOURCES} 43 ${CMAKE_CURRENT_BINARY_DIR}/org/libjpegturbo/turbojpeg/TJLoader.java) 44 45if(MSYS) 46 # UGLY HACK ALERT: If we don't do this, then UseJava.cmake will separate 47 # class path members with a semicolon, which is interpreted as a command 48 # separator by the MSYS shell. 49 set(CMAKE_HOST_SYSTEM_NAME_BAK ${CMAKE_HOST_SYSTEM_NAME}) 50 set(CMAKE_HOST_SYSTEM_NAME "MSYS") 51endif() 52add_jar(turbojpeg-java ${JAVA_SOURCES} OUTPUT_NAME turbojpeg 53 ENTRY_POINT TJExample) 54if(MSYS) 55 set(CMAKE_HOST_SYSTEM_NAME ${CMAKE_HOST_SYSTEM_NAME_BAK}) 56endif() 57 58add_custom_target(javadoc COMMAND 59 javadoc -notimestamp -d ${CMAKE_CURRENT_SOURCE_DIR}/doc -sourcepath ${CMAKE_CURRENT_SOURCE_DIR} org.libjpegturbo.turbojpeg) 60set(JAVACLASSPATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/turbojpeg-java.dir) 61if(Java_VERSION_MAJOR GREATER 9) 62 add_custom_target(javah 63 COMMAND javac -h ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} 64 -d ${CMAKE_CURRENT_BINARY_DIR}/__unused 65 ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJ.java 66 ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJCompressor.java 67 ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJDecompressor.java 68 ${CMAKE_CURRENT_SOURCE_DIR}/org/libjpegturbo/turbojpeg/TJTransformer.java) 69else() 70 add_custom_target(javah 71 COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJ 72 COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJCompressor 73 COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJDecompressor 74 COMMAND javah -d ${CMAKE_CURRENT_SOURCE_DIR} -classpath ${JAVACLASSPATH} org.libjpegturbo.turbojpeg.TJTransformer) 75endif() 76 77if(NOT DEFINED CMAKE_INSTALL_DEFAULT_JAVADIR) 78 set(CMAKE_INSTALL_DEFAULT_JAVADIR "<CMAKE_INSTALL_DATAROOTDIR>/java") 79endif() 80GNUInstallDirs_set_install_dir(JAVADIR 81 "The directory into which Java classes should be installed") 82GNUInstallDirs_get_absolute_install_dir(CMAKE_INSTALL_FULL_JAVADIR 83 CMAKE_INSTALL_JAVADIR) 84set(CMAKE_INSTALL_JAVADIR ${CMAKE_INSTALL_JAVADIR} PARENT_SCOPE) 85set(CMAKE_INSTALL_FULL_JAVADIR ${CMAKE_INSTALL_FULL_JAVADIR} PARENT_SCOPE) 86report_directory(JAVADIR) 87install_jar(turbojpeg-java ${CMAKE_INSTALL_JAVADIR}) 88mark_as_advanced(CLEAR CMAKE_INSTALL_JAVADIR) 89